List of usage examples for org.springframework.security.web.authentication WebAuthenticationDetails WebAuthenticationDetails
public WebAuthenticationDetails(HttpServletRequest request)
From source file:org.runway.utils.AuthenticationUtils.java
public static void autoLogin(User user, HttpServletRequest request, AuthenticationManager authenticationManager) { // GrantedAuthority[] grantedAuthorities = new GrantedAuthority[] { new GrantedAuthorityImpl( // user.getAuthority()) }; UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities()); // generate session if one doesn't exist HttpSession session = request.getSession(); token.setDetails(new WebAuthenticationDetails(request)); Authentication authenticatedUser = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authenticatedUser); // setting role to the session session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); }
From source file:org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetails.java
public UaaAuthenticationDetails(HttpServletRequest request) { WebAuthenticationDetails webAuthenticationDetails = new WebAuthenticationDetails(request); this.origin = webAuthenticationDetails.getRemoteAddress(); this.sessionId = webAuthenticationDetails.getSessionId(); String clientId = request.getParameter("client_id"); if (clientId != null) { this.clientId = clientId; }/*from w w w. j ava2s . co m*/ }
From source file:com.application.model.dao.AuthenticationService.java
public void handleAuthentication(String login, String password, HttpServletRequest httpRequest) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(login, password); token.setDetails(new WebAuthenticationDetails(httpRequest)); ServletContext servletContext = httpRequest.getSession().getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); AuthenticationManager authManager = wac.getBean(AuthenticationManager.class); Authentication authentication = authManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:com.morevaadin.vaadin7.springsecurity.service.AuthenticationService.java
public void handleAuthentication(String login, String password, HttpServletRequest httpRequest) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(login, password); token.setDetails(new WebAuthenticationDetails(httpRequest)); ServletContext servletContext = httpRequest.getSession().getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); AuthenticationManager authManager = wac.getBean(AuthenticationManager.class); Authentication authentication = authManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:fr.xebia.audit.AuditAspectTest.java
@Before public void before() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr("10.0.0.1"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("ze-principal", "ze-credentials"); authentication.setDetails(details);//from w w w .j a v a 2 s .co m SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:com.epam.cme.storefront.security.impl.DefaultAutoLoginStrategy.java
@Override public void login(final String username, final String password, final HttpServletRequest request, final HttpServletResponse response) { final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);//from ww w . ja va 2s . c o m token.setDetails(new WebAuthenticationDetails(request)); try { final Authentication authentication = getAuthenticationManager().authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); getCustomerFacade().loginSuccess(); getGuidCookieStrategy().setCookie(request, response); } catch (final Exception e) { SecurityContextHolder.getContext().setAuthentication(null); LOG.error("Failure during autoLogin", e); } }
From source file:org.springframework.security.web.jackson2.WebAuthenticationDetailsMixinTest.java
@Test public void buildWebAuthenticationDetailsUsingDifferentConstructors() throws IOException { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr("localhost"); request.setSession(new MockHttpSession(null, "1")); WebAuthenticationDetails details = new WebAuthenticationDetails(request); String jsonString = "{\"@class\": \"org.springframework.security.web.authentication.WebAuthenticationDetails\"," + "\"sessionId\": \"1\", \"remoteAddress\": \"/localhost\"}"; WebAuthenticationDetails authenticationDetails = this.mapper.readValue(jsonString, WebAuthenticationDetails.class); assertThat(details.equals(authenticationDetails)); }
From source file:com.acc.storefront.security.impl.DefaultAutoLoginStrategy.java
@Override public void login(final String username, final String password, final HttpServletRequest request, final HttpServletResponse response) { final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);//from w ww . j av a 2 s . co m token.setDetails(new WebAuthenticationDetails(request)); try { final Authentication authentication = getAuthenticationManager().authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); getCustomerFacade().loginSuccess(); getGuidCookieStrategy().setCookie(request, response); getRememberMeServices().loginSuccess(request, response, token); } catch (final Exception e) { SecurityContextHolder.getContext().setAuthentication(null); LOG.error("Failure during autoLogin", e); } }
From source file:springchat.rest.AuthenticationRest.java
@RequestMapping(value = "/rest/auth", method = RequestMethod.POST, produces = { "application/json" }) @ResponseBody// w ww. ja va 2 s . co m public AuthenticationResultDto postUser(@RequestParam("user") String user, HttpServletRequest request) { AuthenticationResultDto dto = new AuthenticationResultDto(); dto.setSessionId(request.getSession().getId()); try { // Must be called from request filtered by Spring Security, otherwise SecurityContextHolder is not updated AbstractAuthenticationToken token = new UsernamePasswordAuthenticationToken(user, ""); token.setDetails(new WebAuthenticationDetails(request)); Authentication authentication = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); dto.setSuccess(Boolean.TRUE); request.getSession().setAttribute("authenticated", Boolean.TRUE); } catch (Exception e) { SecurityContextHolder.getContext().setAuthentication(null); dto.setSuccess(Boolean.FALSE); request.getSession().setAttribute("authenticated", Boolean.FALSE); } return dto; }
From source file:com.lll.util.SpringSecurityUtils.java
/** * UserDetails?Security Context./*from ww w . ja v a 2s . c om*/ * * @param userDetails ??. * @param request ?IP??. */ public static void saveUserDetailsToContext(UserDetails userDetails, HttpServletRequest request) { PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities()); authentication.setDetails(new WebAuthenticationDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); }