use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-kettle by pentaho.
the class UnifiedRepositoryConnectionAclService method getAcl.
@Override
public ObjectAcl getAcl(ObjectId fileId, boolean forceParentInheriting) throws KettleException {
RepositoryFileAcl acl = null;
try {
acl = pur.getAcl(fileId.getId());
} catch (Exception drfe) {
// The user does not have rights to view the acl information.
throw new KettleException(drfe);
}
RepositoryFileSid sid = acl.getOwner();
ObjectRecipient owner = new RepositoryObjectRecipient(sid.getName());
if (sid.getType().equals(RepositoryFileSid.Type.USER)) {
owner.setType(Type.USER);
} else {
owner.setType(Type.ROLE);
}
ObjectAcl objectAcl = new RepositoryObjectAcl(owner);
List<RepositoryFileAce> aces;
if (forceParentInheriting) {
objectAcl.setEntriesInheriting(true);
aces = pur.getEffectiveAces(acl.getId(), true);
} else {
objectAcl.setEntriesInheriting(acl.isEntriesInheriting());
aces = (acl.isEntriesInheriting()) ? pur.getEffectiveAces(acl.getId()) : acl.getAces();
}
List<ObjectAce> objectAces = new ArrayList<ObjectAce>();
for (RepositoryFileAce ace : aces) {
EnumSet<RepositoryFilePermission> permissions = ace.getPermissions();
EnumSet<RepositoryFilePermission> permissionSet = EnumSet.noneOf(RepositoryFilePermission.class);
RepositoryFileSid aceSid = ace.getSid();
ObjectRecipient recipient = new RepositoryObjectRecipient(aceSid.getName());
if (aceSid.getType().equals(RepositoryFileSid.Type.USER)) {
recipient.setType(Type.USER);
} else {
recipient.setType(Type.ROLE);
}
permissionSet.addAll(permissions);
objectAces.add(new RepositoryObjectAce(recipient, permissionSet));
}
objectAcl.setAces(objectAces);
return objectAcl;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-kettle by pentaho.
the class UnifiedRepositoryConnectionAclService method setAcl.
@Override
public void setAcl(ObjectId fileId, ObjectAcl objectAcl) throws KettleException {
try {
RepositoryFileAcl acl = pur.getAcl(fileId.getId());
RepositoryFileAcl.Builder newAclBuilder = new RepositoryFileAcl.Builder(acl).entriesInheriting(objectAcl.isEntriesInheriting()).clearAces();
if (!objectAcl.isEntriesInheriting()) {
List<ObjectAce> aces = objectAcl.getAces();
for (ObjectAce objectAce : aces) {
EnumSet<RepositoryFilePermission> permissions = objectAce.getPermissions();
EnumSet<RepositoryFilePermission> permissionSet = EnumSet.noneOf(RepositoryFilePermission.class);
ObjectRecipient recipient = objectAce.getRecipient();
RepositoryFileSid sid;
if (recipient.getType().equals(Type.ROLE)) {
sid = new RepositoryFileSid(recipient.getName(), RepositoryFileSid.Type.ROLE);
} else {
sid = new RepositoryFileSid(recipient.getName());
}
if (permissions != null) {
permissionSet.addAll(permissions);
}
newAclBuilder.ace(sid, permissionSet);
}
}
pur.updateAcl(newAclBuilder.build());
} catch (Exception drfe) {
// The user does not have rights to view or set the acl information.
throw new KettleException(drfe);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-kettle by pentaho.
the class PurRepository method getObjectInformation.
@Override
public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType) throws KettleException {
try {
RepositoryFile repositoryFile;
try {
repositoryFile = pur.getFileById(objectId.getId());
} catch (Exception e) {
// javax.jcr.Session throws exception, if a node with specified ID does not exist
// see http://jira.pentaho.com/browse/BISERVER-12758
log.logError("Error when trying to obtain a file by id: " + objectId.getId(), e);
return null;
}
if (repositoryFile == null) {
return null;
}
RepositoryFileAcl repositoryFileAcl = pur.getAcl(repositoryFile.getId());
String parentPath = getParentPath(repositoryFile.getPath());
String name = repositoryFile.getTitle();
String description = repositoryFile.getDescription();
Date modifiedDate = repositoryFile.getLastModifiedDate();
// String creatorId = repositoryFile.getCreatorId();
String ownerName = repositoryFileAcl != null ? repositoryFileAcl.getOwner().getName() : "";
boolean deleted = isDeleted(repositoryFile);
RepositoryDirectoryInterface directory = findDirectory(parentPath);
return new RepositoryObject(objectId, name, directory, ownerName, modifiedDate, objectType, description, deleted);
} catch (Exception e) {
throw new KettleException("Unable to get object information for object with id=" + objectId, e);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class ExportManifestEntity method getRepositoryFileAcl.
/**
* Helper method for importing. Returns a FileRepositoryAcl object for the the ExportManifestEntity. Will return null
* if there is no EntityAcl present.
*
* @return RepositoryFile
*/
public RepositoryFileAcl getRepositoryFileAcl() throws ExportManifestFormatException {
RepositoryFileAcl repositoryFileAcl;
EntityAcl entityAcl = getEntityAcl();
if (entityAcl == null) {
return null;
}
ArrayList<RepositoryFileAce> repositoryFileAces = new ArrayList<RepositoryFileAce>();
RepositoryFileSid rfs;
for (EntityAcl.Aces ace : entityAcl.getAces()) {
rfs = getSid(ace.getRecipient(), ace.getRecipientType());
HashSet<RepositoryFilePermission> permissionSet = new HashSet<RepositoryFilePermission>();
for (String permission : ace.getPermissions()) {
permissionSet.add(getPermission(permission));
}
RepositoryFileAce repositoryFileAce = new RepositoryFileAce(rfs, EnumSet.copyOf(permissionSet));
repositoryFileAces.add(repositoryFileAce);
}
repositoryFileAcl = new RepositoryFileAcl("", getSid(entityAcl.getOwner(), entityAcl.getOwnerType()), entityAcl.isEntriesInheriting(), repositoryFileAces);
return repositoryFileAcl;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class ExportManifestEntity method createEntityAcl.
private void createEntityAcl(RepositoryFileAcl repositoryFileAcl) {
DefaultTenantedPrincipleNameResolver nameResolver = new DefaultTenantedPrincipleNameResolver();
if (repositoryFileAcl == null) {
return;
}
entityAcl = new EntityAcl();
entityAcl.setEntriesInheriting(repositoryFileAcl.isEntriesInheriting());
entityAcl.setOwner(nameResolver.getPrincipleName(repositoryFileAcl.getOwner().getName()));
entityAcl.setOwnerType(repositoryFileAcl.getOwner().getType().name());
List<EntityAcl.Aces> aces = entityAcl.getAces();
aces.clear();
for (RepositoryFileAce repositoryFileAce : repositoryFileAcl.getAces()) {
EntityAcl.Aces ace = new EntityAcl.Aces();
ace.setRecipient(nameResolver.getPrincipleName(repositoryFileAce.getSid().getName()));
ace.setRecipientType(repositoryFileAce.getSid().getType().name());
List<String> permissions = ace.getPermissions();
for (RepositoryFilePermission permission : repositoryFileAce.getPermissions()) {
permissions.add(permission.toString());
}
aces.add(ace);
}
}
Aggregations