Example usage for org.springframework.security.ldap.userdetails LdapUserDetailsService setUserDetailsMapper

List of usage examples for org.springframework.security.ldap.userdetails LdapUserDetailsService setUserDetailsMapper

Introduction

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

Prototype

public void setUserDetailsMapper(UserDetailsContextMapper userDetailsMapper) 

Source Link

Usage

From source file:net.oneandone.stool.overview.config.SecurityConfiguration.java

@Override
public UserDetailsService userDetailsService() {
    FilterBasedLdapUserSearch userSearch;
    DefaultLdapAuthoritiesPopulator authoritiesPopulator;
    LdapUserDetailsService result;

    userSearch = new FilterBasedLdapUserSearch("ou=cisostages", "(uid={0})", contextSource());
    authoritiesPopulator = new DefaultLdapAuthoritiesPopulator(contextSource(), "ou=roles,ou=cisostages");
    authoritiesPopulator.setGroupSearchFilter("(member=uid={1})");
    authoritiesPopulator.setGroupRoleAttribute("ou");
    authoritiesPopulator.setSearchSubtree(false);
    authoritiesPopulator.setIgnorePartialResultException(true);

    result = new LdapUserDetailsService(userSearch, authoritiesPopulator);
    result.setUserDetailsMapper(new InetOrgPersonContextMapper());
    return result;
}

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

/**
 * Get the roles of user <code>suzy</code> by extracting the <code>cn</code> token from the <code>uniqueMember</code>
 * attribute of the object that matches base of <code>ou=users</code> and filter of <code>(uid={0})</code>.
 * //from w  w  w.  ja v  a  2 s .c o m
 * <p>
 * Note that the UserDetailsService used by Spring Security is re-used here.
 * </p>
 * 
 * @throws Exception
 */
@Test
public void testGetAuthoritiesForUser1() throws Exception {
    LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})"); //$NON-NLS-1$//$NON-NLS-2$

    LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator());

    RolePreprocessingMapper mapper = new RolePreprocessingMapper();
    mapper.setRoleAttributes(new String[] { "uniqueMember" }); //$NON-NLS-1$
    mapper.setTokenName("cn"); //$NON-NLS-1$
    service.setUserDetailsMapper(mapper);

    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();

    userRoleListService.setUserDetailsService(service);

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

    assertTrue(res.contains("ROLE_A")); //$NON-NLS-1$

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

}

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

@Test
public void testGetAuthoritiesForUser1ForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("suzy", defaultTenant);

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

    LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator());

    RolePreprocessingMapper mapper = new RolePreprocessingMapper();
    mapper.setRoleAttributes(new String[] { "uniqueMember" }); //$NON-NLS-1$
    mapper.setTokenName("cn"); //$NON-NLS-1$
    service.setUserDetailsMapper(mapper);

    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();

    userRoleListService.setUserDetailsService(service);

    List res = userRoleListService.getRolesForUser(defaultTenant, "suzy"); //$NON-NLS-1$

    assertTrue(res.contains("ROLE_A")); //$NON-NLS-1$

    if (logger.isDebugEnabled()) {
        logger.debug("results of getAuthoritiesForUser1(): " + res); //$NON-NLS-1$
    }/*  www .  ja v  a 2 s.  co m*/

    try {
        userRoleListService.getRolesForUser(new Tenant("/pentaho", true), "suzy");
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }

}