Java Code Examples for org.apache.hadoop.fs.permission.AclStatus#Builder

The following examples show how to use org.apache.hadoop.fs.permission.AclStatus#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJsonUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testToAclStatus() throws IOException {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user::rwx\",\"user:user1:rw-\",\"group::rw-\",\"other::r-x\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  ObjectReader reader = new ObjectMapper().reader(Map.class);
  Map<?, ?> json = reader.readValue(jsonString);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER, ALL),
          aclEntry(ACCESS, USER, "user1", READ_WRITE),
          aclEntry(ACCESS, GROUP, READ_WRITE),
          aclEntry(ACCESS, OTHER, READ_EXECUTE));

  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.addEntries(aclSpec);
  aclStatusBuilder.stickyBit(false);

  Assert.assertEquals("Should be equal", aclStatusBuilder.build(),
      JsonUtil.toAclStatus(json));
}
 
Example 2
Source File: TestJsonUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testToJsonFromAclStatus() {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user:user1:rwx\",\"group::rw-\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.stickyBit(false);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER,"user1", ALL),
          aclEntry(ACCESS, GROUP, READ_WRITE));

  aclStatusBuilder.addEntries(aclSpec);
  Assert.assertEquals(jsonString,
      JsonUtil.toJsonString(aclStatusBuilder.build()));

}
 
Example 3
Source File: TestJsonUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testToAclStatus() throws IOException {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user::rwx\",\"user:user1:rw-\",\"group::rw-\",\"other::r-x\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  ObjectReader reader = new ObjectMapper().reader(Map.class);
  Map<?, ?> json = reader.readValue(jsonString);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER, ALL),
          aclEntry(ACCESS, USER, "user1", READ_WRITE),
          aclEntry(ACCESS, GROUP, READ_WRITE),
          aclEntry(ACCESS, OTHER, READ_EXECUTE));

  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.addEntries(aclSpec);
  aclStatusBuilder.stickyBit(false);

  Assert.assertEquals("Should be equal", aclStatusBuilder.build(),
      JsonUtil.toAclStatus(json));
}
 
Example 4
Source File: TestJsonUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testToJsonFromAclStatus() {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user:user1:rwx\",\"group::rw-\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.stickyBit(false);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER,"user1", ALL),
          aclEntry(ACCESS, GROUP, READ_WRITE));

  aclStatusBuilder.addEntries(aclSpec);
  Assert.assertEquals(jsonString,
      JsonUtil.toJsonString(aclStatusBuilder.build()));

}
 
Example 5
Source File: HttpFSFileSystem.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 6
Source File: JsonUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Convert a Json map to a AclStatus object. */
public 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<AclEntry>();
  for (Object entry : entries) {
    AclEntry aclEntry = AclEntry.parseAclEntry((String) entry, true);
    aclEntryList.add(aclEntry);
  }
  aclStatusBuilder.addEntries(aclEntryList);
  return aclStatusBuilder.build();
}
 
Example 7
Source File: PBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static AclStatus convert(GetAclStatusResponseProto e) {
  AclStatusProto r = e.getResult();
  AclStatus.Builder builder = new AclStatus.Builder();
  builder.owner(r.getOwner()).group(r.getGroup()).stickyBit(r.getSticky())
      .addEntries(convertAclEntry(r.getEntriesList()));
  if (r.hasPermission()) {
    builder.setPermission(convert(r.getPermission()));
  }
  return builder.build();
}
 
Example 8
Source File: FSImageLoader.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Return the JSON formatted ACL status of the specified file.
 * @param path a path specifies a file
 * @return JSON formatted AclStatus
 * @throws IOException if failed to serialize fileStatus to JSON.
 */
String getAclStatus(String path) throws IOException {
  PermissionStatus p = getPermissionStatus(path);
  List<AclEntry> aclEntryList = getAclEntryList(path);
  FsPermission permission = p.getPermission();
  AclStatus.Builder builder = new AclStatus.Builder();
  builder.owner(p.getUserName()).group(p.getGroupName())
      .addEntries(aclEntryList).setPermission(permission)
      .stickyBit(permission.getStickyBit());
  AclStatus aclStatus = builder.build();
  return JsonUtil.toJsonString(aclStatus);
}
 
Example 9
Source File: HttpFSFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
Source File: JsonUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Convert a Json map to a AclStatus object. */
public 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<AclEntry>();
  for (Object entry : entries) {
    AclEntry aclEntry = AclEntry.parseAclEntry((String) entry, true);
    aclEntryList.add(aclEntry);
  }
  aclStatusBuilder.addEntries(aclEntryList);
  return aclStatusBuilder.build();
}
 
Example 11
Source File: PBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static AclStatus convert(GetAclStatusResponseProto e) {
  AclStatusProto r = e.getResult();
  AclStatus.Builder builder = new AclStatus.Builder();
  builder.owner(r.getOwner()).group(r.getGroup()).stickyBit(r.getSticky())
      .addEntries(convertAclEntry(r.getEntriesList()));
  if (r.hasPermission()) {
    builder.setPermission(convert(r.getPermission()));
  }
  return builder.build();
}
 
Example 12
Source File: FSImageLoader.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Return the JSON formatted ACL status of the specified file.
 * @param path a path specifies a file
 * @return JSON formatted AclStatus
 * @throws IOException if failed to serialize fileStatus to JSON.
 */
String getAclStatus(String path) throws IOException {
  PermissionStatus p = getPermissionStatus(path);
  List<AclEntry> aclEntryList = getAclEntryList(path);
  FsPermission permission = p.getPermission();
  AclStatus.Builder builder = new AclStatus.Builder();
  builder.owner(p.getUserName()).group(p.getGroupName())
      .addEntries(aclEntryList).setPermission(permission)
      .stickyBit(permission.getStickyBit());
  AclStatus aclStatus = builder.build();
  return JsonUtil.toJsonString(aclStatus);
}