Here are the examples of the java api class java.nio.file.attribute.AclEntryType taken from open source projects.
1. SftpHelper#writeAclEntry()
Project: mina-sshd
File: SftpHelper.java
File: SftpHelper.java
public static void writeAclEntry(Buffer buffer, AclEntry acl) { ValidateUtils.checkNotNull(acl, "No ACL"); AclEntryType type = acl.type(); int aclType = encodeAclEntryType(type); ValidateUtils.checkTrue(aclType >= 0, "Unknown ACL type: %s", type); buffer.putInt(aclType); buffer.putInt(encodeAclFlags(acl.flags())); buffer.putInt(encodeAclMask(acl.permissions())); Principal user = acl.principal(); buffer.putString(user.getName()); }
2. SftpVersionsTest#testSftpACLEncodeDecode()
Project: mina-sshd
File: SftpVersionsTest.java
File: SftpVersionsTest.java
// see SSHD-574 @Test public void testSftpACLEncodeDecode() throws Exception { AclEntryType[] types = AclEntryType.values(); final List<AclEntry> aclExpected = new ArrayList<>(types.length); for (AclEntryType t : types) { aclExpected.add(AclEntry.newBuilder().setType(t).setFlags(EnumSet.allOf(AclEntryFlag.class)).setPermissions(EnumSet.allOf(AclEntryPermission.class)).setPrincipal(new DefaultGroupPrincipal(getCurrentTestName() + "@" + getClass().getPackage().getName())).build()); } final AtomicInteger numInvocations = new AtomicInteger(0); SftpSubsystemFactory factory = new SftpSubsystemFactory() { @Override public Command create() { SftpSubsystem subsystem = new SftpSubsystem(getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()) { @Override protected Map<String, Object> resolveFileAttributes(Path file, int flags, LinkOption... options) throws IOException { Map<String, Object> attrs = super.resolveFileAttributes(file, flags, options); if (GenericUtils.isEmpty(attrs)) { attrs = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); } @SuppressWarnings("unchecked") List<AclEntry> aclActual = (List<AclEntry>) attrs.put("acl", aclExpected); if (aclActual != null) { log.info("resolveFileAttributes(" + file + ") replaced ACL: " + aclActual); } return attrs; } @Override protected void setFileAccessControl(Path file, List<AclEntry> aclActual, LinkOption... options) throws IOException { if (aclActual != null) { assertListEquals("Mismatched ACL set for file=" + file, aclExpected, aclActual); numInvocations.incrementAndGet(); } } }; Collection<? extends SftpEventListener> listeners = getRegisteredListeners(); if (GenericUtils.size(listeners) > 0) { for (SftpEventListener l : listeners) { subsystem.addSftpEventListener(l); } } return subsystem; } }; factory.addSftpEventListener(new AbstractSftpEventListenerAdapter() { @Override public void modifyingAttributes(ServerSession session, Path path, Map<String, ?> attrs) { @SuppressWarnings("unchecked") List<AclEntry> aclActual = GenericUtils.isEmpty(attrs) ? null : (List<AclEntry>) attrs.get("acl"); if (getTestedVersion() > SftpConstants.SFTP_V3) { assertListEquals("Mismatched modifying ACL for file=" + path, aclExpected, aclActual); } else { assertNull("Unexpected modifying ACL for file=" + path, aclActual); } } @Override public void modifiedAttributes(ServerSession session, Path path, Map<String, ?> attrs, Throwable thrown) { @SuppressWarnings("unchecked") List<AclEntry> aclActual = GenericUtils.isEmpty(attrs) ? null : (List<AclEntry>) attrs.get("acl"); if (getTestedVersion() > SftpConstants.SFTP_V3) { assertListEquals("Mismatched modified ACL for file=" + path, aclExpected, aclActual); } else { assertNull("Unexpected modified ACL for file=" + path, aclActual); } } }); sshd.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(factory)); Path targetPath = detectTargetFolder(); Path lclSftp = Utils.resolve(targetPath, SftpConstants.SFTP_SUBSYSTEM_NAME, getClass().getSimpleName()); Files.createDirectories(lclSftp.resolve("sub-folder")); Path lclFile = assertHierarchyTargetFolderExists(lclSftp).resolve(getCurrentTestName() + "-" + getTestedVersion() + ".txt"); Files.write(lclFile, getClass().getName().getBytes(StandardCharsets.UTF_8)); Path parentPath = targetPath.getParent(); String remotePath = Utils.resolveRelativeRemotePath(parentPath, lclSftp); int numInvoked = 0; try (SshClient client = setupTestClient()) { client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (SftpClient sftp = session.createSftpClient(getTestedVersion())) { for (DirEntry entry : sftp.readDir(remotePath)) { String fileName = entry.getFilename(); if (".".equals(fileName) || "..".equals(fileName)) { continue; } Attributes attrs = validateSftpFileTypeAndPermissions(fileName, getTestedVersion(), entry.getAttributes()); List<AclEntry> aclActual = attrs.getAcl(); if (getTestedVersion() == SftpConstants.SFTP_V3) { assertNull("Unexpected ACL for entry=" + fileName, aclActual); } else { assertListEquals("Mismatched ACL for entry=" + fileName, aclExpected, aclActual); } attrs.getFlags().clear(); attrs.setAcl(aclExpected); sftp.setStat(remotePath + "/" + fileName, attrs); if (getTestedVersion() > SftpConstants.SFTP_V3) { numInvoked++; } } } } finally { client.stop(); } } assertEquals("Mismatched invocations count", numInvoked, numInvocations.get()); }