LDAP security realm / groovy init script issue

61 views
Skip to first unread message

geoffroy...@gmail.com

unread,
Jan 26, 2023, 12:14:21 PM1/26/23
to Jenkins Users
Hello

i am trying to configure LDAP Security Realm using groovy init script.

So far, it works fine, but i am not able to Disable Role Prefixing using the method  setDisableRolePrefixing

Code:
...
instance.securityRealm = new LDAPSecurityRealm(...)
instance.securityRealm.setDisableRolePrefixing​(true)
instance.save()


Error is: 
groovy.lang.MissingMethodException: No signature of method: hudson.security.LDAPSecurityRealm.setDisableRolePrefixing​() is applicable for argument types: (java.lang.Boolean) values: [true]
Possible solutions: setDisableRolePrefixing(boolean), isDisableRolePrefixing()
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71)

I'm not fluent with groovy/java, and i don't understand why the method is not recognized although given possible solutions actually list the method...

Thanks in advance for your help

Thomas Markus

unread,
Jan 27, 2023, 2:15:20 AM1/27/23
to jenkins...@googlegroups.com
Hi,

Am 26.01.23 um 18:14 schrieb geoffroy...@gmail.com:
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/eda149c1-dba6-4cc1-ab27-7cfd416d563en%40googlegroups.com.

maybe the typical confusion between Boolean and boolean, try
instance.securityRealm.setDisableRolePrefixing​(Boolean.TRUE.booleanValue())
instead of
instance.securityRealm.setDisableRolePrefixing​(true)

best regards
Thomas
OpenPGP_0x9794716335E9B5AF.asc
OpenPGP_signature

geoffroy...@gmail.com

unread,
Jan 27, 2023, 4:37:21 AM1/27/23
to Jenkins Users
Hi Thomas
thanks for your answer.
i tried it (and googled a bit about java boolean vs Boolean), but no success, still same error.
I also tried variations of Boolean.TRUE instead of true for another function call, and it worked fine.
So seems the issue is not related to such confusion...

geoffroy...@gmail.com

unread,
Feb 13, 2023, 5:26:14 AM2/13/23
to Jenkins Users
Hi
sorry to bump this thread, but i was not able to find a solution.
Any idea? Shall i create a ticket?
Thx

Baptiste Mathus

unread,
Feb 13, 2023, 11:10:18 AM2/13/23
to jenkins...@googlegroups.com
Hi,

It looks like you should heavily consider using Jenkins Configuration As Code.
See https://plugins.jenkins.io/ldap/#plugin-content-configuration-with-jcasc

Using system Groovy scripting like your code is doing is much more risky (this could well break an instance) and reserved to experts as it directly manipulates the Jenkins API (i.e. no guarantee that it will keep working durably).

> Shall i create a ticket?

This looks more like a support request than an actual bug at this point. So I'd say not yet at least. 


geoffroy...@gmail.com

unread,
Feb 14, 2023, 5:23:26 AM2/14/23
to Jenkins Users
Thanks for your help

sure we are also considering CasC, but so far Post Init groovy scripts have proven to be a viable solution (but now outdated) to perform some configuration as code.

My concern here is this is the first time i am facing such issue, where a Java class method cannot be called from init groovy script.
Script is directly manipulating Jenkins java code, not API. So i would expect that the well-defined and simple (setter) java method setDisableRolePrefixing can be called from it...

Regards

Reply all
Reply to author
Forward
0 new messages