Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting with Active Directory Server from jira script runners using jira crowd directory service

Virender Kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 5, 2019

We are running Jira version 7.10, and trying to connect with Active Directory Service with jira script runners groovy scripts. I browsed some google links and able to write the below code.

However the code gives the exception with "validated object is Null", on the code execution line "RemoteDirectory mydir = dir.getDirectory(my_directory)".

Any help is much appreciated.

// All import Statement
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.CrowdDirectoryService
import com.atlassian.crowd.embedded.api.Directory
import com.atlassian.crowd.directory.RemoteDirectory // interface
import com.atlassian.crowd.search.builder.QueryBuilder
import com.atlassian.crowd.search.builder.Restriction
import com.atlassian.crowd.search.query.entity.restriction.constants.UserTermKeys
import com.atlassian.crowd.search.EntityDescriptor
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.directory.GenericLDAP
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.crowd.directory.DelegatedAuthenticationDirectory
import com.atlassian.crowd.directory.loader.DelegatedAuthenticationDirectoryInstanceLoader // interface
import com.atlassian.crowd.directory.loader.DelegatedAuthenticationDirectoryInstanceLoaderImpl
import com.atlassian.crowd.directory.ssl.LdapHostnameVerificationSSLSocketFactory

def dirsvc = ComponentAccessor.getComponent(CrowdDirectoryService)
def dirs = dirsvc.findAllDirectories()
Directory my_directory = dirsvc.findDirectoryById(10000)
log.info(my_directory.getName())
log.info(my_directory.getType())
log.info(my_directory.getDescription())
def dir = ComponentAccessor.getComponent(DelegatedAuthenticationDirectoryInstanceLoaderImpl)
log.info(dir)
log.info("Basic directory created")
RemoteDirectory mydir = dir.getDirectory(my_directory)
log.info("Remote directory created")
def qry = QueryBuilder.queryFor(User.class, EntityDescriptor.user()).with( Restriction.on(UserTermKeys.LAST_NAME).startingWith("berg")).returningAtMost(10)
log.info(qry)
def ldap = mydir.getAuthoritativeDirectory()
def users2 = ldap.searchUsers(qry)
log.info(users2)

2019-11-05 18:39:56,744 http-nio-80-exec-58 ERROR MMT5551 1119x22944x1 1i7at5n 172.16.114.203 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TE-16, actionId: 41, file: /opt/atlassian/scripts/assign_ticket_to_user_manager.groovy
java.lang.NullPointerException: The validated object is null
at org.apache.commons.lang3.Validate.notNull(Validate.java:222)
at org.apache.commons.lang3.Validate.notNull(Validate.java:203)
at com.atlassian.crowd.model.directory.DirectoryImpl.setImplementationClass(DirectoryImpl.java:216)
at com.atlassian.crowd.directory.loader.DelegatedAuthenticationDirectoryInstanceLoaderImpl.getLdapVersionOfDirectory(DelegatedAuthenticationDirectoryInstanceLoaderImpl.java:49)
at com.atlassian.crowd.directory.loader.DelegatedAuthenticationDirectoryInstanceLoaderImpl.getDirectory(DelegatedAuthenticationDirectoryInstanceLoaderImpl.java:38)
at com.atlassian.crowd.directory.loader.DirectoryInstanceLoader$getDirectory.call(Unknown Source)
at assign_ticket_to_user_manager.run(assign_ticket_to_user_manager.groovy:32)

 

 

0 answers

Suggest an answer

Log in or Sign up to answer