Search in sources :

Example 61 with AclStatus

use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.

the class ViewFileSystemBaseTest method testInternalGetAclStatus.

@Test
public void testInternalGetAclStatus() throws IOException {
    final UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
    AclStatus aclStatus = fsView.getAclStatus(new Path("/internalDir"));
    assertEquals(aclStatus.getOwner(), currentUser.getUserName());
    assertEquals(aclStatus.getGroup(), currentUser.getGroupNames()[0]);
    assertEquals(aclStatus.getEntries(), AclUtil.getMinimalAcl(PERMISSION_555));
    assertFalse(aclStatus.isStickyBit());
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 62 with AclStatus

use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.

the class JsonUtilClient method toAclStatus.

/** Convert a Json map to a AclStatus object. */
static AclStatus toAclStatus(final Map<?, ?> json) {
    if (json == null) {
        return null;
    }
    final Map<?, ?> m = (Map<?, ?>) json.get(AclStatus.class.getSimpleName());
    AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
    aclStatusBuilder.owner((String) m.get("owner"));
    aclStatusBuilder.group((String) m.get("group"));
    aclStatusBuilder.stickyBit((Boolean) m.get("stickyBit"));
    String permString = (String) m.get("permission");
    if (permString != null) {
        final FsPermission permission = toFsPermission(permString, (Boolean) m.get("aclBit"), (Boolean) m.get("encBit"));
        aclStatusBuilder.setPermission(permission);
    }
    final List<?> entries = (List<?>) m.get("entries");
    List<AclEntry> aclEntryList = new ArrayList<>();
    for (Object entry : entries) {
        AclEntry aclEntry = AclEntry.parseAclEntry((String) entry, true);
        aclEntryList.add(aclEntry);
    }
    aclStatusBuilder.addEntries(aclEntryList);
    return aclStatusBuilder.build();
}
Also used : DatanodeInfoBuilder(org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder) Builder(org.apache.hadoop.fs.ContentSummary.Builder) ArrayList(java.util.ArrayList) AclEntry(org.apache.hadoop.fs.permission.AclEntry) AclStatus(org.apache.hadoop.fs.permission.AclStatus) ArrayList(java.util.ArrayList) List(java.util.List) FsPermission(org.apache.hadoop.fs.permission.FsPermission) Map(java.util.Map)

Example 63 with AclStatus

use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.

the class BaseTestHttpFSWith method testFileAcls.

/**
   * Simple ACL tests on a file:  Set an acl, add an acl, remove one acl,
   * and remove all acls.
   * @throws Exception
   */
private void testFileAcls() throws Exception {
    if (isLocalFS()) {
        return;
    }
    final String aclUser1 = "user:foo:rw-";
    final String rmAclUser1 = "user:foo:";
    final String aclUser2 = "user:bar:r--";
    final String aclGroup1 = "group::r--";
    final String aclSet = "user::rwx," + aclUser1 + "," + aclGroup1 + ",other::---";
    FileSystem proxyFs = FileSystem.get(getProxiedFSConf());
    FileSystem httpfs = getHttpFSFileSystem();
    Path path = new Path(getProxiedFSTestDir(), "testAclStatus.txt");
    OutputStream os = proxyFs.create(path);
    os.write(1);
    os.close();
    AclStatus proxyAclStat = proxyFs.getAclStatus(path);
    AclStatus httpfsAclStat = httpfs.getAclStatus(path);
    assertSameAcls(httpfsAclStat, proxyAclStat);
    assertSameAclBit(httpfs, proxyFs, path);
    httpfs.setAcl(path, AclEntry.parseAclSpec(aclSet, true));
    proxyAclStat = proxyFs.getAclStatus(path);
    httpfsAclStat = httpfs.getAclStatus(path);
    assertSameAcls(httpfsAclStat, proxyAclStat);
    assertSameAclBit(httpfs, proxyFs, path);
    httpfs.modifyAclEntries(path, AclEntry.parseAclSpec(aclUser2, true));
    proxyAclStat = proxyFs.getAclStatus(path);
    httpfsAclStat = httpfs.getAclStatus(path);
    assertSameAcls(httpfsAclStat, proxyAclStat);
    assertSameAclBit(httpfs, proxyFs, path);
    httpfs.removeAclEntries(path, AclEntry.parseAclSpec(rmAclUser1, false));
    proxyAclStat = proxyFs.getAclStatus(path);
    httpfsAclStat = httpfs.getAclStatus(path);
    assertSameAcls(httpfsAclStat, proxyAclStat);
    assertSameAclBit(httpfs, proxyFs, path);
    httpfs.removeAcl(path);
    proxyAclStat = proxyFs.getAclStatus(path);
    httpfsAclStat = httpfs.getAclStatus(path);
    assertSameAcls(httpfsAclStat, proxyAclStat);
    assertSameAclBit(httpfs, proxyFs, path);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream)

Example 64 with AclStatus

use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.

the class ViewFsBaseTest method testInternalGetAclStatus.

@Test
public void testInternalGetAclStatus() throws IOException {
    final UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
    AclStatus aclStatus = fcView.getAclStatus(new Path("/internalDir"));
    assertEquals(aclStatus.getOwner(), currentUser.getUserName());
    assertEquals(aclStatus.getGroup(), currentUser.getGroupNames()[0]);
    assertEquals(aclStatus.getEntries(), AclUtil.getMinimalAcl(PERMISSION_555));
    assertFalse(aclStatus.isStickyBit());
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 65 with AclStatus

use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.

the class HttpFSFileSystem method createAclStatus.

/**
   * Convert the given JSON object into an AclStatus
   * @param json Input JSON representing the ACLs
   * @return Resulting AclStatus
   */
private AclStatus createAclStatus(JSONObject json) {
    AclStatus.Builder aclStatusBuilder = new AclStatus.Builder().owner((String) json.get(OWNER_JSON)).group((String) json.get(GROUP_JSON)).stickyBit((Boolean) json.get(ACL_STICKY_BIT_JSON));
    JSONArray entries = (JSONArray) json.get(ACL_ENTRIES_JSON);
    for (Object e : entries) {
        aclStatusBuilder.addEntry(AclEntry.parseAclEntry(e.toString(), true));
    }
    return aclStatusBuilder.build();
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Aggregations

AclStatus (org.apache.hadoop.fs.permission.AclStatus)96 AclEntry (org.apache.hadoop.fs.permission.AclEntry)84 Test (org.junit.Test)76 Path (org.apache.hadoop.fs.Path)42 FsPermission (org.apache.hadoop.fs.permission.FsPermission)14 FSAclBaseTest (org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest)10 FileSystem (org.apache.hadoop.fs.FileSystem)8 Configuration (org.apache.hadoop.conf.Configuration)5 FileStatus (org.apache.hadoop.fs.FileStatus)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)3 DatanodeInfoBuilder (org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder)3 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)3 Builder (org.apache.hadoop.fs.ContentSummary.Builder)2 FsShell (org.apache.hadoop.fs.FsShell)2 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 Pair (alluxio.collections.Pair)1