Example usage for org.springframework.security.ldap.userdetails DefaultLdapAuthoritiesPopulator DefaultLdapAuthoritiesPopulator

List of usage examples for org.springframework.security.ldap.userdetails DefaultLdapAuthoritiesPopulator DefaultLdapAuthoritiesPopulator

Introduction

In this page you can find the example usage for org.springframework.security.ldap.userdetails DefaultLdapAuthoritiesPopulator DefaultLdapAuthoritiesPopulator.

Prototype

public DefaultLdapAuthoritiesPopulator(ContextSource contextSource, String groupSearchBase) 

Source Link

Document

Constructor for group search scenarios.

Usage

From source file:org.pentaho.test.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListServiceTest.java

/**
 * Same as above except sorted./* w ww . j av  a 2s.  c  o m*/
 */
@Test
public void testGetAuthoritiesForUser2Sorted() {
    DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(getContextSource(),
            "ou=roles"); //$NON-NLS-1$
    populator.setGroupRoleAttribute("cn"); //$NON-NLS-1$
    populator.setGroupSearchFilter("(roleOccupant={0})"); //$NON-NLS-1$

    LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})"); //$NON-NLS-1$//$NON-NLS-2$

    LdapUserDetailsService service = new LdapUserDetailsService(userSearch, populator);

    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();

    userRoleListService.setUserDetailsService(service);
    userRoleListService.setRoleComparator(new DefaultRoleComparator());

    List res = userRoleListService.getRolesForUser(null, "suzy"); //$NON-NLS-1$
    assertTrue(res.contains("ROLE_POWER_USER")); //$NON-NLS-1$

    if (logger.isDebugEnabled()) {
        logger.debug("results of getAuthoritiesForUser2Sorted(): " + res); //$NON-NLS-1$
    }

}