alluxio.security.authorization.Mode.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中alluxio.security.authorization.Mode.<init>()方法的一些代码示例,展示了Mode.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mode.<init>()方法的具体详情如下:
包路径:alluxio.security.authorization.Mode
类名称:Mode
方法名:<init>

Mode.<init>介绍

[英]Default constructor for Mode. Default constructor is required for equality testing and JSON deserialization.
[中]模式的默认构造函数。平等性测试和JSON反序列化需要默认构造函数。

代码示例

代码示例来源:origin: Alluxio/alluxio

/**
 * Gets the default mode.
 *
 * @return the default {@link Mode}
 */
public static Mode defaults() {
 return new Mode(Constants.DEFAULT_FILE_SYSTEM_MODE);
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates the "full access" mode.
 *
 * @return the none {@link Mode}
 */
public static Mode createFullAccess() {
 return new Mode(Bits.ALL, Bits.ALL, Bits.ALL);
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates the "no access" mode.
 *
 * @return the none {@link Mode}
 */
public static Mode createNoAccess() {
 return new Mode();
}

代码示例来源:origin: Alluxio/alluxio

private static Mode parseNumeric(String value) {
 short s = Short.parseShort(value, 8);
 return new Mode(s);
}

代码示例来源:origin: Alluxio/alluxio

private static String toExceptionMessage(String user, Mode.Bits bits, String path,
   Inode inode) {
  StringBuilder sb =
    new StringBuilder().append("user=").append(user).append(", ").append("access=").append(bits)
      .append(", ").append("path=").append(path).append(": ").append("failed at ")
      .append(inode.getName().equals("") ? "/" : inode.getName()).append(", inode owner=")
      .append(inode.getOwner()).append(", inode group=").append(inode.getGroup())
      .append(", inode mode=").append(new Mode(inode.getMode()).toString());
  return sb.toString();
 }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * @param mode1 first mode of the and operation
 * @param mode2 second mode of the and operation
 * @return the AND result of the two Modes
 */
public static Mode and(Mode mode1, Mode mode2) {
 Bits u = mode1.mOwnerBits.and(mode2.mOwnerBits);
 Bits g = mode1.mGroupBits.and(mode2.mGroupBits);
 Bits o = mode1.mOtherBits.and(mode2.mOtherBits);
 return new Mode(u, g, o);
}

代码示例来源:origin: Alluxio/alluxio

@Override
public void setMode(String path, short mode) throws IOException {
 path = stripPath(path);
 String posixPerm = new Mode(mode).toString();
 FileUtils.changeLocalFilePermission(path, posixPerm);
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Tests the {@link Mode#toString()} method.
 */
@Test
public void toStringTest() {
 assertEquals("rwxrwxrwx", new Mode((short) 0777).toString());
 assertEquals("rw-r-----", new Mode((short) 0640).toString());
 assertEquals("rw-------", new Mode((short) 0600).toString());
 assertEquals("---------", new Mode((short) 0000).toString());
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Tests the {@link Mode#toShort()} method.
 */
@Test
public void toShort() {
 Mode mode = new Mode(Mode.Bits.ALL, Mode.Bits.READ_EXECUTE, Mode.Bits.READ_EXECUTE);
 assertEquals(0755, mode.toShort());
 mode = Mode.defaults();
 assertEquals(0777, mode.toShort());
 mode = new Mode(Mode.Bits.READ_WRITE, Mode.Bits.READ, Mode.Bits.READ);
 assertEquals(0644, mode.toShort());
}

代码示例来源:origin: Alluxio/alluxio

@Override
 public void check(FileSystem fs) throws Exception {
  for (AlluxioURI file : Arrays.asList(PATH, NESTED, THROUGH, TTL)) {
   assertTrue(fs.exists(file));
  }
  assertEquals(TEST_MODE, new Mode((short) fs.getStatus(MODE).getMode()));
  assertTrue(fs.getStatus(THROUGH).isPersisted());
  assertEquals(TEST_TTL, fs.getStatus(TTL).getTtl());
  assertEquals(TtlAction.FREE, fs.getStatus(TTL).getTtlAction());
 }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Tests the {@link Mode#equals(Object)} method.
 */
@Test
public void equals() {
 Mode allAccess = new Mode((short) 0777);
 assertTrue(allAccess.equals(Mode.defaults()));
 Mode noAccess = new Mode((short) 0000);
 assertTrue(noAccess.equals(Mode.createNoAccess()));
 assertFalse(allAccess.equals(noAccess));
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void setAclWithoutOwner() throws Exception {
 createFileWithSingleBlock(NESTED_FILE_URI);
 mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext
   .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
 Set<String> entries = Sets.newHashSet(mFileSystemMaster
   .getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).convertAclToStringEntries());
 assertEquals(3, entries.size());
 try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA",
   ServerConfiguration.global())) {
  Set<String> newEntries = Sets.newHashSet("user::rwx", "group::rwx", "other::rwx");
  mThrown.expect(AccessControlException.class);
  mFileSystemMaster.setAcl(NESTED_FILE_URI, SetAclAction.REPLACE,
    newEntries.stream().map(AclEntry::fromCliString).collect(Collectors.toList()),
    SetAclContext.defaults());
 }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates {@link Mode} from proto {@link PMode}.
 *
 * @param pMode proto mode
 * @return created mode
 */
public static Mode fromProto(PMode pMode) {
 Bits ownerBits = pMode.hasOwnerBits() ? Bits.valueOf(pMode.getOwnerBits().name()) : Bits.NONE;
 Bits groupBits = pMode.hasGroupBits() ? Bits.valueOf(pMode.getGroupBits().name()) : Bits.NONE;
 Bits otherBits = pMode.hasOtherBits() ? Bits.valueOf(pMode.getOtherBits().name()) : Bits.NONE;
 return new Mode(ownerBits, groupBits, otherBits);
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Tests {@link AccessControlList#setMode(short)}.
 */
@Test
public void setMode() {
 AccessControlList acl = new AccessControlList();
 short mode = new Mode(Mode.Bits.EXECUTE, Mode.Bits.WRITE, Mode.Bits.READ).toShort();
 acl.setMode(mode);
 Assert.assertEquals(mode, acl.getMode());
}

代码示例来源:origin: Alluxio/alluxio

@Test
 public void setOtherBits() {
  Mode mode = new Mode((short) 0000);
  mode.setOtherBits(Mode.Bits.READ_EXECUTE);
  assertEquals(Mode.Bits.READ_EXECUTE, mode.getOtherBits());
  mode.setOtherBits(Mode.Bits.WRITE);
  assertEquals(Mode.Bits.WRITE, mode.getOtherBits());
  mode.setOtherBits(Mode.Bits.ALL);
  assertEquals(Mode.Bits.ALL, mode.getOtherBits());
 }
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void setGroupBits() {
 Mode mode = new Mode((short) 0000);
 mode.setGroupBits(Mode.Bits.READ_EXECUTE);
 assertEquals(Mode.Bits.READ_EXECUTE, mode.getGroupBits());
 mode.setGroupBits(Mode.Bits.WRITE);
 assertEquals(Mode.Bits.WRITE, mode.getGroupBits());
 mode.setGroupBits(Mode.Bits.ALL);
 assertEquals(Mode.Bits.ALL, mode.getGroupBits());
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Tests the {@link Mode#Mode(Mode)} constructor.
 */
@Test
public void copyConstructor() {
 Mode mode = new Mode(Mode.defaults());
 assertEquals(Mode.Bits.ALL, mode.getOwnerBits());
 assertEquals(Mode.Bits.ALL, mode.getGroupBits());
 assertEquals(Mode.Bits.ALL, mode.getOtherBits());
 assertEquals(0777, mode.toShort());
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void setOwnerBits() {
 Mode mode = new Mode((short) 0000);
 mode.setOwnerBits(Mode.Bits.READ_EXECUTE);
 assertEquals(Mode.Bits.READ_EXECUTE, mode.getOwnerBits());
 mode.setOwnerBits(Mode.Bits.WRITE);
 assertEquals(Mode.Bits.WRITE, mode.getOwnerBits());
 mode.setOwnerBits(Mode.Bits.ALL);
 assertEquals(Mode.Bits.ALL, mode.getOwnerBits());
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void deleteDirRecursiveWithPermissions() throws Exception {
 // userA has permissions to delete directory and nested file
 createFileWithSingleBlock(NESTED_FILE_URI);
 mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext
   .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
 mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext
   .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
 try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA",
   ServerConfiguration.global())) {
  mFileSystemMaster.delete(NESTED_URI,
    DeleteContext.defaults(DeletePOptions.newBuilder().setRecursive(true)));
 }
 assertEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_URI));
 assertEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_FILE_URI));
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Tests {@link AccessControlList#getMode()}.
 */
@Test
public void getMode() {
 AccessControlList acl = new AccessControlList();
 Assert.assertEquals(0, acl.getMode());
 acl.setEntry(new AclEntry.Builder().setType(AclEntryType.OWNING_USER).setSubject(OWNING_USER)
   .addAction(AclAction.READ).build());
 acl.setEntry(new AclEntry.Builder().setType(AclEntryType.OWNING_GROUP).setSubject(OWNING_GROUP)
   .addAction(AclAction.WRITE).build());
 acl.setEntry(new AclEntry.Builder().setType(AclEntryType.OTHER)
   .addAction(AclAction.EXECUTE).build());
 Assert.assertEquals(new Mode(Mode.Bits.READ, Mode.Bits.WRITE, Mode.Bits.EXECUTE).toShort(),
   acl.getMode());
}

相关文章