Issue Type: Improvement Improvement
Assignee: Oleg Nenashev
Components: role-strategy
Created: 08/Jul/14 9:21 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.

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
  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"
}
Project: Jenkins
Priority: Major Major
Reporter: Michael Rumpf
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 jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to