public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { DirContextOperations userData = userSearch.searchForUser(username); return userDetailsMapper.mapUserFromContext(userData, username, authoritiesPopulator.getGrantedAuthorities(userData, username)); }
public UserDetails loadUserByUsername(String username) { DistinguishedName dn = usernameMapper.buildDn(username); List<GrantedAuthority> authorities = getUserAuthorities(dn, username); logger.debug("Loading user '" + username + "' with DN '" + dn + "'"); DirContextAdapter userCtx = loadUserAsContext(dn, username); return userDetailsMapper.mapUserFromContext(userCtx, username, authorities); }
public Authentication authenticate(Authentication authentication) throws AuthenticationException { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, () -> this.messages.getMessage("LdapAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported")); final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication; String username = userToken.getName(); String password = (String) authentication.getCredentials(); if (this.logger.isDebugEnabled()) { this.logger.debug("Processing authentication request for user: " + username); } if (!StringUtils.hasLength(username)) { throw new BadCredentialsException(this.messages.getMessage( "LdapAuthenticationProvider.emptyUsername", "Empty Username")); } if (!StringUtils.hasLength(password)) { throw new BadCredentialsException(this.messages.getMessage( "AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password")); } Assert.notNull(password, "Null password was supplied in authentication token"); DirContextOperations userData = doAuthentication(userToken); UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, authentication.getName(), loadUserAuthorities(userData, authentication.getName(), (String) authentication.getCredentials())); return createSuccessfulAuthentication(userToken, user); }
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { DirContextOperations userData = userSearch.searchForUser(username); return userDetailsMapper.mapUserFromContext(userData, username, authoritiesPopulator.getGrantedAuthorities(userData, username)); }
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { DirContextOperations userData = userSearch.searchForUser(username); return userDetailsMapper.mapUserFromContext(userData, username, authoritiesPopulator.getGrantedAuthorities(userData, username)); }
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { DistinguishedName dn = usernameMapper.buildDn(username); List<GrantedAuthority> authorities = getUserAuthorities(dn, username); logger.debug("Loading user '"+ username + "' with DN '" + dn + "'"); DirContextAdapter userCtx = loadUserAsContext(dn, username); return userDetailsMapper.mapUserFromContext(userCtx, username, authorities); }
public UserDetails loadUserByUsername(String username) { DistinguishedName dn = usernameMapper.buildDn(username); List<GrantedAuthority> authorities = getUserAuthorities(dn, username); logger.debug("Loading user '" + username + "' with DN '" + dn + "'"); DirContextAdapter userCtx = loadUserAsContext(dn, username); return userDetailsMapper.mapUserFromContext(userCtx, username, authorities); }
@Override public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) { UserDetails userDetails = delegate.mapUserFromContext(ctx, username, authorities); String firstName = ctx.getStringAttribute("givenName"); String lastName = ctx.getStringAttribute("sn"); Collection<? extends GrantedAuthority> userAuthorities = getAuthorities(ctx, username, userDetails.getAuthorities()); Collection<Privilege> privileges = new ArrayList<>(userAuthorities.size()); for (GrantedAuthority authority : userAuthorities) { if (authority instanceof Privilege) { privileges.add((Privilege) authority); } else { privileges.add(new SimplePrivilege(authority.getAuthority(), authority.getAuthority())); } } return new SimpleUser(firstName, lastName, userDetails.getUsername(), null, privileges); }
@Override public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) { UserDetails userDetails = delegate.mapUserFromContext(ctx, username, authorities); String firstName = ctx.getStringAttribute("givenName"); String lastName = ctx.getStringAttribute("sn"); Collection<? extends GrantedAuthority> userAuthorities = getAuthorities(ctx, username, userDetails.getAuthorities()); Collection<Privilege> privileges = new ArrayList<>(userAuthorities.size()); for (GrantedAuthority authority : userAuthorities) { if (authority instanceof Privilege) { privileges.add((Privilege) authority); } else { privileges.add(new SimplePrivilege(authority.getAuthority(), authority.getAuthority())); } } return new SimpleUser(firstName, lastName, userDetails.getUsername(), null, privileges); }
public Authentication authenticate(Authentication authentication) throws AuthenticationException { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, () -> this.messages.getMessage("LdapAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported")); final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication; String username = userToken.getName(); String password = (String) authentication.getCredentials(); if (this.logger.isDebugEnabled()) { this.logger.debug("Processing authentication request for user: " + username); } if (!StringUtils.hasLength(username)) { throw new BadCredentialsException(this.messages.getMessage( "LdapAuthenticationProvider.emptyUsername", "Empty Username")); } if (!StringUtils.hasLength(password)) { throw new BadCredentialsException(this.messages.getMessage( "AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password")); } Assert.notNull(password, "Null password was supplied in authentication token"); DirContextOperations userData = doAuthentication(userToken); UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, authentication.getName(), loadUserAuthorities(userData, authentication.getName(), (String) authentication.getCredentials())); return createSuccessfulAuthentication(userToken, user); }
UserDetails user = userDetailsContextMapper.mapUserFromContext(userData, username, extraAuthorities);