use of org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString 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.transform.GrantedAuthorityToString 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);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole3.
/**
* Search for all users starting at <code>ou=groups</code>, looking for objects with
* <code>(&(objectClass=groupOfUniqueNames)(cn={0}))</code>, and extracting the <code>uid</code> token of the
* <code>uniqueMember</code> attribute. This search implies that the schema is setup such that a user's roles come
* from that user's DN being present in the <code>uniqueMember</code> attribute of a child object under the
* <code>ou=groups</code> object.
*/
@Test
public void testGetUsernamesInRole3() {
SearchControls con1 = new SearchControls();
// $NON-NLS-1$
con1.setReturningAttributes(new String[] { "uniqueMember" });
LdapSearchParamsFactory paramFactory = // $NON-NLS-1$//$NON-NLS-2$
new LdapSearchParamsFactoryImpl("ou=groups", "(&(objectClass=groupOfUniqueNames)(cn={0}))", con1);
// $NON-NLS-1$ //$NON-NLS-2$
Transformer transformer1 = new SearchResultToAttrValueList("uniqueMember", "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, "DEVELOPMENT");
// $NON-NLS-1$
assertTrue(res.contains("pat"));
// $NON-NLS-1$
assertTrue(res.contains("tiffany"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getUsernamesInRole3(): " + res);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole4.
/**
* Search for all users starting at <code>ou=groups</code>, looking for objects with
* <code>(&(objectClass=groupOfUniqueNames)(cn={0}))</code>, and extracting the <code>uid</code> token of the
* <code>uniqueMember</code> attribute. This search implies that the schema is setup such that a user's roles come
* from that user's DN being present in the <code>uniqueMember</code> attribute of a child object under the
* <code>ou=groups</code> object.
*
* @throws Exception
*/
@Test
public void testGetUsernamesInRole4() throws Exception {
SearchControls con1 = new SearchControls();
// $NON-NLS-1$
con1.setReturningAttributes(new String[] { "uniqueMember" });
LdapSearchParamsFactory paramFactory = // $NON-NLS-1$//$NON-NLS-2$
new LdapSearchParamsFactoryImpl("ou=groups", "(&(objectClass=groupOfUniqueNames)(cn={0}))", con1);
// $NON-NLS-1$ //$NON-NLS-2$
Transformer transformer1 = new SearchResultToAttrValueList("uniqueMember", "uid");
GrantedAuthorityToString transformer2 = new GrantedAuthorityToString();
LdapSearch usernamesInRoleSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1, transformer2);
SearchControls con2 = new SearchControls();
// $NON-NLS-1$
con2.setReturningAttributes(new String[] { "uid" });
LdapSearchParamsFactory paramFactory2 = // $NON-NLS-1$//$NON-NLS-2$
new LdapSearchParamsFactoryImpl("ou=users", "(businessCategory=cn={0}*)", con2);
// $NON-NLS-1$
Transformer transformer3 = new SearchResultToAttrValueList("uid");
GrantedAuthorityToString transformer4 = new GrantedAuthorityToString();
LdapSearch usernamesInRoleSearch2 = new GenericLdapSearch(getContextSource(), paramFactory2, transformer3, transformer4);
Set searches = new HashSet();
searches.add(usernamesInRoleSearch);
searches.add(usernamesInRoleSearch2);
UnionizingLdapSearch unionSearch = new UnionizingLdapSearch(searches);
unionSearch.afterPropertiesSet();
DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
userRoleListService.setUsernamesInRoleSearch(unionSearch);
// $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 getUsernamesInRole4() with role=ROLE_DEV: " + res);
}
// $NON-NLS-1$
res = userRoleListService.getUsersInRole(null, "DEVELOPMENT");
// $NON-NLS-1$
assertTrue(res.contains("pat"));
// $NON-NLS-1$
assertTrue(res.contains("tiffany"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getUsernamesInRole4() with role=DEVELOPMENT: " + res);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole1ForTenant.
@Test
public void testGetUsernamesInRole1ForTenant() {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("suzy", defaultTenant);
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(defaultTenant, "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);
}
try {
userRoleListService.getUsersInRole(new Tenant("/pentaho", true), "DEV");
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
Aggregations