use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoIT method testDeleteRole.
@Test
public void testDeleteRole() throws Exception {
int DEFAULT_ROLE_COUNT = 3;
loginAsRepositoryAdmin();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
IPentahoRole pentahoRole = userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_6, null);
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
assertNotNull(pentahoRole);
logout();
login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
try {
userRoleDaoProxy.deleteRole(pentahoRole);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
assertNull(pentahoRole);
assertEquals(DEFAULT_ROLE_COUNT, userRoleDaoProxy.getRoles(mainTenant_1).size());
pentahoRole = userRoleDaoProxy.createRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_6, null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_6);
assertNotNull(pentahoRole);
userRoleDaoProxy.deleteRole(pentahoRole);
assertNull(userRoleDaoProxy.getRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath()));
try {
userRoleDaoProxy.deleteRole(pentahoRole);
fail("Exception not thrown");
} catch (NotFoundException e) {
// Expected exception
}
try {
pentahoRole = new PentahoRole(null, ROLE_6, ROLE_DESCRIPTION_6);
userRoleDaoProxy.deleteRole(pentahoRole);
fail("Exception not thrown");
} catch (Exception ex) {
// Expected exception
}
try {
pentahoRole = new PentahoRole(mainTenant_1, null, ROLE_DESCRIPTION_6);
userRoleDaoProxy.deleteRole(pentahoRole);
fail("Exception not thrown");
} catch (NotFoundException e) {
// Expected exception
}
try {
pentahoRole = new PentahoRole(mainTenant_1, UNKNOWN_ROLE, ROLE_DESCRIPTION_6);
userRoleDaoProxy.deleteRole(pentahoRole);
fail("Exception not thrown");
} catch (NotFoundException e) {
// Expected exception
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoIT method createAndTestRole.
public void createAndTestRole(ITenant tenant, String roleName) {
userRoleDaoProxy.createRole(tenant, roleName, ROLE_DESCRIPTION_1, null);
IPentahoRole pentahoRole = userRoleDaoProxy.getRole(tenant, roleName);
assertEquals(pentahoRole.getTenant(), tenant);
assertEquals(pentahoRole.getName(), roleName);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoIT method testGetRoles.
@Test
public void testGetRoles() throws Exception {
int DEFAULT_ROLE_COUNT = 3;
loginAsRepositoryAdmin();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_7, ROLE_DESCRIPTION_7, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_8, ROLE_DESCRIPTION_8, null);
List<IPentahoRole> roles = userRoleDaoProxy.getRoles(mainTenant_1);
assertEquals(2 + DEFAULT_ROLE_COUNT, roles.size());
for (IPentahoRole user : roles) {
if (user.getName().equals(ROLE_7)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.getDescription(), ROLE_DESCRIPTION_7);
} else if (user.getName().equals(ROLE_8)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.getDescription(), ROLE_DESCRIPTION_8);
}
}
try {
roles = userRoleDaoProxy.getRoles(UNKNOWN_TENANT);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
}
Aggregations