use of org.apache.commons.collections.Transformer in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetAllUserNames1.
/**
* Search for all users starting at <code>ou=groups</code>, looking for objects with
* <code>objectClass=groupOfUniqueNames</code>, and extracting the <code>uid</code> token of the
* <code>uniqueMember</code> attribute.
*/
@Test
public void testGetAllUserNames1() 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);
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 getAllUserNames1(): " + res);
}
}
use of org.apache.commons.collections.Transformer 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);
}
}
use of org.apache.commons.collections.Transformer 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);
}
}
use of org.apache.commons.collections.Transformer 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);
}
}
use of org.apache.commons.collections.Transformer 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);
}
}
Aggregations