Search in sources :

Example 1 with SearchExecutor

use of org.springframework.ldap.core.SearchExecutor in project spring-security by spring-projects.

the class LdapUserDetailsManager method getUserAuthorities.

/**
	 *
	 * @param dn the distinguished name of the entry - may be either relative to the base
	 * context or a complete DN including the name of the context (either is supported).
	 * @param username the user whose roles are required.
	 * @return the granted authorities returned by the group search
	 */
@SuppressWarnings("unchecked")
List<GrantedAuthority> getUserAuthorities(final DistinguishedName dn, final String username) {
    SearchExecutor se = new SearchExecutor() {

        public NamingEnumeration<SearchResult> executeSearch(DirContext ctx) throws NamingException {
            DistinguishedName fullDn = LdapUtils.getFullDn(dn, ctx);
            SearchControls ctrls = new SearchControls();
            ctrls.setReturningAttributes(new String[] { groupRoleAttributeName });
            return ctx.search(groupSearchBase, groupSearchFilter, new String[] { fullDn.toUrl(), username }, ctrls);
        }
    };
    AttributesMapperCallbackHandler roleCollector = new AttributesMapperCallbackHandler(roleMapper);
    template.search(se, roleCollector);
    return roleCollector.getList();
}
Also used : DistinguishedName(org.springframework.ldap.core.DistinguishedName) SearchResult(javax.naming.directory.SearchResult) SearchControls(javax.naming.directory.SearchControls) DirContext(javax.naming.directory.DirContext) SearchExecutor(org.springframework.ldap.core.SearchExecutor) AttributesMapperCallbackHandler(org.springframework.ldap.core.AttributesMapperCallbackHandler)

Aggregations

DirContext (javax.naming.directory.DirContext)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 AttributesMapperCallbackHandler (org.springframework.ldap.core.AttributesMapperCallbackHandler)1 DistinguishedName (org.springframework.ldap.core.DistinguishedName)1 SearchExecutor (org.springframework.ldap.core.SearchExecutor)1