use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class JcrTenantUtils method getTenantedUser.
public static String getTenantedUser(String username) {
if (username != null && !username.equals(getRepositoryAdminUserName()) && getUserNameUtils() != null) {
ITenant tenant = getUserNameUtils().getTenant(username);
if (tenant == null || tenant.getId() == null) {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
if (tenantId == null) {
tenantId = getDefaultTenantPath();
}
tenant = new Tenant(tenantId, true);
return getUserNameUtils().getPrincipleId(tenant, username);
} else {
return username;
}
} else {
return username;
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class JcrTenantUtils method getTenantedRole.
public static String getTenantedRole(String principal) {
if (principal != null && !principal.equals("administrators") && getRoleNameUtils() != null) {
ITenant tenant = getRoleNameUtils().getTenant(principal);
if (tenant == null || tenant.getId() == null) {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
if (tenantId == null) {
tenantId = getDefaultTenantPath();
}
tenant = new Tenant(tenantId, true);
return getRoleNameUtils().getPrincipleId(tenant, principal);
} else {
return principal;
}
} else {
return principal;
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class PentahoSessionCredentialsStrategy method getUserId.
private String getUserId() {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
Assert.state(pentahoSession != null, "this method cannot be called with a null IPentahoSession");
return JcrTenantUtils.getTenantedUser(pentahoSession.getName());
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class RepositoryTenantManager method createTenant.
/*
* (non-Javadoc)
*
* @see org.pentaho.platform.api.repository2.unified.ITenantManager#createTenant(java.lang.String,
* java.lang.String)
*/
@Override
public ITenant createTenant(final ITenant parentTenant, final String tenantName, final String tenantAdminRoleName, final String authenticatedRoleName, final String anonymousRoleName) {
Tenant newTenant;
String parentTenantFolder;
if (parentTenant == null) {
if (repositoryFileDao.getFileByAbsolutePath("/" + tenantName) != null) {
return null;
}
} else {
if (repositoryFileDao.getFileByAbsolutePath(parentTenant.getRootFolderAbsolutePath() + "/" + tenantName) != null) {
return null;
}
}
if (parentTenant == null) {
newTenant = new Tenant(RepositoryFile.SEPARATOR + tenantName, true);
parentTenantFolder = "/";
} else {
newTenant = new Tenant(parentTenant.getRootFolderAbsolutePath() + RepositoryFile.SEPARATOR + tenantName, true);
parentTenantFolder = parentTenant.getRootFolderAbsolutePath();
}
String tenantCreatorId = PentahoSessionHolder.getSession().getName();
RepositoryFile tenantRootFolder = createTenantFolder(parentTenant, tenantName, tenantCreatorId);
userRoleDao.createRole(newTenant, tenantAdminRoleName, "", new String[0]);
userRoleDao.createRole(newTenant, authenticatedRoleName, "", new String[0]);
userRoleDao.createRole(newTenant, anonymousRoleName, "", new String[0]);
roleBindingDao.setRoleBindings(newTenant, authenticatedRoleName, singleTenantAuthenticatedAuthorityRoleBindingList);
String tenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId(newTenant, tenantAdminRoleName);
RepositoryFileSid tenantAdminRoleSid = new RepositoryFileSid(tenantAdminRoleId, Type.ROLE);
this.jcrTemplate.save();
// tenant admin permissions on the root folder.
if (parentTenant == null) {
repositoryFileAclDao.addAce(tenantRootFolder.getId(), tenantAdminRoleSid, EnumSet.of(RepositoryFilePermission.ALL));
} else {
RepositoryFileAcl acl = repositoryFileAclDao.getAcl(tenantRootFolder.getId());
Builder aclBuilder = new RepositoryFileAcl.Builder(acl).ace(tenantAdminRoleSid, EnumSet.of(RepositoryFilePermission.ALL));
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
login(repositoryAdminUsername, tenantAdminRoleId);
try {
// Give all to Tenant Admin of all ancestors
while (!parentTenantFolder.equals("/")) {
ITenant tenant = new Tenant(parentTenantFolder, true);
String parentTenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId(tenant, tenantAdminRoleName);
RepositoryFileSid parentTenantAdminSid = new RepositoryFileSid(parentTenantAdminRoleId, Type.ROLE);
aclBuilder.ace(parentTenantAdminSid, EnumSet.of(RepositoryFilePermission.ALL));
parentTenantFolder = FilenameUtils.getFullPathNoEndSeparator(parentTenantFolder);
}
repositoryFileAclDao.updateAcl(aclBuilder.build());
} catch (Throwable th) {
th.printStackTrace();
} finally {
PentahoSessionHolder.setSession(origPentahoSession);
SecurityContextHolder.getContext().setAuthentication(origAuthentication);
}
}
try {
RepositoryFileSid fileOwnerSid = new RepositoryFileSid(tenantCreatorId);
createInitialTenantFolders(newTenant, tenantRootFolder, fileOwnerSid);
} catch (Exception ex) {
throw new RuntimeException("Error creating initial tenant folders", ex);
}
return newTenant;
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testOnLogout.
public void testOnLogout() throws Exception {
// $NON-NLS-1$
final String ID1 = "1";
// $NON-NLS-1$
final String ID2 = "2";
MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
repo.storeDomain(getTestDomain(ID1), false);
repo.storeDomain(getTestDomain(ID2), false);
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
repo.getDomain(ID1);
// $NON-NLS-1$ //$NON-NLS-2$
IPentahoSession session2 = new StandaloneSession("Standalone Session", "2");
PentahoSessionHolder.setSession(session2);
repo.getDomain(ID2);
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Logging out session 2 should only remove cached domains from session 2
repo.onLogout(session2);
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Aggregations