use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoIT method testUpdateRole.
@Test
public void testUpdateRole() throws Exception {
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 });
IPentahoRole pentahoRole = userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_5, null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_5);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_5);
String changedDescription1 = ROLE_DESCRIPTION_5 + "change1";
userRoleDaoProxy.setRoleDescription(mainTenant_1, ROLE_5, changedDescription1);
String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_5 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
assertNotNull(pentahoRole);
assertEquals(changedDescription1, pentahoRole.getDescription());
String changedDescription2 = ROLE_DESCRIPTION_5 + "change2";
userRoleDaoProxy.setRoleDescription(null, ROLE_5 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), changedDescription2);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_5);
assertEquals(changedDescription2, pentahoRole.getDescription());
userRoleDaoProxy.setRoleDescription(null, ROLE_5 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_5);
assertNull(pentahoRole.getDescription());
try {
userRoleDaoProxy.setRoleDescription(null, null, changedDescription2);
fail("Exception not thrown");
} catch (Exception ex) {
// Expected exception
assertNotNull(ex);
}
try {
userRoleDaoProxy.setRoleDescription(mainTenant_1, UNKNOWN_ROLE, changedDescription2);
fail("Exception not thrown");
} catch (NotFoundException ex) {
// Expected exception
assertNotNull(ex);
}
logout();
login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
try {
changedDescription1 = ROLE_DESCRIPTION_5 + "change1";
userRoleDaoProxy.setRoleDescription(mainTenant_1, ROLE_5, changedDescription1);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoIT method testCreateRole.
@Test
public void testCreateRole() throws Exception {
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 });
subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant1_1, "admin", "password", "", new String[] { adminRoleName });
subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant1_2, "admin", "password", "", new String[] { adminRoleName });
subTenant2_1 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant2_1, "admin", "password", "", new String[] { adminRoleName });
subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant2_2, "admin", "password", "", new String[] { adminRoleName });
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
IPentahoRole pentahoRole;
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_1);
assertEquals(pentahoRole.getTenant(), mainTenant_1);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
int DEFAULT_ROLE_COUNT = 3;
List<IPentahoRole> roles = userRoleDaoProxy.getRoles(mainTenant_1);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_1) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), mainTenant_1);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
logout();
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
try {
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
pentahoRole = userRoleDaoProxy.createRole(mainTenant_2, ROLE_1, ROLE_DESCRIPTION_2, null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_2, ROLE_1);
assertEquals(pentahoRole.getTenant(), mainTenant_2);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_2);
roles = userRoleDaoProxy.getRoles(mainTenant_2);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_1) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), mainTenant_2);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_2);
logout();
login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
try {
pentahoRole = userRoleDaoProxy.createRole(mainTenant_2, ROLE_1, ROLE_DESCRIPTION_1, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
userRoleDaoProxy.createRole(null, ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_3, null);
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getTenant(), subTenant2_1);
assertEquals(pentahoRole.getName(), ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_3);
roles = userRoleDaoProxy.getRoles(subTenant2_1);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath()) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), subTenant2_1);
assertEquals(pentahoRole.getName(), ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_3);
logout();
login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
try {
pentahoRole = userRoleDaoProxy.createRole(subTenant2_1, ROLE_3, ROLE_DESCRIPTION_3, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
pentahoRole = userRoleDaoProxy.createRole(null, ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_4, null);
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getTenant(), subTenant1_1);
assertEquals(pentahoRole.getName(), ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_4);
roles = userRoleDaoProxy.getRoles(subTenant1_1);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath()) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), subTenant1_1);
assertEquals(pentahoRole.getName(), ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_4);
logout();
login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
try {
pentahoRole = userRoleDaoProxy.createRole(subTenant1_1, ROLE_3, ROLE_DESCRIPTION_3, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
try {
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
fail("Exception not thrown");
} catch (AlreadyExistsException e) {
// Expected exception
}
logout();
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoService method removeRolesFromUser.
public void removeRolesFromUser(String userName, String roleNames) throws NotFoundException, UncategorizedUserRoleDaoException, SecurityException {
if (canAdminister()) {
StringTokenizer tokenizer = new StringTokenizer(roleNames, "\t");
Set<String> assignedRoles = new HashSet<>();
ITenant tenant = TenantUtils.getCurrentTenant();
for (IPentahoRole pentahoRole : getRoleDao().getUserRoles(tenant, userName)) {
assignedRoles.add(pentahoRole.getName());
}
while (tokenizer.hasMoreTokens()) {
assignedRoles.remove(tokenizer.nextToken());
}
getRoleDao().setUserRoles(tenant, userName, assignedRoles.toArray(new String[assignedRoles.size()]));
} else {
throw new SecurityException();
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoResource method assignAllRolesToUser.
/**
* Associate all roles to the selected user
*
* @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
* @param userName (username)
* @return
*/
@PUT
@Path("/assignAllRolesToUser")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignAllRolesToUser(@QueryParam("tenant") String tenantPath, @QueryParam("userName") String userName) {
IUserRoleDao roleDao = getUserRoleDao();
Set<String> assignedRoles = new HashSet<String>();
for (IPentahoRole pentahoRole : roleDao.getRoles(getTenant(tenantPath))) {
assignedRoles.add(pentahoRole.getName());
}
roleDao.setUserRoles(getTenant(tenantPath), userName, assignedRoles.toArray(new String[0]));
if (userName.equals(getSession().getName())) {
updateRolesForCurrentSession();
}
return Response.ok().build();
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testGetRoles.
@Test
public void testGetRoles() throws Exception {
List<IPentahoRole> roleList = new ArrayList<>();
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getRoles()).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
IPentahoRole role = mock(IPentahoRole.class);
when(role.getName()).thenReturn("testRole");
roleList.add(role);
RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
assertEquals(wrapRoleList.getRoles(), userRoleService.getRoles().getRoles());
}
Aggregations