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);
}
}
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);
}
}
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"));
}
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"));
}
Aggregations