Search in sources :

Example 11 with AccessControlList

use of alluxio.security.authorization.AccessControlList in project alluxio by Alluxio.

the class FingerprintTest method createACLFingeprint.

@Test
public void createACLFingeprint() {
    UfsStatus status = new UfsFileStatus(CommonUtils.randomAlphaNumString(10), CommonUtils.randomAlphaNumString(10), mRandom.nextLong(), mRandom.nextLong(), CommonUtils.randomAlphaNumString(10), CommonUtils.randomAlphaNumString(10), (short) mRandom.nextInt(), mRandom.nextLong());
    AccessControlList acl = AccessControlList.fromStringEntries(CommonUtils.randomAlphaNumString(10), CommonUtils.randomAlphaNumString(10), Arrays.asList("user::rw-", "group::r--", "other::rwx"));
    Fingerprint fp = Fingerprint.create(CommonUtils.randomAlphaNumString(10), status, acl);
    String expected = fp.serialize();
    assertNotNull(expected);
    assertEquals("user::rw-,group::r--,other::rwx", Fingerprint.parse(expected).getTag(Fingerprint.Tag.ACL));
    assertEquals(expected, Fingerprint.parse(expected).serialize());
}
Also used : AccessControlList(alluxio.security.authorization.AccessControlList) Test(org.junit.Test)

Example 12 with AccessControlList

use of alluxio.security.authorization.AccessControlList in project alluxio by Alluxio.

the class GrpcUtils method fromProto.

/**
 * @param pAcl the proto representation
 * @return the {@link AccessControlList} instance created from the proto representation
 */
public static AccessControlList fromProto(PAcl pAcl) {
    AccessControlList acl;
    if (pAcl.getIsDefault()) {
        acl = new DefaultAccessControlList();
        ((DefaultAccessControlList) acl).setEmpty(pAcl.getIsDefaultEmpty());
    } else {
        acl = new AccessControlList();
    }
    acl.setOwningUser(pAcl.getOwner().intern());
    acl.setOwningGroup(pAcl.getOwningGroup().intern());
    acl.setMode((short) pAcl.getMode());
    if (pAcl.getEntriesCount() > 0) {
        for (PAclEntry tEntry : pAcl.getEntriesList()) {
            acl.setEntry(fromProto(tEntry));
        }
    }
    return acl;
}
Also used : DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) AccessControlList(alluxio.security.authorization.AccessControlList) DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList)

Example 13 with AccessControlList

use of alluxio.security.authorization.AccessControlList in project alluxio by Alluxio.

the class MutableInodeFile method fromJournalEntry.

/**
 * Converts the entry to an {@link MutableInodeFile}.
 *
 * @param entry the entry to convert
 * @return the {@link MutableInodeFile} representation
 */
public static MutableInodeFile fromJournalEntry(InodeFileEntry entry) {
    // If journal entry has no mode set, set default mode for backwards-compatibility.
    MutableInodeFile ret = new MutableInodeFile(BlockId.getContainerId(entry.getId())).setName(entry.getName()).setBlockIds(entry.getBlocksList()).setBlockSizeBytes(entry.getBlockSizeBytes()).setCacheable(entry.getCacheable()).setCompleted(entry.getCompleted()).setCreationTimeMs(entry.getCreationTimeMs()).setLastModificationTimeMs(entry.getLastModificationTimeMs(), true).setLastAccessTimeMs(entry.hasLastAccessTimeMs() ? entry.getLastAccessTimeMs() : entry.getLastModificationTimeMs(), true).setLength(entry.getLength()).setParentId(entry.getParentId()).setPersistenceState(PersistenceState.valueOf(entry.getPersistenceState())).setPinned(entry.getPinned()).setPersistJobId(entry.getPersistJobId()).setShouldPersistTime(entry.getShouldPersistTime()).setReplicationDurable(entry.getReplicationDurable()).setReplicationMax(entry.getReplicationMax()).setReplicationMin(entry.getReplicationMin()).setTempUfsPath(entry.getTempUfsPath()).setTtl(entry.getTtl()).setTtlAction((ProtobufUtils.fromProtobuf(entry.getTtlAction()))).setUfsFingerprint(entry.hasUfsFingerprint() ? entry.getUfsFingerprint() : Constants.INVALID_UFS_FINGERPRINT);
    if (entry.hasAcl()) {
        ret.mAcl = ProtoUtils.fromProto(entry.getAcl());
    } else {
        // Backward compatibility.
        AccessControlList acl = new AccessControlList();
        acl.setOwningUser(entry.getOwner().intern());
        acl.setOwningGroup(entry.getGroup().intern());
        short mode = entry.hasMode() ? (short) entry.getMode() : Constants.DEFAULT_FILE_SYSTEM_MODE;
        acl.setMode(mode);
        ret.mAcl = acl;
    }
    if (entry.getXAttrCount() > 0) {
        ret.setXAttr(CommonUtils.convertFromByteString(entry.getXAttrMap()));
    }
    ret.setMediumTypes(new HashSet<>(entry.getMediumTypeList()));
    return ret;
}
Also used : DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) AccessControlList(alluxio.security.authorization.AccessControlList)

Aggregations

AccessControlList (alluxio.security.authorization.AccessControlList)13 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)12 AlluxioURI (alluxio.AlluxioURI)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 Mode (alluxio.security.authorization.Mode)3 UnderFileSystem (alluxio.underfs.UnderFileSystem)3 Pair (alluxio.collections.Pair)2 CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)2 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)2 LockedInodePath (alluxio.master.file.meta.LockedInodePath)2 MountTable (alluxio.master.file.meta.MountTable)2 AclEntry (alluxio.security.authorization.AclEntry)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BlockInfoException (alluxio.exception.BlockInfoException)1 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)1 CompleteFileContext (alluxio.master.file.contexts.CompleteFileContext)1