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());
}
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;
}
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;
}
Aggregations