use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT 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.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT method testRoleWithMembers.
@Test
public void testRoleWithMembers() 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 });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, new String[] { ROLE_1 });
userRoleDaoProxy.createUser(mainTenant_1, USER_3, PASSWORD_3, USER_DESCRIPTION_3, new String[] { ROLE_1, ROLE_2 });
List<IPentahoUser> users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_2);
assertEquals(1, users.size());
assertEquals(USER_3, users.get(0).getUsername());
ArrayList<String> expectedUserNames = new ArrayList<String>();
expectedUserNames.add(USER_2);
expectedUserNames.add(USER_3);
ArrayList<String> actualUserNames = new ArrayList<String>();
String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
users = userRoleDaoProxy.getRoleMembers(null, ROLE_1 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
for (IPentahoUser user : users) {
actualUserNames.add(user.getUsername());
}
assertEquals(2, actualUserNames.size());
assertTrue(actualUserNames.containsAll(expectedUserNames));
users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_3);
assertEquals(0, users.size());
userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_6, new String[] { USER_5 });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_7, new String[] { USER_5, USER_6 });
ArrayList<String> expectedRoleNames = new ArrayList<String>();
expectedRoleNames.add(ROLE_6);
expectedRoleNames.add(authenticatedRoleName);
ArrayList<String> actualRoleNames = new ArrayList<String>();
List<IPentahoRole> roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_6);
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(2, roles.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
expectedRoleNames = new ArrayList<String>();
expectedRoleNames.add(ROLE_5);
expectedRoleNames.add(ROLE_6);
expectedRoleNames.add(authenticatedRoleName);
actualRoleNames = new ArrayList<String>();
roles = userRoleDaoProxy.getUserRoles(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(3, actualRoleNames.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_7);
assertEquals(1, roles.size());
assertEquals(authenticatedRoleName, roles.get(0).getName());
userRoleDaoProxy.setUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), new String[] { ROLE_5, ROLE_6 });
roles = userRoleDaoProxy.getUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
actualRoleNames.clear();
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(3, actualRoleNames.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
expectedUserNames = new ArrayList<String>();
expectedUserNames.add(USER_1);
expectedUserNames.add(USER_2);
expectedRoleNames.add(authenticatedRoleName);
userRoleDaoProxy.setRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), new String[] { USER_1, USER_2 });
users = userRoleDaoProxy.getRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
actualUserNames.clear();
for (IPentahoUser user : users) {
actualUserNames.add(user.getUsername());
}
assertEquals(2, actualUserNames.size());
assertTrue(actualUserNames.containsAll(expectedUserNames));
}
use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver 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.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class UserRoleDaoIT method testRoleWithMembers.
@Test
public void testRoleWithMembers() 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 });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, new String[] { ROLE_1 });
userRoleDaoProxy.createUser(mainTenant_1, USER_3, PASSWORD_3, USER_DESCRIPTION_3, new String[] { ROLE_1, ROLE_2 });
List<IPentahoUser> users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_2);
assertEquals(1, users.size());
assertEquals(USER_3, users.get(0).getUsername());
ArrayList<String> expectedUserNames = new ArrayList<String>();
expectedUserNames.add(USER_2);
expectedUserNames.add(USER_3);
ArrayList<String> actualUserNames = new ArrayList<String>();
String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
users = userRoleDaoProxy.getRoleMembers(null, ROLE_1 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
for (IPentahoUser user : users) {
actualUserNames.add(user.getUsername());
}
assertEquals(2, actualUserNames.size());
assertTrue(actualUserNames.containsAll(expectedUserNames));
users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_3);
assertEquals(0, users.size());
userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_6, new String[] { USER_5 });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_7, new String[] { USER_5, USER_6 });
ArrayList<String> expectedRoleNames = new ArrayList<String>();
expectedRoleNames.add(ROLE_6);
expectedRoleNames.add(authenticatedRoleName);
ArrayList<String> actualRoleNames = new ArrayList<String>();
List<IPentahoRole> roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_6);
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(2, roles.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
expectedRoleNames = new ArrayList<String>();
expectedRoleNames.add(ROLE_5);
expectedRoleNames.add(ROLE_6);
expectedRoleNames.add(authenticatedRoleName);
actualRoleNames = new ArrayList<String>();
roles = userRoleDaoProxy.getUserRoles(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(3, actualRoleNames.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_7);
assertEquals(1, roles.size());
assertEquals(authenticatedRoleName, roles.get(0).getName());
userRoleDaoProxy.setUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), new String[] { ROLE_5, ROLE_6 });
roles = userRoleDaoProxy.getUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
actualRoleNames.clear();
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(3, actualRoleNames.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
expectedUserNames = new ArrayList<String>();
expectedUserNames.add(USER_1);
expectedUserNames.add(USER_2);
expectedRoleNames.add(authenticatedRoleName);
userRoleDaoProxy.setRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), new String[] { USER_1, USER_2 });
users = userRoleDaoProxy.getRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
actualUserNames.clear();
for (IPentahoUser user : users) {
actualUserNames.add(user.getUsername());
}
assertEquals(2, actualUserNames.size());
assertTrue(actualUserNames.containsAll(expectedUserNames));
}
use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method getDefaultLdapUserRoleListService.
private DefaultLdapUserRoleListService getDefaultLdapUserRoleListService(Map<String, String> roleMap) {
IAuthenticationRoleMapper roleMapper = new DefaultLdapRoleMapper(roleMap);
DefaultLdapUserRoleListService defaultLdapUserRoleListService = new DefaultLdapUserRoleListService(null, null, roleMapper);
defaultLdapUserRoleListService.setExtraRoles(Arrays.asList(ROLES));
defaultLdapUserRoleListService.setUserNameUtils(new DefaultTenantedPrincipleNameResolver());
defaultLdapUserRoleListService.setRoleNameUtils(new DefaultTenantedPrincipleNameResolver("_"));
return defaultLdapUserRoleListService;
}
Aggregations