use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class JcrRoleAuthorizationPolicyRoleBindingDao method setRoleBindings.
@Override
public void setRoleBindings(final ITenant tenant, final String runtimeRoleName, final List<String> logicalRoleNames) {
ITenant tempTenant = tenant;
if (tenant == null) {
tempTenant = JcrTenantUtils.getTenant(runtimeRoleName, false);
}
if (!TenantUtils.isAccessibleTenant(tempTenant)) {
throw new NotFoundException("Tenant " + tenant.getId() + " not found");
}
Assert.notNull(logicalRoleNames);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
setRoleBindings(session, tenant, runtimeRoleName, logicalRoleNames);
return null;
}
});
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class UserRoleDaoUserRoleListService method getRolesForUser.
@Override
public List<String> getRolesForUser(ITenant tenant, String username) throws UsernameNotFoundException, DataAccessException {
String userToSearch = username;
// Extract Tenant from the user name
ITenant tenantFromUser = JcrTenantUtils.getTenant(username, true);
if (tenantFromUser == null || tenantFromUser.getId() == null) {
// No tenant information in the user name so we check the tenant argument
if (tenant == null || tenant.getId() == null) {
// No tenant provided so we assume default tenant
tenant = JcrTenantUtils.getDefaultTenant();
}
userToSearch = usernamePrincipalResolver.getPrincipleId(tenant, username);
}
UserDetails user = userDetailsService.loadUserByUsername(userToSearch);
List<String> roles = new ArrayList<String>(user.getAuthorities().size());
for (GrantedAuthority role : user.getAuthorities()) {
String principalName = role.getAuthority();
roles.add(principalName);
}
return roles;
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class MetadataRepositoryLifecycleManagerIT method testDoNewTenant.
@Test
public void testDoNewTenant() throws Exception {
loginAsRepositoryAdmin();
ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, tenantAuthenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, tenantAuthenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName, tenantAuthenticatedAuthorityName });
login("admin", mainTenant_1, new String[] { adminAuthorityName, tenantAuthenticatedAuthorityName });
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_3", Mode.CUSTOM);
dumpToFile.execute();
metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
String metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
RepositoryFile metadataRepositoryPath = repo.getFile(metadataPath);
assertTrue(metadataRepositoryPath.getPath() != null);
// Nothing should change if we run it again
metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
metadataRepositoryPath = repo.getFile(metadataPath);
assertTrue(metadataRepositoryPath.getPath() != null);
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class RepositoryImportResourceIT method setUp.
@Before
public void setUp() throws ObjectFactoryException {
PentahoSystem.init();
ITenant tenat = mock(ITenant.class);
resolver = mock(ITenantedPrincipleNameResolver.class);
doReturn(tenat).when(resolver).getTenant(anyString());
doReturn(REAL_USER).when(resolver).getPrincipleName(anyString());
policy = mock(IAuthorizationPolicy.class);
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
return policy;
}
if (invocation.getArguments()[0].equals(ITenantedPrincipleNameResolver.class)) {
return resolver;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
IPentahoSession session = mock(IPentahoSession.class);
doReturn("sampleSession").when(session).getName();
PentahoSessionHolder.setSession(session);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method testStopThenStartInheriting.
@Test
public void testStopThenStartInheriting() throws Exception {
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
login(USERNAME_TIFFANY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile tiffanyHomeFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_TIFFANY));
RepositoryFile testFolder = repo.createFolder(tiffanyHomeFolder.getId(), new RepositoryFile.Builder("test").folder(true).build(), null);
RepositoryFileAcl acl = repo.getAcl(testFolder.getId());
RepositoryFileAcl updatedAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(false).build();
updatedAcl = repo.updateAcl(updatedAcl);
assertFalse(updatedAcl.isEntriesInheriting());
updatedAcl = new RepositoryFileAcl.Builder(updatedAcl).entriesInheriting(true).build();
updatedAcl = repo.updateAcl(updatedAcl);
assertTrue(updatedAcl.isEntriesInheriting());
}
Aggregations