use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class JdbcUserRoleListServiceTest method testGetRolesForUserForTenant.
@Test
public void testGetRolesForUserForTenant() throws Exception {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("admin", defaultTenant);
JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
dao.setUserDetailsService(makePopulatedJdbcDao());
dao.afterPropertiesSet();
// $NON-NLS-1$
List<String> roles = dao.getRolesForUser(defaultTenant, "rod");
// $NON-NLS-1$
assertTrue(roles.contains("ROLE_TELLER"));
// $NON-NLS-1$
assertTrue(roles.contains("ROLE_SUPERVISOR"));
try {
roles = dao.getRolesForUser(new Tenant("/pentaho", true), "rod");
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class JdbcUserRoleListServiceTest method testGetAllAuthoritiesWithRolePrefixForTenant.
@Test
public void testGetAllAuthoritiesWithRolePrefixForTenant() throws Exception {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("admin", defaultTenant);
JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
// $NON-NLS-1$
dao.setAllAuthoritiesQuery("SELECT DISTINCT(AUTHORITY) AS AUTHORITY FROM AUTHORITIES ORDER BY 1");
// $NON-NLS-1$
dao.setRolePrefix("ARBITRARY_PREFIX_");
dao.afterPropertiesSet();
List<String> auths = dao.getAllRoles(defaultTenant);
// $NON-NLS-1$
assertTrue("Authorities list should not be empty", auths.size() > 0);
for (String role : auths) {
// $NON-NLS-1$
System.out.println("Authority with prefix: " + role);
}
try {
auths = dao.getAllRoles(new Tenant("/pentaho", true));
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
use of org.pentaho.platform.api.mt.ITenant 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);
}
}
use of org.pentaho.platform.api.mt.ITenant 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);
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDao method createRole.
public IPentahoRole createRole(Session session, final ITenant theTenant, final String roleName, final String description, final String[] memberUserNames) throws AuthorizableExistsException, RepositoryException {
ITenant tenant = theTenant;
String role = roleName;
if (tenant == null) {
tenant = JcrTenantUtils.getTenant(roleName, false);
role = JcrTenantUtils.getPrincipalName(roleName, false);
}
if (tenant == null || tenant.getId() == null) {
tenant = JcrTenantUtils.getCurrentTenant();
}
if (!TenantUtils.isAccessibleTenant(tenant)) {
throw new NotFoundException(Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0006_TENANT_NOT_FOUND", theTenant.getId()));
}
String roleId = tenantedRoleNameUtils.getPrincipleId(tenant, role);
UserManager tenantUserMgr = getUserManager(tenant, session);
// Intermediate path will always be an empty string. The path is already provided while creating a user manager
// $NON-NLS-1$
tenantUserMgr.createGroup(new PrincipalImpl(roleId), "");
setRoleMembers(session, tenant, role, memberUserNames);
setRoleDescription(session, tenant, role, description);
return getRole(session, theTenant, roleName);
}
Aggregations