Search in sources :

Example 1 with Acl

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;
}
Also used : DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) AccessControlList(alluxio.security.authorization.AccessControlList) DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) AclActions(alluxio.security.authorization.AclActions) AclEntry(alluxio.security.authorization.AclEntry) Acl(alluxio.proto.shared.Acl)

Aggregations

Acl (alluxio.proto.shared.Acl)1 AccessControlList (alluxio.security.authorization.AccessControlList)1 AclActions (alluxio.security.authorization.AclActions)1 AclEntry (alluxio.security.authorization.AclEntry)1 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)1