Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-32710

Configure AD Authorization with Groovy

    Details

    • Similar Issues:

      Description

      I am working on configuring Active Directory via Groovy.

      I was able to authenticate via active directory via the UI.

      I have the following based on the LDAP plugin:

          import jenkins.model.*
          import hudson.security.*
          import hudson.plugins.*
          import hudson.plugins.active_directory.*
          import hudson.*
          import jenkins.*
      
          String domain = 'my.domain.com'
          String site = ''
          String server = '192.168.1.1'
          String bindName = 'account@my.domain.com'
          String bindPassword = 'password'
      
          SecurityRealm ad_realm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server)
          jenkins.instance.setSecurityRealm(ad_realm)
      

      This is the error:

      Expected process to exit with [0], but received '255'
                 ---- Begin output of "/opt/java/latest/bin/java" -jar "/tmp/kitchen/cache/jenkins-cli.jar" -s http://localhost:8080 groovy /tmp/groovy20160208-28479-azdr83 ----
                 STDOUT: 
                 STDERR: groovy.lang.MissingPropertyException: No such property: jenkins for class: RemoteClass
                 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
                 	at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
                 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
                 	at RemoteClass.run(RemoteClass:16)
                 	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
                 	at groovy.lang.GroovyShell.run(GroovyShell.java:517)
                 	at hudson.cli.GroovyCommand.run(GroovyCommand.java:86)
                 	at hudson.cli.CLICommand.main(CLICommand.java:237)
                 	at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:92)
                 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                 	at java.lang.reflect.Method.invoke(Method.java:497)
                 	at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:608)
                 	at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:583)
                 	at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:542)
                 	at hudson.remoting.UserRequest.perform(UserRequest.java:120)
                 	at hudson.remoting.UserRequest.perform(UserRequest.java:48)
                 	at hudson.remoting.Request$2.run(Request.java:326)
                 	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
                 	at hudson.cli.CliManagerImpl$1.call(CliManagerImpl.java:63)
                 	at hudson.remoting.CallableDecoratorAdapter.call(CallableDecoratorAdapter.java:18)
                 	at hudson.remoting.CallableDecoratorList$1.call(CallableDecoratorList.java:21)
                 	at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
                 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
                 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
                 	at java.lang.Thread.run(Thread.java:745)
                 ---- End output of "/opt/java/latest/bin/java" -jar "/tmp/kitchen/cache/jenkins-cli.jar" -s http://localhost:8080 groovy /tmp/groovy20160208-28479-azdr83 ----
                 Ran "/opt/java/latest/bin/java" -jar "/tmp/kitchen/cache/jenkins-cli.jar" -s http://localhost:8080 groovy /tmp/groovy20160208-28479-azdr83 returned 255
      

      Any idea on why I see No such property: jenkins for class: RemoteClass?

        Attachments

          Issue Links

            Activity

            Hide
            jsmickey John Mickey added a comment -

            'site' cannot be nill when configured via Groovy.
            Here is an answer:

            import jenkins.model.*
            import hudson.security.*
            import hudson.plugins.active_directory.*
               
            def instance = Jenkins.getInstance()
            String domain = 'my.domain.com'
            String site = 'site'
            String server = '192.168.1.1'
            String bindName = 'account@my.domain.com'
            String bindPassword = 'password'
            adrealm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server)
            instance.setSecurityRealm(adrealm)
            
            Show
            jsmickey John Mickey added a comment - 'site' cannot be nill when configured via Groovy. Here is an answer: import jenkins.model.* import hudson.security.* import hudson.plugins.active_directory.* def instance = Jenkins.getInstance() String domain = 'my.domain.com' String site = 'site' String server = '192.168.1.1' String bindName = 'account@my.domain.com' String bindPassword = 'password' adrealm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server) instance.setSecurityRealm(adrealm)
            Hide
            inebrious Benjamin Goldman added a comment -

            John Mickey question: the documentation (read the code...) implies that both site and server can be blank and optional.

            thoughts on how we can reconcile this?

            Show
            inebrious Benjamin Goldman added a comment - John Mickey question: the documentation (read the code...) implies that both site and server can be blank and optional. thoughts on how we can reconcile this?
            Hide
            vishwadeep_bansal Vishwadeep Bansal added a comment - - edited

            import jenkins.model.import hudson.security.*import hudson.plugins.active_directory.

            def instance = Jenkins.getInstance()String domain = 'my.domain.com'String site = 'site'String server = '192.168.1.1'String bindName = 'account@my.domain.com'String bindPassword = 'password'
            adrealm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server)
            instance.setSecurityRealm(adrealm)

            I am doing automated AD integration with the code mentioned above, however getting issues. bindName is not getting updated on the page and authentication do not work. Also I would like to keep the script in init.groovy.d folder so that it could do the charm when service starts.

            Show
            vishwadeep_bansal Vishwadeep Bansal added a comment - - edited import jenkins.model. import hudson.security.*import hudson.plugins.active_directory. def instance = Jenkins.getInstance()String domain = 'my.domain.com'String site = 'site'String server = '192.168.1.1'String bindName = 'account@my.domain.com'String bindPassword = 'password' adrealm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server) instance.setSecurityRealm(adrealm) I am doing automated AD integration with the code mentioned above, however getting issues. bindName is not getting updated on the page and authentication do not work. Also I would like to keep the script in init.groovy.d folder so that it could do the charm when service starts.
            Show
            kpsimoulis Konstantinos Psimoulis added a comment - Please check my comment in: https://issues.jenkins-ci.org/browse/JENKINS-44822?focusedCommentId=344366&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-344366

              People

              • Assignee:
                Unassigned
                Reporter:
                jsmickey John Mickey
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: