use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class DefaultTenantedPrincipleNameResolverTest method testIsValid.
@Test
public void testIsValid() {
DefaultTenantedPrincipleNameResolver resolver = new DefaultTenantedPrincipleNameResolver();
resolver.setDelimeter(DefaultTenantedPrincipleNameResolver.ALTERNATE_DELIMETER);
Assert.assertEquals(resolver.isValid("pentaho_user"), false);
}
use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver 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.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class ExportManifestEntity method createEntityAcl.
private void createEntityAcl(RepositoryFileAcl repositoryFileAcl) {
DefaultTenantedPrincipleNameResolver nameResolver = new DefaultTenantedPrincipleNameResolver();
if (repositoryFileAcl == null) {
return;
}
entityAcl = new EntityAcl();
entityAcl.setEntriesInheriting(repositoryFileAcl.isEntriesInheriting());
entityAcl.setOwner(nameResolver.getPrincipleName(repositoryFileAcl.getOwner().getName()));
entityAcl.setOwnerType(repositoryFileAcl.getOwner().getType().name());
List<EntityAcl.Aces> aces = entityAcl.getAces();
aces.clear();
for (RepositoryFileAce repositoryFileAce : repositoryFileAcl.getAces()) {
EntityAcl.Aces ace = new EntityAcl.Aces();
ace.setRecipient(nameResolver.getPrincipleName(repositoryFileAce.getSid().getName()));
ace.setRecipientType(repositoryFileAce.getSid().getType().name());
List<String> permissions = ace.getPermissions();
for (RepositoryFilePermission permission : repositoryFileAce.getPermissions()) {
permissions.add(permission.toString());
}
aces.add(ace);
}
}
use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryBase method initialize.
public void initialize(boolean multiByteEncoding) throws Exception {
loginAsRepositoryAdmin();
SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
mp = new MicroPlatform(getSolutionPath());
// used by DefaultPentahoJackrabbitAccessControlHelper
mp.defineInstance("tenantedUserNameUtils", userNameUtils);
mp.defineInstance("tenantedRoleNameUtils", roleNameUtils);
mp.defineInstance("ILockHelper", new DefaultLockHelper(userNameUtils));
mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
mp.defineInstance(ITenantManager.class, tenantManager);
mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(this.jcrTemplate, this.repositoryFileDao));
mp.defineInstance("ITenantedPrincipleNameResolver", new DefaultTenantedPrincipleNameResolver());
mp.defineInstance("useMultiByteEncoding", multiByteEncoding);
mp.defineInstance(IUnifiedRepository.class, repo);
mp.defineInstance(IRepositoryFileAclDao.class, repositoryFileAclDao);
IUserRoleListService userRoleListService = mock(IUserRoleListService.class);
when(userRoleListService.getRolesForUser(any(ITenant.class), anyString())).thenReturn(Arrays.asList(tenantAdminRoleName, AUTHENTICATED_ROLE_NAME));
mp.defineInstance(IUserRoleListService.class, userRoleListService);
mp.defineInstance("singleTenantAdminUserName", singleTenantAdminUserName);
mp.defineInstance("singleTenantAdminAuthorityName", tenantAdminRoleName);
// Start the micro-platform
mp.start();
loginAsRepositoryAdmin();
setAclManagement();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(systemTenant, sysAdminUserName, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
}
use of org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT 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
}
}
Aggregations