use of alluxio.proto.shared.Acl in project alluxio by Alluxio.
the class ProtoUtils method fromProto.
/**
* @param acl the protobuf representation
* @return {@link AccessControlList}
*/
public static AccessControlList fromProto(Acl.AccessControlList acl) {
AccessControlList ret;
if (acl.hasIsDefault() && acl.getIsDefault()) {
ret = new DefaultAccessControlList();
} else {
ret = new AccessControlList();
}
ret.setOwningUser(acl.getOwningUser().intern());
ret.setOwningGroup(acl.getOwningGroup().intern());
if (acl.getIsEmpty()) {
return ret;
}
// true if there are any extended entries (named user or named group)
boolean hasExtended = false;
for (Acl.NamedAclActions namedActions : acl.getUserActionsList()) {
String name = namedActions.getName();
AclActions actions = fromProto(namedActions.getActions());
AclEntry entry;
if (name.equals(AccessControlList.OWNING_USER_KEY)) {
entry = new AclEntry.Builder().setType(AclEntryType.OWNING_USER).setSubject(acl.getOwningUser()).setActions(actions).build();
} else {
hasExtended = true;
entry = new AclEntry.Builder().setType(AclEntryType.NAMED_USER).setSubject(name).setActions(actions).build();
}
ret.setEntry(entry);
}
for (Acl.NamedAclActions namedActions : acl.getGroupActionsList()) {
String name = namedActions.getName();
AclActions actions = fromProto(namedActions.getActions());
AclEntry entry;
if (name.equals(AccessControlList.OWNING_GROUP_KEY)) {
entry = new AclEntry.Builder().setType(AclEntryType.OWNING_GROUP).setSubject(acl.getOwningGroup()).setActions(actions).build();
} else {
hasExtended = true;
entry = new AclEntry.Builder().setType(AclEntryType.NAMED_GROUP).setSubject(name).setActions(actions).build();
}
ret.setEntry(entry);
}
if (hasExtended) {
// Only set the mask if there are any extended acl entries.
AclActions actions = fromProto(acl.getMaskActions());
AclEntry entry = new AclEntry.Builder().setType(AclEntryType.MASK).setActions(actions).build();
ret.setEntry(entry);
}
AclActions actions = fromProto(acl.getOtherActions());
AclEntry entry = new AclEntry.Builder().setType(AclEntryType.OTHER).setActions(actions).build();
ret.setEntry(entry);
return ret;
}
Aggregations