Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Persistance Error creating new Group from UserManager (ResourcerResolver.commit())

Avatar

Level 5

I have a service I call on to create a new approver group for a user if it doesn't already exist, here's the whole method:

public void updateApproverGroup(Author person) { try { Map<String, Object> param = new HashMap<String, Object>();         param.put(ResourceResolverFactory.SUBSERVICE, "WriteService"); ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(param);       log.info(resourceResolver.getUserID());     session = resourceResolver.adaptTo(Session.class);     userManager = resourceResolver.adaptTo(UserManager.class);     String groupName = person.id + "Approvers"; //does the group exist? Group group = (Group) userManager.getAuthorizable(groupName); if(group == null) { //create the group group = userManager.createGroup(groupName,new SimplePrincipal(groupName),"/home/groups/news"); log.error(group.getPath()); } resourceResolver.commit(); } catch (Exception e) { log.error(e.getMessage()); for(int i  = 0; i < e.getStackTrace().length; i++) { log.error(e.getStackTrace()[i].toString()); } return; } }

My catch block catches an exception, here's the first few lines from my console

30.09.2015 09:17:30.342 *INFO* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl writeuser 30.09.2015 09:17:30.347 *ERROR* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl /home/groups/news/TrloE9Ztv_oj1nzsxYfU 30.09.2015 09:17:30.350 *ERROR* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl Unable to commit changes to session. 30.09.2015 09:17:30.351 *ERROR* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.commit(JcrResourceProvider.java:638) 30.09.2015 09:17:30.351 *ERROR* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext.commit(ResourceResolverContext.java:181) 30.09.2015 09:17:30.351 *ERROR* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl org.apache.sling.resourceresolver.impl.ResourceResolverImpl.commit(ResourceResolverImpl.java:1147) 30.09.2015 09:17:30.351 *ERROR* [0:0:0:0:0:0:0:1 [1443619050214] POST /content/news/stories/200005.request HTTP/1.1] com.uc.news.PersonServiceImpl com.uc.news.PersonServiceImpl.updateApproverGroup(PersonServiceImpl.java:205)

writeuser has full rights for the entire repository, so it doesn't seem like a permissions issue. 

The group that it puts in the console at the second line isn't showing up in the repo either (as expected).

I've also tried creating the usermanager from a jackrabbitsession I adapted from the resource resolver, with no luck. (that method is detailed here).

1 Accepted Solution

Avatar

Correct answer by
Level 10

See this community article where we created both AEM users and groups using the Jackrabbit API:

https://helpx.adobe.com/experience-manager/using/jackrabbit-users.html

View solution in original post

6 Replies

Avatar

Level 5

Do something like this, I think subservice logic is not working in AEM 6.1 (It used to work in AEM6.0)

@Reference ResourceResolverFactory rrfac; ResourceResolver rr=null; Map<String,Object> authInfo = new HashMap<String,Object>(); //Change this code in future to use read only user authInfo.put(ResourceResolverFactory.USER_IMPERSONATION,"WriteUser"); rr = rrfac.getAdministrativeResourceResolver(authInfo); //Your Logic rr.commit();

Avatar

Level 10

can you use resourceResolver.refresh() before commit() and try

Avatar

Level 5

I tried that both before and after the userManager.createGroup() with no success, the log is essentially exactly as before.

Avatar

Correct answer by
Level 10

See this community article where we created both AEM users and groups using the Jackrabbit API:

https://helpx.adobe.com/experience-manager/using/jackrabbit-users.html

Avatar

Level 5

This worked when I swapped the resourcerevolver to resolverFactory.getAdministrativeResourceResolver(null); (as opposed to using getServiceResourceResolver).

I know that getAdministrativeResourceResolver() is deprecated, but I'll use it for now--are there details on how these differ? Is it as simple as using the admin user? How would the admin user differ from a system user will full rights?

Avatar

Level 10

I have seen that behaviour myself - that looks almost like a bug. Sometimes (like this case) so called deprecated APIs work better. This is one of those cases.