Search in sources :

Example 1 with LdapSearch

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

the class DefaultLdapUserRoleListServiceTest method testGetAllAuthorities1.

/**
 * Search for all roles (aka authorities) starting at <code>ou=roles</code>, looking for objects with
 * <code>objectClass=organizationalRole</code>, and returning the <code>cn</code> attribute.
 */
@Test
public void testGetAllAuthorities1() {
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "cn" });
    LdapSearchParamsFactory paramsFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=roles", "(objectClass=organizationalRole)", con1);
    // $NON-NLS-1$
    Transformer one = new SearchResultToAttrValueList("cn");
    Transformer two = new StringToGrantedAuthority();
    Transformer[] transformers = { one, two };
    Transformer transformer = new ChainedTransformer(transformers);
    LdapSearch rolesSearch = new GenericLdapSearch(getContextSource(), paramsFactory, transformer);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllAuthoritiesSearch(rolesSearch);
    List res = userRoleListService.getAllRoles();
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_CTO"));
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_CEO"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllAuthorities1(): " + res);
    }
}
Also used : DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) LdapSearchParamsFactory(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) StringToGrantedAuthority(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) SearchControls(javax.naming.directory.SearchControls) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) 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)

Example 2 with LdapSearch

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

the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole1.

/**
 * Search for all users starting at <code>ou=users</code>, looking for objects with
 * <code>businessCategory=cn={0}*</code>, and returning the <code>uid</code> attribute. This search implies that the
 * schema is setup such that a user's roles come from one of the user's attributes.
 */
@Test
public void testGetUsernamesInRole1() {
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "uid" });
    LdapSearchParamsFactory paramFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=users", "(businessCategory=cn={0}*)", con1);
    // $NON-NLS-1$
    Transformer transformer1 = new SearchResultToAttrValueList("uid");
    GrantedAuthorityToString transformer2 = new GrantedAuthorityToString();
    LdapSearch usernamesInRoleSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1, transformer2);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    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 getUsernamesInRole1(): " + res);
    }
}
Also used : DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) LdapSearchParamsFactory(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) SearchControls(javax.naming.directory.SearchControls) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) 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) GrantedAuthorityToString(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString) LdapSearchParamsFactoryImpl(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl) Test(org.junit.Test)

Example 3 with LdapSearch

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

the class DefaultLdapUserRoleListServiceTest method testGetAllUserNames3.

/**
 * Search for all users starting at <code>ou=roles</code>, looking for objects with
 * <code>objectClass=organizationalRole</code>, and extracting the <code>uid</code> token of the
 * <code>roleOccupant</code> attribute.
 */
@Test
public void testGetAllUserNames3() {
    SearchControls con3 = new SearchControls();
    // $NON-NLS-1$
    con3.setReturningAttributes(new String[] { "roleOccupant" });
    LdapSearchParamsFactory paramsFactory = // $NON-NLS-1$ //$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=roles", "(objectClass=organizationalRole)", con3);
    // $NON-NLS-1$ //$NON-NLS-2$
    Transformer transformer3 = new SearchResultToAttrValueList("roleOccupant", "uid");
    LdapSearch allUsernamesSearch = new GenericLdapSearch(getContextSource(), paramsFactory, transformer3);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllUsernamesSearch(allUsernamesSearch);
    List res = userRoleListService.getAllUsers();
    // $NON-NLS-1$
    assertTrue(res.contains("pat"));
    // $NON-NLS-1$
    assertTrue(res.contains("tiffany"));
    // $NON-NLS-1$
    assertTrue(res.contains("admin"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllUserNames3(): " + res);
    }
}
Also used : DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) LdapSearchParamsFactory(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) SearchControls(javax.naming.directory.SearchControls) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) 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)

Example 4 with LdapSearch

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

the class DefaultLdapUserRoleListServiceTest method testGetAllUserNames2.

/**
 * Search for all users starting at <code>ou=users</code>, looking for objects with <code>objectClass=person</code>,
 * and returning the <code>uniqueMember</code> attribute.
 */
@Test
public void testGetAllUserNames2() {
    SearchControls con2 = new SearchControls();
    // $NON-NLS-1$
    con2.setReturningAttributes(new String[] { "uid" });
    // $NON-NLS-1$ //$NON-NLS-2$
    LdapSearchParamsFactory paramsFactory = new LdapSearchParamsFactoryImpl("ou=users", "(objectClass=person)", con2);
    // $NON-NLS-1$
    Transformer transformer2 = new SearchResultToAttrValueList("uid");
    LdapSearch allUsernamesSearch = new GenericLdapSearch(getContextSource(), paramsFactory, transformer2);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllUsernamesSearch(allUsernamesSearch);
    List res = userRoleListService.getAllUsers();
    // $NON-NLS-1$
    assertTrue(res.contains("pat"));
    // $NON-NLS-1$
    assertTrue(res.contains("admin"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllUserNames2(): " + res);
    }
}
Also used : DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) LdapSearchParamsFactory(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) SearchControls(javax.naming.directory.SearchControls) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) 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)

Example 5 with LdapSearch

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

the class DefaultLdapUserRoleListServiceTest method testGetAllAuthorities1Sorted.

/**
 * Same as above except sorted.
 */
@Test
public void testGetAllAuthorities1Sorted() {
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "cn" });
    LdapSearchParamsFactory paramsFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=roles", "(objectClass=organizationalRole)", con1);
    // $NON-NLS-1$
    Transformer one = new SearchResultToAttrValueList("cn");
    Transformer two = new StringToGrantedAuthority();
    Transformer[] transformers = { one, two };
    Transformer transformer = new ChainedTransformer(transformers);
    LdapSearch rolesSearch = new GenericLdapSearch(getContextSource(), paramsFactory, transformer);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllAuthoritiesSearch(rolesSearch);
    userRoleListService.setRoleComparator(new DefaultRoleComparator());
    List res = userRoleListService.getAllRoles();
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_CTO"));
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_CEO"));
    assertTrue(res.indexOf("ROLE_ADMINISTRATOR") < res.indexOf("ROLE_DEV"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllAuthorities1Sorted(): " + 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) StringToGrantedAuthority(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) DefaultRoleComparator(org.pentaho.platform.engine.security.DefaultRoleComparator) 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) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) 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

SearchControls (javax.naming.directory.SearchControls)13 Transformer (org.apache.commons.collections.Transformer)13 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)13 Test (org.junit.Test)13 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)13 GenericLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch)13 LdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch)13 LdapSearchParamsFactory (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory)13 LdapSearchParamsFactoryImpl (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl)13 UnionizingLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch)13 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)13 ArrayList (java.util.ArrayList)7 List (java.util.List)7 GrantedAuthorityToString (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString)6 StringToGrantedAuthority (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority)5 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ITenant (org.pentaho.platform.api.mt.ITenant)2 Tenant (org.pentaho.platform.core.mt.Tenant)2 HashMap (java.util.HashMap)1