gpt4 book ai didi

java - 在 AEM 中以编程方式授予组权限?

转载 作者:行者123 更新时间:2023-12-01 09:42:33 24 4
gpt4 key购买 nike

我需要通过以编程方式使用而不是全部在 AEM 中授予组权限,我只需要授予权限[复制]、[编辑]和[创建]

我的代码在这里:-

 privileges = new Privilege[] {accCtrlMgr.privilegeFromName(Privilege.JCR_ALL)};

我只想要[复制]、[编辑]和[创建],而不是[ Privilege.JCR_ALL ]

最佳答案

我希望这段代码对您有所帮助。

public static void setCreateEditReplicateAcl(final String aGroupPrincipal, String aPath, final UserManagementService aUserManagementService, final Session aSession) {
try {
UserManager userManager = aUserManagementService.getUserManager(aSession);
AccessControlManager accessControlManager = aSession.getAccessControlManager();
Authorizable group = userManager.getAuthorizable(aGroupPrincipal);
Privilege[] privileges = {
accessControlManager.privilegeFromName(Privilege.JCR_VERSION_MANAGEMENT),
accessControlManager.privilegeFromName(Privilege.JCR_MODIFY_PROPERTIES),
accessControlManager.privilegeFromName(Privilege.JCR_ADD_CHILD_NODES),
accessControlManager.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT),
accessControlManager.privilegeFromName(Privilege.JCR_NODE_TYPE_MANAGEMENT),
accessControlManager.privilegeFromName(Replicator.REPLICATE_PRIVILEGE)
};
AccessControlList aclList;
try {
aclList = (AccessControlList) accessControlManager.getApplicablePolicies(aPath).nextAccessControlPolicy();
} catch (NoSuchElementException e) {
aclList = (AccessControlList) accessControlManager.getPolicies(aPath)[0];
}
aclList.addAccessControlEntry(group.getPrincipal(), privileges);
accessControlManager.setPolicy(aPath, aclList);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

关于java - 在 AEM 中以编程方式授予组权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38344563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com