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

Shamith Shankar May 31, 2015
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

2 answers

1 vote
Olalekan Fagbemiro October 8, 2020

Someone posted a solution at https://community.developer.atlassian.com/t/getting-exception-while-updating-user-groups-from-ssl-enabled-ad-directory/20168/3.

Basically the solution described was to to switch to another class loader so that the LdapHostnameVerificationSSLSocketFactory class can be loaded (worked for me)

Thread currentThread = Thread.currentThread();
ClassLoader classLoader= currentThread.getContextClassLoader();
currentThread.setContextClassLoader(LdapHostnameVerificationSSLSocketFactory.class.getClassLoader()); 

 

1 vote
Alex Sergeev October 26, 2015

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