![]() |
|
|
|
|
Change By:
|
Michael Rumpf
(08/Jul/14 9:23 AM)
|
|
Description:
|
I' currently trying to automate the role creation and assignment. As the plugin does not provide a REST API, the only chance was to execute a System Groovy Script via Jenkins' script console.
The ugly thing is that the Plugin API seems to be aimed at internal usage only. The Role constructors are package protected so that I was forced to use "setAccessible(true)" in order to make them accessible.
The following script shows a first draft which only creates a role without any permissions yet:
{code} import Hudson.* import java.util.* import com.michelin.cio.hudson.plugins.rolestrategy.* import java.lang.reflect.* import hudson.security.*
def authStrategy = Hudson.instance.getAuthorizationStrategy()
if(authStrategy instanceof RoleBasedAuthorizationStrategy){ println "Role Strategy Plugin found!" RoleBasedAuthorizationStrategy roleAuthStrategy = (RoleBasedAuthorizationStrategy) authStrategy
// Make constructors
available
accessible
Constructor[] constrs = Role.class.getConstructors(); for (Constructor<?> c : constrs) { c.setAccessible(true); } // create the new role Set<Permission> permissions = new HashSet<Permission>(); permissions.add(""); // TODO: Pass list of Permissions Role newRole = new Role("test", "test.*", null); roleAuthStrategy.addRole(RoleBasedAuthorizationStrategy.PROJECT, newRole);
// Role, Set<String> def globalRoles = roleAuthStrategy.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL) def projectRoles = roleAuthStrategy.getGrantedRoles(RoleBasedAuthorizationStrategy.PROJECT) def slaveRoles = roleAuthStrategy.getGrantedRoles(RoleBasedAuthorizationStrategy.SLAVE)
println "GLOBAL:" for (r in globalRoles) { println " " + r.key.name }
println "PROJECT:" for (r in projectRoles) { println " " + r.key.name }
println "SLAVE:" for (r in slaveRoles) { println " " + r.key.name } } else { println "not found" } {code}
|
|
|
|
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
|
--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[email protected].
For more options, visit
https://groups.google.com/d/optout.