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
Constructor[] constrs = Role.class.getConstructors();
for (Constructor<?> c : constrs) {
c.setAccessible(true);
}
Set<Permission> permissions = new HashSet<Permission>();
permissions.add("");
Role newRole = new Role("test", "test.*", null);
roleAuthStrategy.addRole(RoleBasedAuthorizationStrategy.PROJECT, newRole);
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"
}