JIRA v5.2.2
SUMMARY: I have a Groovy script that -- currently -- successfully sends emails to individuals (not necessarilly JIRA users) within our organization. I'm having trouble using LDAP-defined groups.
QUESTION: Can you take a look at my script and let me know if there's a way to adjust so that I'll be able to send emails to LDAP-defined groups; not just individuals?
SCRIPT:
def componentManager = ComponentManager.getInstance(); def mailServiceManager = componentManager.getMailServerManager(): def mailServer = mailServiceManager.getDefaultSMTPMailServer(); Email jemail = new Email("LDAPGROUPNAME"); jemail.setFrom("me@me.com"); jemail.setFromName("Me"); jemail.setMimeType("text/html"); jemail.setSubtject("Testies"); jemail.setBody("Testing This"); mailServer.send(jemail);
ERRORS (ONLY OCCUR WHEN I USE AN LDAP-DEFINED GROUP):
Thanks for your consideration.
Community moderators have prevented the ability to post new answers.
Are you talking about LDAP distribution lists? Or groups defined in LDAP that you see in jira through synchronisation?
If the latter you need to iterate the group and mail the users individually, eg with com.atlassian.jira.security.groups.GroupManager#getUsersInGroup
If the former then the SMTP address for the group is not available in jira, you need to query ldap for it.
You can get an ldap connection for any of the configured user directories, can't find example code right now. Otherwise you can create your ldap connection and get the DL address yourself, using eg groovy-ldap (easy) or gldapo (harder).
Jamie --- this is awesome, thank you for covering all the bases in making up for my lack of detailed question. Your guidance on the LDAP distribution list is perfect --- I'll research the query ldap approach.
Thanks again, Jamie, good luck again West Ham today.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've given up on this season ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just a note about LDAP in groovyrunner - I was trying to do so using groovy-ldap (as a groovy service), but given up the the fight with classloaders so all the code I have rewritten to pure old java API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah that can be a bitter fight. Should work though if you drop groovy-ldap and groovy-all into web-inf/lib... works for me from the admin panel anyway. But better to get your connection from embedded crowd, otherwise you have to configure everything twice.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are right with getting connection attributes and it is as easy as
def cds = com.atlassian.jira.component.ComponentAccessor.getComponent(com.atlassian.crowd.embedded.api.CrowdDirectoryService) def attrs = cds.findAllDirectories().find{it.isActive() && it.attributes.keySet().contains('ldap.url')}?.attributes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I’d like to try using Groovy-Ldap in conjunction with Script Runner Scripted Fields. We dropped the groovy-ldap jar file and restarted JIRA. My sys admin says this file is from 2007 – so this could be my problem.
Here is my requirement:
Display a searchable select list on the Create screen that “queries” Active Directory users. These users are NOT JIRA-users.
I’ve added the following code into the Script section:
import org.apache.directory.groovyldap.LDAP LDAP = LDAP.newInstance('ldap://SERVER:389','cn=User, ou=IT, dc=com',
<Password>) // search op results = ldap.search('(objectClass=*)', 'dc=com', SearchScope.ONE ) def ResultList = null if (results) { ResultList = entry.cn }
I have a few issues . . . .
First, How do I test that ScriptRunner is utilizing the Groovy-Ldap API? I receive an error when reindexing: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: groovy/lang/Closure
Second, since I need this field to display on the screen, I’ve added the following to the description field of Field A, so, I can see Field B (Scripted Field). I’ve updated the config information in the javascript code from: https://gist.github.com/jechlin/5380119. I can’t seem to get this to work. I’ve taken out the code to look for an action.
Jamie – you mentioned above – groovy-all – is this what I’m missing?
Using JIRA 6.0.8.
Thank You.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The library is old, but still works fine, more or less.
You should put groovy-ldap into web-inf/lib. You should NOT put groovy-all.jar into web-inf/lib, or anywhere else, it is already bundled in the plugin.
First of all do some simple tests in admin -> script console, don't go straight to scripted fields and blow up the indexing...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin got the same error
java.lang.NoClassDefFoundError: groovy/lang/Closure
library already in /opt/jira/atlassian-jira/WEB-INF/lib
just after jira restart.
code is
import org.apache.directory.groovyldap.LDAP lda_server = 'ldap://192.168.0.1:389' ldap_user = 'ldap_user' ldap_password = 'XXXXX' ldap = LDAP.newInstance(lda_server, ldap_user, ldap_password )
got exception on last line
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aleksey,
I got the same error as you. Could you find the reason or any solutions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It kind of works if you put groovy-ldap.jar into the scriptrunner's jar, into the META-INF/lib directory. I was still not able to really retrieve information from LDAP (JNDI to "normal object" conversion did not work, or I was not smart enough to figure it out), but I was perfectly able to validate whether a particular entry exists, which was my intention in the first place.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.