List of usage examples for org.springframework.security.ldap.userdetails LdapUserDetailsImpl.Essence LdapUserDetailsImpl.Essence
LdapUserDetailsImpl.Essence
From source file:org.springframework.security.ldap.userdetails.LdapUserDetailsMapper.java
@Override public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) { String dn = ctx.getNameInNamespace(); this.logger.debug("Mapping user details from context with DN: " + dn); LdapUserDetailsImpl.Essence essence = new LdapUserDetailsImpl.Essence(); essence.setDn(dn);//from w w w . j a v a 2s. c om Object passwordValue = ctx.getObjectAttribute(this.passwordAttributeName); if (passwordValue != null) { essence.setPassword(mapPassword(passwordValue)); } essence.setUsername(username); // Map the roles for (int i = 0; (this.roleAttributes != null) && (i < this.roleAttributes.length); i++) { String[] rolesForAttribute = ctx.getStringAttributes(this.roleAttributes[i]); if (rolesForAttribute == null) { this.logger.debug("Couldn't read role attribute '" + this.roleAttributes[i] + "' for user " + dn); continue; } for (String role : rolesForAttribute) { GrantedAuthority authority = createAuthority(role); if (authority != null) { essence.addAuthority(authority); } } } // Add the supplied authorities for (GrantedAuthority authority : authorities) { essence.addAuthority(authority); } // Check for PPolicy data PasswordPolicyResponseControl ppolicy = (PasswordPolicyResponseControl) ctx .getObjectAttribute(PasswordPolicyControl.OID); if (ppolicy != null) { essence.setTimeBeforeExpiration(ppolicy.getTimeBeforeExpiration()); essence.setGraceLoginsRemaining(ppolicy.getGraceLoginsRemaining()); } return essence.createUserDetails(); }