use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class JcrRepositoryFileAclDao method internalUpdateAcl.
protected RepositoryFileAcl internalUpdateAcl(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final RepositoryFileAcl acl) throws RepositoryException {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
DefaultPermissionConversionHelper permissionConversionHelper = new DefaultPermissionConversionHelper(session);
Node node = session.getNodeByIdentifier(fileId.toString());
if (node == null) {
throw new RepositoryException(Messages.getInstance().getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", // $NON-NLS-1$
fileId.toString()));
}
String absPath = node.getPath();
AccessControlManager acMgr = session.getAccessControlManager();
AccessControlList acList = getAccessControlList(acMgr, absPath);
// clear all entries
AccessControlEntry[] acEntries = acList.getAccessControlEntries();
for (int i = 0; i < acEntries.length; i++) {
acList.removeAccessControlEntry(acEntries[i]);
}
JcrRepositoryFileAclUtils.setAclMetadata(session, absPath, acList, new AclMetadata(acl.getOwner().getName(), acl.isEntriesInheriting()));
// add entries to now empty list but only if not inheriting; force user to start with clean slate
boolean adminPrincipalExist = false;
ITenant principalTenant = null;
if (!acl.isEntriesInheriting()) {
for (RepositoryFileAce ace : acl.getAces()) {
Principal principal = null;
if (RepositoryFileSid.Type.ROLE == ace.getSid().getType()) {
String principalName = JcrTenantUtils.getRoleNameUtils().getPrincipleName(ace.getSid().getName());
if (tenantAdminAuthorityName.equals(principalName)) {
adminPrincipalExist = true;
}
principal = new SpringSecurityRolePrincipal(JcrTenantUtils.getTenantedRole(ace.getSid().getName()));
} else {
principal = new SpringSecurityUserPrincipal(JcrTenantUtils.getTenantedUser(ace.getSid().getName()));
}
acList.addAccessControlEntry(principal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, ace.getPermissions()));
}
if (!adminPrincipalExist) {
if (acl.getAces() != null && acl.getAces().size() > 0) {
principalTenant = JcrTenantUtils.getRoleNameUtils().getTenant(acl.getAces().get(0).getSid().getName());
}
if (principalTenant == null || principalTenant.getId() == null) {
principalTenant = JcrTenantUtils.getTenant();
}
List<RepositoryFilePermission> permissionList = new ArrayList<RepositoryFilePermission>();
permissionList.add(RepositoryFilePermission.ALL);
Principal adminPrincipal = new SpringSecurityRolePrincipal(JcrTenantUtils.getRoleNameUtils().getPrincipleId(principalTenant, tenantAdminAuthorityName));
acList.addAccessControlEntry(adminPrincipal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, EnumSet.copyOf(permissionList)));
}
}
acMgr.setPolicy(absPath, acList);
session.save();
return getAcl(fileId);
}
use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class DefaultDeleteHelper method permanentlyDeleteFile.
/**
* {@inheritDoc}
*/
public void permanentlyDeleteFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
Assert.notNull(fileId);
Node fileNode = session.getNodeByIdentifier(fileId.toString());
// guard against using a file retrieved from a more lenient session inside a more strict session
Assert.notNull(fileNode);
// see if anything is referencing this node; if yes, then we cannot delete it as a
// ReferentialIntegrityException
// will result
Set<RepositoryFile> referrers = new HashSet<RepositoryFile>();
PropertyIterator refIter = fileNode.getReferences();
if (refIter.hasNext()) {
while (refIter.hasNext()) {
// for each referrer property, march up the tree until we find the file node to which the property belongs
RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty());
if (referrer != null) {
referrers.add(referrer);
}
}
if (!referrers.isEmpty()) {
RepositoryFile referee = JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode);
throw new RepositoryFileDaoReferentialIntegrityException(referee, referrers);
}
}
// it first
if (fileNode.isLocked()) {
Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath());
// don't need lock token anymore
lockHelper.removeLockToken(session, pentahoJcrConstants, lock);
}
// if this file was non-permanently deleted, delete its containing folder too
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
String trashFolder = ServerRepositoryPaths.getUserHomeFolderPath(new Tenant(tenantId, true), PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + FOLDER_NAME_TRASH;
Node parent = fileNode.getParent();
purgeHistory(fileNode, session, pentahoJcrConstants);
if (fileNode.getPath().startsWith(trashFolder)) {
// Remove the file and then the wrapper foler
fileNode.remove();
parent.remove();
} else {
fileNode.remove();
}
}
use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class DefaultDeleteHelper method undeleteFile.
/**
* {@inheritDoc}
*/
public void undeleteFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
Node fileToUndeleteNode = session.getNodeByIdentifier(fileId.toString());
String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath();
String origParentFolderPath = getOriginalParentFolderPath(session, pentahoJcrConstants, fileToUndeleteNode, false);
String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName();
if (session.itemExists(absDestPath)) {
RepositoryFile file = JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem(absDestPath));
throw new RepositoryFileDaoFileExistsException(file);
}
session.move(fileToUndeleteNode.getPath(), absDestPath);
session.getItem(trashFileIdNodePath).remove();
}
use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class AbstractRepositoryTenantManager method getChildTenants.
public List<ITenant> getChildTenants(Session session, final ITenant parentTenant, final boolean includeDisabledTenants) throws RepositoryException {
List<ITenant> children = new ArrayList<ITenant>();
List<RepositoryFile> allChildren = JcrRepositoryFileUtils.getChildren(session, new PentahoJcrConstants(session), pathConversionHelper, null, getTenantRootFolder(session, parentTenant).getId(), null);
for (RepositoryFile repoFile : allChildren) {
Map<String, Serializable> metadata = JcrRepositoryFileUtils.getFileMetadata(session, repoFile.getId());
if (metadata.containsKey(ITenantManager.TENANT_ROOT) && (Boolean) metadata.get(ITenantManager.TENANT_ROOT)) {
Tenant tenant = new Tenant(repoFile.getPath(), isTenantEnabled(session, repoFile.getId()));
if (includeDisabledTenants || tenant.isEnabled()) {
children.add(new Tenant(pathConversionHelper.relToAbs(repoFile.getPath()), isTenantEnabled(session, repoFile.getId())));
}
}
}
return children;
}
use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class RepositoryTenantManager method createTenantFolder.
private RepositoryFile createTenantFolder(final ITenant parentTenant, final String tenantName, final String tenantCreatorId) {
return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException {
Tenant tenant = null;
RepositoryFile parentFolder = null;
if (parentTenant == null) {
tenant = new Tenant("/" + tenantName, true);
} else {
tenant = new Tenant(parentTenant.getRootFolderAbsolutePath() + "/" + tenantName, true);
String folderPath = parentTenant.getRootFolderAbsolutePath();
parentFolder = repositoryFileDao.getFileByAbsolutePath(folderPath);
}
RepositoryFileAcl acl = new RepositoryFileAcl.Builder(tenantCreatorId).entriesInheriting(false).build();
RepositoryFile systemTenantFolder = repositoryFileDao.createFolder(parentFolder != null ? parentFolder.getId() : null, new RepositoryFile.Builder(tenant.getName()).folder(true).build(), acl, "");
repositoryFileDao.getFileByAbsolutePath(tenant.getId());
Map<String, Serializable> fileMeta = repositoryFileDao.getFileMetadata(systemTenantFolder.getId());
fileMeta.put(ITenantManager.TENANT_ROOT, true);
fileMeta.put(ITenantManager.TENANT_ENABLED, true);
JcrRepositoryFileUtils.setFileMetadata(session, systemTenantFolder.getId(), fileMeta);
createRuntimeRolesFolderNode(session, new PentahoJcrConstants(session), tenant);
return systemTenantFolder;
}
});
}
Aggregations