not able to add users to group for AD with local groups

Hi,
I am using below commands to add users to group for AD with local groups ,
Group g = ComponentAccessor.getCrowdService().getGroup("dev1")
ComponentAccessor.getUserUtil().addUserToGroup(g,u9)

dev1 is local group and u9 is AD user. i am able to add in UI but throwing below exception while using grovy script to update. Am i missing anything here ?

 

com.atlassian.jira.exception.AddException: com.atlassian.crowd.exception.runtime.OperationFailedException: org.springframework.transaction.CannotCreateTransactionException: Could not create DirContext instance for transaction; nested exception is org.springframework.ldap.CommunicationException; nested exception is javax.naming.CommunicationException: [Root exception is java.lang.ClassNotFoundException: com.atlassian.crowd.directory.ssl.LdapHostnameVerificationSSLSocketFactory] at com.atlassian.jira.user.util.UserUtilImpl.doAddUserToGroup(UserUtilImpl.java:615) at com.atlassian.jira.user.util.UserUtilImpl.addUserToGroup(UserUtilImpl.java:597) at com.atlassian.jira.user.util.UserUtil$addUserToGroup.call(Unknown Source) at UpdateFieldsScript2.doScript(update_users.groovy:2837) at UpdateFieldsScript2$doScript.call(Unknown Source) at update_users.run(update_users.groovy:2879) Caused by: com.atlassian.crowd.exception.runtime.OperationFailedException: org.springframework.transaction.CannotCreateTransactionException: Could not create DirContext instance for transaction; nested exception is org.springframework.ldap.CommunicationException: ; nested exception is javax.naming.CommunicationException:  [Root exception is java.lang.ClassNotFoundException: com.atlassian.crowd.directory.ssl.LdapHostnameVerificationSSLSocketFactory] at com.atlassian.crowd.embedded.core.CrowdServiceImpl.addUserToGroup(CrowdServiceImpl.java:734) at com.atlassian.crowd.embedded.core.DelegatingCrowdService.addUserToGroup(DelegatingCrowdService.java:165) at com.atlassian.crowd.embedded.core.FilteredCrowdServiceImpl.addUserToGroup(FilteredCrowdServiceImpl.java:324) at com.atlassian.jira.user.util.UserUtilImpl.doAddUserToGroup(UserUtilImpl.java:607) ... 5 more

1 answer

We just have resolved similar problem.
This code also (like UserUtil) does not work with AD:

GroupManager groupManager = ComponentAccessor.getGroupManager();
UserManager userManager = ComponentAccessor.getUserManager();
User user = userManager.getUserByKey("username");
Group group = groupManager.getGroup("groupname");
groupManager.addUserToGroup(user.directoryUser, group);

But switching from GroupManager to GroupService makes it work with AD:

UserManager userManager = ComponentAccessor.getUserManager();
User user = userManager.getUserByKey("admin-user");
JiraServiceContext context = new JiraServiceContextImpl(user); // user which adds another user to a group
GroupService groupService = ComponentAccessor.getOSGiComponentInstanceOfType(com.atlassian.jira.bc.group.GroupService.class)
groupService.addUsersToGroups(context, Collections.singleton("groupname"), Collections.singleton("username")); // this may be optimized :)

// in case you want to check operation result see this for errors:
context.getErrorCollection();
There are still some possible cases when it does not work but the same applies to trying to add a user to a group via UI.

UPD: JIRA version is 6.3.12

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

20,744 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you