Search in sources :

Example 1 with DefaultRoleComparator

use of org.pentaho.platform.engine.security.DefaultRoleComparator in project pentaho-platform by pentaho.

the class DefaultLdapUserRoleListServiceTest method testGetAuthoritiesForUser2Sorted.

/**
 * Same as above except sorted.
 */
@Test
public void testGetAuthoritiesForUser2Sorted() {
    // $NON-NLS-1$
    DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), "ou=roles");
    // $NON-NLS-1$
    populator.setGroupRoleAttribute("cn");
    // $NON-NLS-1$
    populator.setGroupSearchFilter("(roleOccupant={0})");
    // $NON-NLS-1$//$NON-NLS-2$
    LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})");
    LdapUserDetailsService service = new LdapUserDetailsService(userSearch, populator);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setUserDetailsService(service);
    userRoleListService.setRoleComparator(new DefaultRoleComparator());
    // $NON-NLS-1$
    List res = userRoleListService.getRolesForUser(null, "suzy");
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_POWER_USER"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAuthoritiesForUser2Sorted(): " + res);
    }
}
Also used : LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) DefaultRoleComparator(org.pentaho.platform.engine.security.DefaultRoleComparator) DefaultLdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) LdapUserSearch(org.springframework.security.ldap.search.LdapUserSearch) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) Test(org.junit.Test)

Example 2 with DefaultRoleComparator

use of org.pentaho.platform.engine.security.DefaultRoleComparator 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 DefaultRoleComparator

use of org.pentaho.platform.engine.security.DefaultRoleComparator in project pentaho-platform by pentaho.

the class InMemoryUserRoleListServiceTest method testGetAllAuthoritiesSorted.

@Test
public void testGetAllAuthoritiesSorted() throws Exception {
    dao.setRoleComparator(new DefaultRoleComparator());
    List<String> authorities = dao.getAllRoles();
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("testGetAllAuthoritiesSorted(): Authorities: " + authorities);
    }
    assertTrue(authorities.indexOf("ROLE_THREE") < authorities.indexOf("ROLE_TWO"));
}
Also used : DefaultRoleComparator(org.pentaho.platform.engine.security.DefaultRoleComparator) Test(org.junit.Test)

Example 4 with DefaultRoleComparator

use of org.pentaho.platform.engine.security.DefaultRoleComparator in project pentaho-platform by pentaho.

the class InMemoryUserRoleListServiceTest method testGetRolesForUserSorted.

@Test
public void testGetRolesForUserSorted() throws Exception {
    dao.setRoleComparator(new DefaultRoleComparator());
    // $NON-NLS-1$
    List<String> authorities = dao.getRolesForUser(null, "scott");
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("testGetRolesForUser(): Roles: " + authorities);
    }
    assertTrue(authorities.indexOf("ROLE_ONE") < authorities.indexOf("ROLE_THREE"));
}
Also used : DefaultRoleComparator(org.pentaho.platform.engine.security.DefaultRoleComparator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DefaultRoleComparator (org.pentaho.platform.engine.security.DefaultRoleComparator)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)2 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)2 SearchControls (javax.naming.directory.SearchControls)1 Transformer (org.apache.commons.collections.Transformer)1 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)1 GenericLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch)1 LdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch)1 LdapSearchParamsFactory (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory)1 LdapSearchParamsFactoryImpl (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl)1 UnionizingLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch)1 StringToGrantedAuthority (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority)1 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)1 LdapUserSearch (org.springframework.security.ldap.search.LdapUserSearch)1 DefaultLdapAuthoritiesPopulator (org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator)1 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)1