Search in sources :

Example 1 with StringToGrantedAuthority

use of org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority 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 StringToGrantedAuthority

use of org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority 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)

Example 3 with StringToGrantedAuthority

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

the class DefaultLdapUserRoleListServiceTest method testGetAllAuthorities1ForTenant.

@Test
public void testGetAllAuthorities1ForTenant() {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("suzy", defaultTenant);
    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(defaultTenant);
    // $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);
    }
    try {
        userRoleListService.getAllRoles(new Tenant("/pentaho", true));
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
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) ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) 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)

Example 4 with StringToGrantedAuthority

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

the class DefaultLdapUserRoleListServiceTest method testGetAllAuthorities2.

/**
 * Search for all roles (aka authorities) starting at <code>ou=groups</code>, looking for objects with
 * <code>objectClass=groupOfUniqueNames</code>, and returning the <code>cn</code> attribute.
 */
@Test
public void testGetAllAuthorities2() {
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "cn" });
    LdapSearchParamsFactory paramsFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=groups", "(objectClass=groupOfUniqueNames)", 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_SALES"));
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_MARKETING"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllAuthorities2(): " + 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 5 with StringToGrantedAuthority

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

the class DefaultLdapUserRoleListServiceTest method testGetAllAuthorities3.

/**
 * Union the results of two different searches.
 * <ul>
 * <li>Search 1: Search for all roles (aka authorities) starting at <code>ou=groups</code>, looking for objects with
 * <code>objectClass=groupOfUniqueNames</code>, and returning the <code>cn</code> attribute.</li>
 * <li>Search 2: 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.</li>
 * </ul>
 */
@Test
public void testGetAllAuthorities3() throws Exception {
    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);
    SearchControls con2 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "cn" });
    LdapSearchParamsFactory paramsFactory2 = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=groups", "(objectClass=groupOfUniqueNames)", con2);
    // $NON-NLS-1$
    Transformer oneB = new SearchResultToAttrValueList("cn");
    Transformer twoB = new StringToGrantedAuthority();
    Transformer[] transformers2 = { oneB, twoB };
    Transformer transformer2 = new ChainedTransformer(transformers2);
    LdapSearch rolesSearch2 = new GenericLdapSearch(getContextSource(), paramsFactory2, transformer2);
    Set searches = new HashSet();
    searches.add(rolesSearch);
    searches.add(rolesSearch2);
    UnionizingLdapSearch unionSearch = new UnionizingLdapSearch(searches);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllAuthoritiesSearch(unionSearch);
    List res = userRoleListService.getAllRoles();
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_DEVMGR"));
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_DEVELOPMENT"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllAuthorities3(): " + 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) HashSet(java.util.HashSet) Set(java.util.Set) StringToGrantedAuthority(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) UnionizingLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

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