Search in sources :

Example 21 with DefaultLdapUserRoleListService

use of org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService in project pentaho-platform by pentaho.

the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole2.

/**
 * Search for all users starting at <code>ou=roles</code>, looking for objects with
 * <code>(&(objectClass=organizationalRole)(cn={0}))</code>, and extracting the <code>uid</code> token of the
 * <code>roleOccupant</code> attribute. This search implies that the schema is setup such that a user's roles come
 * from that user's DN being present in the <code>roleOccupant</code> attribute of a child object under the
 * <code>ou=roles</code> object.
 */
@Test
public void testGetUsernamesInRole2() {
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "roleOccupant" });
    LdapSearchParamsFactory paramFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=roles", "(&(objectClass=organizationalRole)(cn={0}))", con1);
    // $NON-NLS-1$ //$NON-NLS-2$
    Transformer transformer1 = new SearchResultToAttrValueList("roleOccupant", "uid");
    GrantedAuthorityToString transformer2 = new GrantedAuthorityToString();
    LdapSearch usernamesInRoleSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1, transformer2);
    Map<String, String> roleMap = new HashMap<>();
    roleMap.put("DEV", "dev");
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService(roleMap);
    userRoleListService.setUsernamesInRoleSearch(usernamesInRoleSearch);
    // $NON-NLS-1$
    List<String> res = userRoleListService.getUsersInRole(null, "DEV");
    // $NON-NLS-1$
    assertTrue(res.contains("pat"));
    // $NON-NLS-1$
    assertTrue(res.contains("tiffany"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getUsernamesInRole2(): " + res);
    }
}
Also used : DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) HashMap(java.util.HashMap) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) GrantedAuthorityToString(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString) LdapSearchParamsFactory(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory) SearchControls(javax.naming.directory.SearchControls) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) GrantedAuthorityToString(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString) UnionizingLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch) LdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) LdapSearchParamsFactoryImpl(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl) Test(org.junit.Test)

Aggregations

DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)21 Test (org.junit.Test)20 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)20 SearchControls (javax.naming.directory.SearchControls)16 Transformer (org.apache.commons.collections.Transformer)16 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)16 GenericLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch)16 LdapSearchParamsFactoryImpl (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl)16 ArrayList (java.util.ArrayList)14 List (java.util.List)14 LdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch)13 LdapSearchParamsFactory (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory)13 UnionizingLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch)13 GrantedAuthorityToString (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString)6 StringToGrantedAuthority (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority)5 ITenant (org.pentaho.platform.api.mt.ITenant)4 Tenant (org.pentaho.platform.core.mt.Tenant)4 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)4 LdapUserSearch (org.springframework.security.ldap.search.LdapUserSearch)4 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)4