如何在 Sling 中创建系统用户?
How to create system user in Sling?
如何在 Sling 中创建系统用户?
我尝试搜索,但我找到的所有内容都与我不使用的 AEM 相关。是否可以使用 Jackrabbit API 或 Sling 初始内容(描述文件)创建用户?
我尝试执行以下操作:
curl -u admin:admin -F:name=myuser -Fpwd=mypwd -FpwdConfirm=mypwd -Frep:principalName=myuser -Fjcr:primaryType=rep:SystemUser http://localhost:8080/home/users/system/*
但是出现错误:
*ERROR* [127.0.0.1 [1465215465364] POST /home/users/system/* HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.
javax.jcr.nodetype.ConstraintViolationException: Property is protected: rep:principalName = myuser
at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:525)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.perform(NodeImpl.java:1358)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.perform(NodeImpl.java:1346)
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:209)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1346)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:432)
at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:592)
不确定是否可以通过 post 请求满足:https://mail-archives.apache.org/mod_mbox/sling-users/201512.mbox/%3CCAFMYLMb9Wiy+DYmacc5oT7YRWT1hth8j1XAAo_sKT8uq9HoFNw@mail.gmail.com%3E
建议的解决方案是使用大耳兔 api 来执行此操作。这看起来像:
//get a user manager
try {
User systemUser = userManager.createSystemUser("myuser", "/home/users/system");
} catch (Exception e) {
log.error("Error adding user",e);
throw e;
}
//commit changes
请务必注意,这不允许您为此用户设置密码,也不能使用 user.changePassword() 设置密码——当我尝试这样做时出现错误:
javax.jcr.UnsupportedRepositoryOperationException: system user
来自 java 文档:
Create a new system user for the specified userID. The new authorizable is required to have the following characteristics:
- User.isSystemUser() returns true.
- The system user doesn't have a password set and doesn't allow change the password.
http://jackrabbit.apache.org/api/2.10/org/apache/jackrabbit/core/security/user/UserManagerImpl.html
这是我的整个激活器 class:https://gist.github.com/scrupulo/61b574c9aa1838da37d456012af5dd50
有一个基于 Sling 和 Jackrabbit Oak 的现成解决方案。它具有用于设置用户和 ACL 的基于文本的 DSL,例如:
create service user bob,alice
set ACL on /libs,/apps
remove * for alice
allow jcr:read for bob
end
也可以将这些说明嵌入用于构建 Sling 启动板的配置模型中 - 假设您使用的是 slingstart-maven-plugin
。
完整的文档可以在 Repository Initializers and Repository Initialization Language
找到
如何在 Sling 中创建系统用户?
我尝试搜索,但我找到的所有内容都与我不使用的 AEM 相关。是否可以使用 Jackrabbit API 或 Sling 初始内容(描述文件)创建用户?
我尝试执行以下操作:
curl -u admin:admin -F:name=myuser -Fpwd=mypwd -FpwdConfirm=mypwd -Frep:principalName=myuser -Fjcr:primaryType=rep:SystemUser http://localhost:8080/home/users/system/*
但是出现错误:
*ERROR* [127.0.0.1 [1465215465364] POST /home/users/system/* HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.
javax.jcr.nodetype.ConstraintViolationException: Property is protected: rep:principalName = myuser
at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:525)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.perform(NodeImpl.java:1358)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.perform(NodeImpl.java:1346)
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:209)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1346)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:432)
at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:592)
不确定是否可以通过 post 请求满足:https://mail-archives.apache.org/mod_mbox/sling-users/201512.mbox/%3CCAFMYLMb9Wiy+DYmacc5oT7YRWT1hth8j1XAAo_sKT8uq9HoFNw@mail.gmail.com%3E
建议的解决方案是使用大耳兔 api 来执行此操作。这看起来像:
//get a user manager
try {
User systemUser = userManager.createSystemUser("myuser", "/home/users/system");
} catch (Exception e) {
log.error("Error adding user",e);
throw e;
}
//commit changes
请务必注意,这不允许您为此用户设置密码,也不能使用 user.changePassword() 设置密码——当我尝试这样做时出现错误:
javax.jcr.UnsupportedRepositoryOperationException: system user
来自 java 文档:
Create a new system user for the specified userID. The new authorizable is required to have the following characteristics:
- User.isSystemUser() returns true.
- The system user doesn't have a password set and doesn't allow change the password.
http://jackrabbit.apache.org/api/2.10/org/apache/jackrabbit/core/security/user/UserManagerImpl.html
这是我的整个激活器 class:https://gist.github.com/scrupulo/61b574c9aa1838da37d456012af5dd50
有一个基于 Sling 和 Jackrabbit Oak 的现成解决方案。它具有用于设置用户和 ACL 的基于文本的 DSL,例如:
create service user bob,alice
set ACL on /libs,/apps
remove * for alice
allow jcr:read for bob
end
也可以将这些说明嵌入用于构建 Sling 启动板的配置模型中 - 假设您使用的是 slingstart-maven-plugin
。
完整的文档可以在 Repository Initializers and Repository Initialization Language
找到