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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

90 views 0 5
Read article

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