use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl 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.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class DefaultUnifiedRepository method updateAcl.
/**
* {@inheritDoc}
*/
public RepositoryFileAcl updateAcl(final RepositoryFileAcl acl) {
Assert.notNull(acl);
RepositoryFile file = getFileById(acl.getId());
List<RepositoryFilePermission> perms = new ArrayList<RepositoryFilePermission>();
perms.add(RepositoryFilePermission.ACL_MANAGEMENT);
if (!hasAccess(file.getPath(), EnumSet.copyOf(perms))) {
throw new UnifiedRepositoryAccessDeniedException(Messages.getInstance().getString("DefaultUnifiedRepository.ERROR_0001_ACCESS_DENIED_UPDATE_ACL", acl.getId()));
}
return repositoryFileAclDao.updateAcl(acl);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class RepositoryUtils method getFolder.
public RepositoryFile getFolder(final String path, final RepositoryFileAcl acl, final boolean createIfNotExist, final boolean createParents, final String versionMessage) {
RepositoryFile folder = repository.getFile(path);
if (null == folder && createIfNotExist) {
final String parentPath = RepositoryFilenameUtils.getFullPathNoEndSeparator(path);
if (!parentPath.equals(path)) {
final RepositoryFile parentFolder = getFolder(parentPath, acl, createParents, createParents, versionMessage);
if (null != parentFolder) {
final String folderName = RepositoryFilenameUtils.getName(path);
folder = new RepositoryFile.Builder(folderName).path(path).folder(true).build();
if (null != acl) {
folder = repository.createFolder(parentFolder.getId(), folder, acl, versionMessage);
} else {
folder = repository.createFolder(parentFolder.getId(), folder, versionMessage);
}
}
}
}
return folder;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class MondrianImportHandlerTest method testImportFile_applyAclSettings.
@Test
public void testImportFile_applyAclSettings() throws Exception {
RepositoryFileAcl acl = mock(RepositoryFileAcl.class);
when(bundle.getProperty(eq(MondrianImportHandler.DOMAIN_ID))).thenReturn(MondrianImportHandler.DOMAIN_ID);
when(bundle.isApplyAclSettings()).thenReturn(true);
when(bundle.getAcl()).thenReturn(acl);
IAclAwareMondrianCatalogService aclImporter = mock(IAclAwareMondrianCatalogService.class);
MondrianImportHandler handler = new MondrianImportHandler(mimeTypes, aclImporter);
handler.importFile(bundle);
ArgumentCaptor<RepositoryFileAcl> captor = ArgumentCaptor.forClass(RepositoryFileAcl.class);
verify(aclImporter).addCatalog(any(InputStream.class), any(MondrianCatalog.class), anyBoolean(), captor.capture(), any(IPentahoSession.class));
assertEquals(acl, captor.getValue());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method addCatalog_WithAcl.
@Test
public void addCatalog_WithAcl() throws Exception {
initMondrianCatalogsCache();
MondrianCatalogHelper helperSpy = spy(helper);
IPentahoSession session = mock(IPentahoSession.class);
doNothing().when(helperSpy).init(session);
doReturn(Collections.<MondrianCatalog>emptyList()).when(helperSpy).getCatalogs(session);
doReturn(null).when(helperSpy).makeSchema(anyString());
MondrianCatalog cat = createTestCatalog();
RepositoryFileAcl acl = mock(RepositoryFileAcl.class);
IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), eq(acl));
doReturn(aclHelper).when(helperSpy).getAclHelper();
doReturn(null).when(helperSpy).makeSchema(CATALOG_NAME);
doReturn(true).when(helperSpy).catalogExists(any(MondrianCatalog.class), eq(session));
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, acl, session);
verify(aclHelper, times(1)).setAclFor(any(RepositoryFile.class), eq(acl));
doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
verify(aclHelper, times(2)).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
}
Aggregations