use of org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetAuthoritiesForUser2.
/**
* Get the roles of user <code>suzy</code> by returning the <code>cn</code> attribute of each object that matches base
* of <code>ou=roles</code> and filter of <code>(roleOccupant={0})</code>.
*
* <p>
* Note that the UserDetailsService used by Spring Security is re-used here.
* </p>
*/
@Test
public void testGetAuthoritiesForUser2() {
// $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);
// $NON-NLS-1$
List res = userRoleListService.getRolesForUser(null, "suzy");
// $NON-NLS-1$
assertTrue(res.contains("ROLE_IS"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getAuthoritiesForUser2(): " + res);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService 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);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService 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);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole1.
/**
* Search for all users starting at <code>ou=users</code>, looking for objects with
* <code>businessCategory=cn={0}*</code>, and returning the <code>uid</code> attribute. This search implies that the
* schema is setup such that a user's roles come from one of the user's attributes.
*/
@Test
public void testGetUsernamesInRole1() {
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);
// $NON-NLS-1$
List<String> res = userRoleListService.getUsersInRole(null, "DEV");
// $NON-NLS-1$
assertTrue(res.contains("pat"));
// $NON-NLS-1$
assertTrue(res.contains("tiffany"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getUsernamesInRole1(): " + res);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService 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);
}
}
Aggregations