use of org.pentaho.platform.plugin.services.security.userrole.ldap.NoOpLdapAuthoritiesPopulator in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetAuthoritiesForUser1.
/**
* Get the roles of user <code>suzy</code> by extracting the <code>cn</code> token from the <code>uniqueMember</code>
* attribute of the object that matches base of <code>ou=users</code> and filter of <code>(uid={0})</code>.
*
* <p>
* Note that the UserDetailsService used by Spring Security is re-used here.
* </p>
*
* @throws Exception
*/
@Test
public void testGetAuthoritiesForUser1() throws Exception {
// $NON-NLS-1$//$NON-NLS-2$
LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})");
LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator());
RolePreprocessingMapper mapper = new RolePreprocessingMapper();
// $NON-NLS-1$
mapper.setRoleAttributes(new String[] { "uniqueMember" });
// $NON-NLS-1$
mapper.setTokenName("cn");
service.setUserDetailsMapper(mapper);
DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
userRoleListService.setUserDetailsService(service);
// $NON-NLS-1$
List res = userRoleListService.getRolesForUser(null, "suzy");
// $NON-NLS-1$
assertTrue(res.contains("ROLE_A"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getAuthoritiesForUser1(): " + res);
}
}
use of org.pentaho.platform.plugin.services.security.userrole.ldap.NoOpLdapAuthoritiesPopulator in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetAuthoritiesForUser1ForTenant.
@Test
public void testGetAuthoritiesForUser1ForTenant() throws Exception {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("suzy", defaultTenant);
// $NON-NLS-1$//$NON-NLS-2$
LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})");
LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator());
RolePreprocessingMapper mapper = new RolePreprocessingMapper();
// $NON-NLS-1$
mapper.setRoleAttributes(new String[] { "uniqueMember" });
// $NON-NLS-1$
mapper.setTokenName("cn");
service.setUserDetailsMapper(mapper);
DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
userRoleListService.setUserDetailsService(service);
// $NON-NLS-1$
List res = userRoleListService.getRolesForUser(defaultTenant, "suzy");
// $NON-NLS-1$
assertTrue(res.contains("ROLE_A"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getAuthoritiesForUser1(): " + res);
}
try {
userRoleListService.getRolesForUser(new Tenant("/pentaho", true), "suzy");
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
Aggregations