如何以编程方式提供用户权限?

gst*_*low 5 permissions aem

我知道我可以给予权限

${host}:4502/useradmin
Run Code Online (Sandbox Code Playgroud)

当我双击用户登录并转到Permissions选项卡

我想在部署内容包时提供权限.

可能吗?

Sab*_*bya 5

当您为特定节点/路径的用户授予权限时,它基本上将权限存储在rep:policy节点下面的节点级别(允许/拒绝).

我想在部署内容包时提供权限.

  • 您可以部署仅包含rep:policies的AEM包,这些策略将通过useradmin用于设置权限.

您可以参考ACS Tools的ACL打包程序来打包ACL.

注意:安装程序包的用户需要具有设置ACL的权限

要以编程方式设置ACL(如问题的标题所示),您可能需要检查几个Jackrabbit/JCR接口/类.

org.apache.jackrabbit.api.security.JackrabbitAccessControlManager
org.apache.jackrabbit.api.security.JackrabbitAccessControlList
javax.jcr.security.Privilege
Run Code Online (Sandbox Code Playgroud)


gst*_*low 5

我在要配置权限文件的文件夹下添加了名称

_rep_policy.xml
Run Code Online (Sandbox Code Playgroud)

内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
          jcr:primaryType="rep:ACL">
    <allow
            jcr:primaryType="rep:GrantACE"
            rep:principalName="myusername"
            rep:privileges="{Name}[jcr:read,rep:write,jcr:versionManagement,jcr:lockManagement]"/>
</jcr:root>
Run Code Online (Sandbox Code Playgroud)

在pom.xml中,我添加了以下条目:

<profiles>
        <profile>
            <id>autoInstallContentPackage</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.day.jcr.vault</groupId>
                        <artifactId>content-package-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install-package</id>
                                <goals>
                                    <goal>install</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            ...
                            <properties>
                                <acHandling>Overwrite</acHandling>   //allow modify permissions
                            </properties>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        ....
Run Code Online (Sandbox Code Playgroud)