Search in sources :

Example 1 with DefaultUsernameComparator

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

the class DefaultLdapUserRoleListServiceTest method testGetAllUserNames1Sorted.

/**
 * Same as above except sorted.
 */
@Test
public void testGetAllUserNames1Sorted() throws Exception {
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "uniqueMember" });
    LdapSearchParamsFactoryImpl paramFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=groups", "(objectClass=groupOfUniqueNames)", con1);
    paramFactory.afterPropertiesSet();
    // $NON-NLS-1$ //$NON-NLS-2$
    Transformer transformer1 = new SearchResultToAttrValueList("uniqueMember", "uid");
    GenericLdapSearch allUsernamesSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1);
    allUsernamesSearch.afterPropertiesSet();
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllUsernamesSearch(allUsernamesSearch);
    userRoleListService.setUsernameComparator(new DefaultUsernameComparator());
    List res = userRoleListService.getAllUsers();
    assertTrue(res.indexOf("pat") < res.indexOf("tiffany"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllUserNames1Sorted(): " + res);
    }
}
Also used : DefaultUsernameComparator(org.pentaho.platform.engine.security.DefaultUsernameComparator) DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) 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) LdapSearchParamsFactoryImpl(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl) Test(org.junit.Test)

Example 2 with DefaultUsernameComparator

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

the class InMemoryUserRoleListServiceTest method testGetAllUserNamesSorted.

@Test
public void testGetAllUserNamesSorted() throws Exception {
    dao.setUsernameComparator(new DefaultUsernameComparator());
    List<String> usernames = dao.getAllUsers();
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("testGetAllUserNamesSorted(): Usernames: " + usernames);
    }
    assertTrue(usernames.indexOf("marissa") < usernames.indexOf("scott"));
}
Also used : DefaultUsernameComparator(org.pentaho.platform.engine.security.DefaultUsernameComparator) Test(org.junit.Test)

Example 3 with DefaultUsernameComparator

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

the class InMemoryUserRoleListServiceTest method testGetAllUserNamesInRoleSorted.

@Test
public void testGetAllUserNamesInRoleSorted() throws Exception {
    dao.setUsernameComparator(new DefaultUsernameComparator());
    List<String> usernames = dao.getUsersInRole(null, "ROLE_ONE");
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("testGetAllUserNamesInRoleSorted(): Usernames: " + usernames);
    }
    assertTrue(usernames.indexOf("marissa") < usernames.indexOf("scott"));
}
Also used : DefaultUsernameComparator(org.pentaho.platform.engine.security.DefaultUsernameComparator) Test(org.junit.Test)

Example 4 with DefaultUsernameComparator

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

the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole1Sorted.

/**
 * Same as above except sorted.
 */
@Test
public void testGetUsernamesInRole1Sorted() {
    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);
    userRoleListService.setUsernameComparator(new DefaultUsernameComparator());
    // $NON-NLS-1$
    List<String> res = userRoleListService.getUsersInRole(null, "DEV");
    // $NON-NLS-1$
    assertTrue(res.contains("pat"));
    // $NON-NLS-1$
    assertTrue(res.contains("tiffany"));
    assertTrue(res.indexOf("pat") < res.indexOf("tiffany"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getUsernamesInRole1Sorted(): " + res);
    }
}
Also used : DefaultUsernameComparator(org.pentaho.platform.engine.security.DefaultUsernameComparator) 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)

Aggregations

Test (org.junit.Test)4 DefaultUsernameComparator (org.pentaho.platform.engine.security.DefaultUsernameComparator)4 SearchControls (javax.naming.directory.SearchControls)2 Transformer (org.apache.commons.collections.Transformer)2 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)2 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)2 GenericLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch)2 LdapSearchParamsFactoryImpl (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl)2 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)2 ArrayList (java.util.ArrayList)1 List (java.util.List)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 UnionizingLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch)1 GrantedAuthorityToString (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString)1