use of org.pentaho.platform.api.repository2.unified.RepositoryFileAce 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.RepositoryFileAce 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.RepositoryFileAce 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);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAce in project pentaho-platform by pentaho.
the class MockUnifiedRepository method hasAccess.
private boolean hasAccess(final Serializable fileId, final EnumSet<RepositoryFilePermission> permissions) {
String username = currentUserProvider.getUser();
List<String> roles = currentUserProvider.getRoles();
RepositoryFileAcl acl = idManager.getFileById(fileId).getAcl();
if (acl.getOwner().getType() == USER && acl.getOwner().getName().equals(username)) {
// owner can do anything
return true;
}
List<RepositoryFileAce> aces = internalGetEffectiveAces(fileId);
for (RepositoryFileAce ace : aces) {
if (ace.getSid().equals(everyone()) && ace.getPermissions().containsAll(permissions)) {
// match special everyone role
return true;
} else if (ace.getSid().getType() == USER && ace.getSid().getName().equals(username) && ace.getPermissions().containsAll(permissions)) {
// match on user
return true;
}
for (String role : roles) {
if (ace.getSid().getType() == ROLE && ace.getSid().getName().equals(role) && ace.getPermissions().containsAll(permissions)) {
// match on role
return true;
}
}
}
return false;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAce in project pentaho-platform by pentaho.
the class ExportManifestTest method createMockAce.
private RepositoryFileAce createMockAce(String recipientName, String recipientType, RepositoryFilePermission first, RepositoryFilePermission... rest) {
RepositoryFileSid.Type type = RepositoryFileSid.Type.valueOf(recipientType);
RepositoryFileSid recipient = new RepositoryFileSid(recipientName, type);
return new RepositoryFileAce(recipient, EnumSet.of(first, rest));
}
Aggregations