- 步骤:
授予新权限的步骤: * 1) 调用FileSystem.getUserPrincipalLookupService()方法查看 * 2) 获得 ACL 视图 * 3) 使用 AclEntry.Builder 对象创建一个新的实体 * 4) 读取 ACL * 5) 插入新的实体 * 6) 使用 setAcl() 或 setAttribute() 重写 ACL
- 代码
Path path = Paths.get("E:/hsm.sql"); try { //1 lookup for the principal UserPrincipal user = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("icer"); //2 get the ACL view AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class); //3 create a new entry AclEntry entry = AclEntry.newBuilder().setType(AclEntryType.ALLOW) .setPrincipal(user).setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.APPEND_DATA).build(); //4 read acl List<AclEntry> acl = view.getAcl(); //5 Insert the new entry acl.add(0, entry); //6.1 rewrite acl // view.setAcl(acl); //6.2rewrite acl Files.setAttribute(path, "acl:acl", acl, LinkOption.NOFOLLOW_LINKS); } catch (Exception e) { e.printStackTrace(); }
授予文件新的权限---ACL
最新推荐文章于 2024-06-23 09:43:55 发布