-
Bug
-
Resolution: Not A Defect
-
Major
-
None
-
Jenkins version latest 1.60
Operating system : OpenSuse
Installed plugins: Groovy, credentials , ssh,
BACKGROUND OF ISSUE:
I am using groovy scripting console from jenkins to enable the global security of jenkins server.
I looked around jenkins code to see if there is already a method which i can call, instead I got a function called `disableSecurity` which disables the global security, as defined here:
https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/Jenkins.java#L2160
This method basically sets the boolean variable called 'useSecurity' to false.
PROBLEM :
Now I actually wanted to see if there is a method where this private bool variable `useSecurity` is set to true.
Luckily i found the method `setAuthorizationStrategy` which no matter if nothing passed to this method, will set `useSecurity` to true always whenever it gets called.
Now in my groovy script im calling it like this:
import jenkins.model.* def inst = Jenkins.getInstance() inst.setAuthorizationStrategy() inst.save()
But after i run the script, my security is still disabled.
Looking at code here : https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/Jenkins.java#L2148
The method defined in above link is like this:
public void setAuthorizationStrategy(AuthorizationStrategy a) { if (a == null) a = AuthorizationStrategy.UNSECURED; useSecurity = true; authorizationStrategy = a; }
I see this sets the value of useSecurity to true.
but upon execution, my security yet remains disabled.
WORKAROUND NEEDED: I would like to know if im lacking understanding of this code or there are some caveats im missing.
also if someone can please suggest me a way of enabling security from groovy, would really appreciate it.
SUGGESTED SOLUTION:
defined another method like "disableSecurity", call it "enableSecurity" , and in it , set the value of boolean 'useSecurity' to true.