use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method deleteFile.
/**
* {@inheritDoc}
*/
@Override
public void deleteFile(final Serializable fileId, final String versionMessage) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
RepositoryFile fileToBeDeleted = getFileById(fileId);
// Get repository file info and acl info of parent
if (fileToBeDeleted != null) {
RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl(fileToBeDeleted.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
List<RepositoryFilePermission> perms = new ArrayList<RepositoryFilePermission>();
perms.add(RepositoryFilePermission.DELETE);
if (!aclDao.hasAccess(fileToBeDeleted.getPath(), EnumSet.copyOf(perms))) {
throw new AccessDeniedException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_DELETE", fileId));
}
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Serializable parentFolderId = JcrRepositoryFileUtils.getParentId(session, fileId);
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);
deleteHelper.deleteFile(session, pentahoJcrConstants, fileId);
session.save();
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, versionMessage);
return null;
}
});
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class DefaultPermissionConversionHelper method pentahoPermissionsToPrivileges.
// ~ Methods
// =========================================================================================================
public Privilege[] pentahoPermissionsToPrivileges(final Session session, final EnumSet<RepositoryFilePermission> permissions) throws RepositoryException {
Assert.notNull(session);
Assert.notNull(permissions);
Assert.notEmpty(permissions);
Set<Privilege> privileges = new HashSet<Privilege>();
for (RepositoryFilePermission currentPermission : permissions) {
if (permissionEnumToPrivilegeNamesMap.containsKey(currentPermission)) {
Collection<String> privNames = permissionEnumToPrivilegeNamesMap.get(currentPermission);
for (String privName : privNames) {
privileges.add(session.getAccessControlManager().privilegeFromName(privName));
}
} else {
// $NON-NLS-1$//$NON-NLS-2$
logger.debug("skipping permission=" + currentPermission + " as it doesn't have any corresponding privileges");
}
}
Assert.isTrue(!privileges.isEmpty(), "no privileges; see previous 'skipping permission' messages");
return privileges.toArray(new Privilege[0]);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission 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.RepositoryFilePermission in project pentaho-platform by pentaho.
the class FileService method doGetCanAccessList.
public List<Setting> doGetCanAccessList(String pathId, String permissions) {
StringTokenizer tokenizer = new StringTokenizer(permissions, "|");
ArrayList<Setting> permMap = new ArrayList<Setting>();
while (tokenizer.hasMoreTokens()) {
Integer perm = Integer.valueOf(tokenizer.nextToken());
EnumSet<RepositoryFilePermission> permission = EnumSet.of(RepositoryFilePermission.values()[perm]);
permMap.add(new Setting(perm.toString(), new Boolean(getRepository().hasAccess(idToPath(pathId), permission)).toString()));
}
return permMap;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class AccessVoterToLegacyAcl method convert.
private LegacyRepositoryFile convert(RepositoryFile file, RepositoryFileAcl acl) {
LegacyRepositoryFile legacy = new LegacyRepositoryFile(file.getName(), file.getPath(), file.isFolder());
legacy.setId(file.getId());
if (file.getLastModifiedDate() != null) {
legacy.setLastModified(file.getLastModifiedDate().getTime());
}
List<IPentahoAclEntry> legacyAcls = new ArrayList<IPentahoAclEntry>();
for (RepositoryFileAce fileAce : acl.getAces()) {
if (fileAce != null && fileAce.getSid() != null && fileAce.getPermissions() != null) {
for (RepositoryFilePermission filePermission : fileAce.getPermissions()) {
PentahoAclEntry fileAcl = new PentahoAclEntry();
if (RepositoryFileSid.Type.USER == fileAce.getSid().getType()) {
// user
fileAcl.setRecipient(fileAce.getSid().getName());
} else {
// role
fileAcl.setRecipient(new SimpleGrantedAuthority(fileAce.getSid().getName()));
}
fileAcl.setMask(mask(filePermission));
legacyAcls.add(fileAcl);
}
}
}
legacy.setAccessControls(legacyAcls);
return legacy;
}
Aggregations