List of usage examples for org.springframework.security.authentication UsernamePasswordAuthenticationToken setDetails
public void setDetails(Object details)
From source file:org.egov.infstr.security.spring.filter.EgovAuthenticationProcessingFilter.java
@Override protected void setDetails(final HttpServletRequest request, final UsernamePasswordAuthenticationToken authToken) { authToken.setDetails(authenticationDetailsSource.buildDetails(request)); }
From source file:org.geoserver.security.iride.IrideAuthenticationProvider.java
/** * Returns the {@link UsernamePasswordAuthenticationToken} token. * * @param auth the {@link UsernamePasswordAuthenticationToken} token * @return the {@link UsernamePasswordAuthenticationToken} token * @see UsernamePasswordAuthenticationProvider#authenticate(Authentication, HttpServletRequest) */// ww w . j ava 2 s .co m private UsernamePasswordAuthenticationToken buildAuthenticationToken(UsernamePasswordAuthenticationToken auth) { if (auth == null) { // pass request to next provider in the chain return null; } if (!auth.getAuthorities().contains(GeoServerRole.AUTHENTICATED_ROLE)) { final List<GrantedAuthority> roles = new ArrayList<>(); roles.addAll(auth.getAuthorities()); roles.add(GeoServerRole.AUTHENTICATED_ROLE); final UsernamePasswordAuthenticationToken newAuth = new UsernamePasswordAuthenticationToken( auth.getPrincipal(), auth.getCredentials(), roles); newAuth.setDetails(auth.getDetails()); return newAuth; } return auth; }
From source file:org.jamwiki.servlets.RegisterServlet.java
/** * *//*from w w w . j av a 2s .c om*/ private void login(HttpServletRequest request, String username, String password) { WikiUserDetails userDetails = new WikiUserDetails(username, password, true, true, true, true, JAMWikiAuthenticationConfiguration.getDefaultGroupRoles()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authentication.setDetails(new WebAuthenticationDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:org.opens.tgol.controller.LoginController.java
private void doGuestAutoLogin(HttpServletRequest request) { try {//from w w w . ja v a 2 s . c o m // Must be called from request filtered by Spring Security, otherwise SecurityContextHolder is not updated UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(guestUser, guestPassword); token.setDetails(new WebAuthenticationDetails(request)); Authentication guest = authenticationManager.authenticate(token); Logger.getLogger(this.getClass()).debug("Logging in with [{}]" + guest.getPrincipal()); SecurityContextHolder.getContext().setAuthentication(guest); } catch (Exception e) { SecurityContextHolder.getContext().setAuthentication(null); Logger.getLogger(this.getClass()).debug("Failure in autoLogin", e); } }
From source file:org.orcid.frontend.web.controllers.OauthConfirmAccessController.java
/***************************** * Authenticate user methods/*from w w w . j a v a 2s . c o m*/ ****************************/ private Authentication authenticateUser(HttpServletRequest request, OauthAuthorizeForm form) throws AuthenticationException { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( form.getUserName().getValue(), form.getPassword().getValue()); token.setDetails(new WebAuthenticationDetails(request)); return authenticateUser(token); }
From source file:org.orcid.frontend.web.controllers.OauthConfirmAccessController.java
private Authentication authenticateUser(HttpServletRequest request, String email, String password) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(email, password); token.setDetails(new WebAuthenticationDetails(request)); return authenticateUser(token); }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
private void automaticallyLogin(HttpServletRequest request, String password, OrcidProfile orcidProfile) { UsernamePasswordAuthenticationToken token = null; try {/* w w w. ja va 2s.com*/ String orcid = orcidProfile.getOrcidIdentifier().getPath(); // Force refresh of profile entity to ensure new password value is // picked up from DB. profileDao.refresh(profileDao.find(orcid)); token = new UsernamePasswordAuthenticationToken(orcid, password); token.setDetails(new WebAuthenticationDetails(request)); Authentication authentication = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { // this should never happen SecurityContextHolder.getContext().setAuthentication(null); LOGGER.warn("User {0} should have been logged-in, but we unable to due to a problem", e, (token != null ? token.getPrincipal() : "empty principle")); } }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
public void createMinimalRegistrationAndLogUserIn(HttpServletRequest request, HttpServletResponse response, OrcidProfile profileToSave, boolean usedCaptchaVerification) { String password = profileToSave.getPassword(); UsernamePasswordAuthenticationToken token = null; try {/*w w w . ja v a 2s .c o m*/ profileToSave = createMinimalRegistration(request, profileToSave, usedCaptchaVerification); String orcidId = profileToSave.getOrcidIdentifier().getPath(); token = new UsernamePasswordAuthenticationToken(profileToSave.getOrcidIdentifier().getPath(), password); token.setDetails(new WebAuthenticationDetails(request)); Authentication authentication = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); if (internalSSOManager.enableCookie()) { //Set user cookie internalSSOManager.writeCookie(orcidId, request, response); } } catch (AuthenticationException e) { // this should never happen SecurityContextHolder.getContext().setAuthentication(null); LOGGER.warn("User {0} should have been logged-in, but we unable to due to a problem", e, (token != null ? token.getPrincipal() : "empty principle")); } }
From source file:org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices.java
private OAuth2Authentication extractAuthentication(Map<String, Object> map) { Object principal = getPrincipal(map); List<GrantedAuthority> authorities = this.authoritiesExtractor.extractAuthorities(map); OAuth2Request request = new OAuth2Request(null, this.clientId, null, true, null, null, null, null, null); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal, "N/A", authorities);/*from w ww .ja va2s. c om*/ token.setDetails(map); return new OAuth2Authentication(request, token); }
From source file:org.springframework.cloud.security.oauth2.resource.SpringSocialTokenServices.java
private OAuth2Authentication extractAuthentication(UserProfile user) { UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken(user.getUsername(), "N/A", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")); principal.setDetails(user); OAuth2Request request = new OAuth2Request(null, clientId, null, true, null, null, null, null, null); return new OAuth2Authentication(request, principal); }