Hi,
I am trying to add member to group from code (via service) and user list from getMembers() is successfully fetching the newly added member details, however, when checking same at userAdmin (screen) then newly added member is not present in the group.
Can anyone help me to find what I am missing there?
Regards
Divya
Solved! Go to Solution.
Hi @DivyaTyagi, looking on code you have shared, I have few observations:
// resource resolver #1 UserManager userManager = resourceResolverAddMember.adaptTo(UserManager.class); // resource resolver #2 Session currentSession = resourceResolver.adaptTo(Session.class);
log.info("Member added to group ::" + result);
// currentSession.save();
log.info("Current session is saved");
In my opinion the root cause of the issue is level of permissions of session you are using. It can be easily check. Please modify your code like below:
log.info("Member added to group ::" + result); currentSession.save(); log.info("Current session is saved"); // refreshing session currentSession.refresh(false); //** To get members of group Iterator<Authorizable> auth = cugGroup.getMembers(); while(auth.hasNext()) { Authorizable authMember = auth.next(); log.info("Grp Member :: " + authMember.getID()); }
If you will you see that changes are not saved - then the solution will be to use session that will allow you to modify/add new users to the group.
Hi @DivyaTyagi
Are you using Usermanger Api to add the user.
Could you add your code snippet to check.
Regards,
Sanjay
@DivyaTyagi - Just making sure, are you using the JackrabbitSession and making sure the session is saved?
A code snippet should help to get more ideas..
Thanks
I am using javax.jcr.Session and saving the session after adding member to group.
Hi,
Did you saved/commit the session changes?
Note : Please do not use below method if you are checking if user is already part of group or not, this method is very expensive
userGroup.isMember(user)
Yes , I am saving the current session after adding member to group.
Hi,
@Sanjay_Bangar @arunpatidar @Shubham_borole
Thanks for the response.
Below is the code snippet I am using. Code is executing successfully and I am getting recently added member in logs but same is not reflecting at userAdmin (https://author-server.adobecqms.net/useradmin)
if(StringUtils.isNotEmpty(page.getProperties().get(CUG_GROUP, String.class))) {
UserManager userManager = resourceResolverAddMember.adaptTo(UserManager.class);
Session currentSession = resourceResolver.adaptTo(Session.class);
try {
Authorizable user = userManager.getAuthorizable(currentSession.getUserID());
Group cugGroup = (Group) userManager.getAuthorizable(page.getProperties().get(CUG_GROUP, String.class));
if(cugGroup != null){
boolean result = cugGroup.addMember(user);
log.info("Member added to group ::" + result);
currentSession.save();
log.info("Current session is saved");
//** To get members of group
Iterator<Authorizable> auth = cugGroup.getMembers();
while(auth.hasNext()){
Authorizable authMember = auth.next();
log.info("Grp Member :: " + authMember.getID());
}
return true;
}
} catch (RepositoryException e) {
// TODO Auto-generated catch block
log.error("Error :: " + e.getMessage());
e.printStackTrace();
}
return false;
}
Regards
Divya
Hi,
Your code looks fine.
I also tried with groovyconsole. it works for me.
import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; UserManager userManager = resourceResolver.adaptTo(UserManager.class); Authorizable user = userManager.getAuthorizable(session.getUserID()); Group cugGroup = (Group) userManager.getAuthorizable("test-group-2"); if(cugGroup != null){ boolean result = cugGroup.addMember(user); println("Member added to group ::" + result); save(); println("Current session is saved"); //** To get members of group }
Could you please check error logs, could be an issue while saving?
Hi @DivyaTyagi, looking on code you have shared, I have few observations:
// resource resolver #1 UserManager userManager = resourceResolverAddMember.adaptTo(UserManager.class); // resource resolver #2 Session currentSession = resourceResolver.adaptTo(Session.class);
log.info("Member added to group ::" + result);
// currentSession.save();
log.info("Current session is saved");
In my opinion the root cause of the issue is level of permissions of session you are using. It can be easily check. Please modify your code like below:
log.info("Member added to group ::" + result); currentSession.save(); log.info("Current session is saved"); // refreshing session currentSession.refresh(false); //** To get members of group Iterator<Authorizable> auth = cugGroup.getMembers(); while(auth.hasNext()) { Authorizable authMember = auth.next(); log.info("Grp Member :: " + authMember.getID()); }
If you will you see that changes are not saved - then the solution will be to use session that will allow you to modify/add new users to the group.
Thanks for the reply.
I am getting newly added group in logs via below code :-
//** To get members of group Iterator<Authorizable> auth = cugGroup.getMembers(); while(auth.hasNext()) { Authorizable authMember = auth.next(); log.info("Grp Member :: " + authMember.getID()); }
However, newly member not displayed to group (as member) at UserAdmin screen (https://publish-server.adobecqms.net/useradmin)
Regards
Divya
Hi @DivyaTyagi, did you refreshed session before getting list of group members? Also could you please confirm that session you are using has permissions to add new user to the group?
I have added session.refresh(false) as suggested by you but getting same results. We have tried with even granting admin access for the session we are using to add new user to the group.
Views
Likes
Replies
Views
Likes
Replies