我写了一个java程序来在AEM中创建一个Group。它工作正常。但与Group
一起,我还需要创建另一个组aboutMe
属性。
我的代码:
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
UserManager userManager = ((JackrabbitSession) session).getUserManager();
JackrabbitSession js = (JackrabbitSession) session;
Group group = null;
group = userManager.createGroup("TestGroup");
session.save();
有没有办法添加aboutMe属性字段?
答案 0 :(得分:0)
您可以group.setProperty("jcr:description","your string")
或任何财产。请参阅javadocs here
<强>更新强>
为com.adobe.granite.security.user
注入
@Reference
private UserPropertiesService service;
获取UserProperties对象(资源是您的组的资源实例) -
if (this.service != null) {
Authorizable authorizable = (Authorizable)resource.adaptTo(Authorizable.class);
UserProperties userProperties;
if (authorizable == null)
{
UserProperties userProperties = (UserProperties)resource.adaptTo(UserProperties.class);
if (userProperties != null) {
UserManager uMgr = (UserManager)resolver.adaptTo(UserManager.class);
authorizable = uMgr.getAuthorizable(userProperties.getAuthorizableID());
}
}
else
{
Session session = ((Node)resource.adaptTo(Node.class)).getSession();
UserPropertiesManager mgr = this.service.createUserPropertiesManager(session, resolver);
String propPath = request.getParameter("path");
userProperties = mgr.getUserProperties(authorizable, propPath);
}
获得UserProperties后,您可以将aboutMe
信息添加到您的论坛。