use of com.michelin.cio.hudson.plugins.rolestrategy.RoleMap in project configuration-as-code-plugin by jenkinsci.
the class RoleBasedAuthorizationStrategyConfigurator method retrieveRoleMap.
@Nonnull
private static RoleMap retrieveRoleMap(@Nonnull Object config, @Nonnull String name, Configurator<RoleDefinition> configurator) throws Exception {
Map map = (Map) config;
final Collection<?> c = (Collection<?>) map.get(name);
TreeMap<Role, Set<String>> resMap = new TreeMap<>();
if (c == null) {
// we cannot return emptyMap here due to the Role Strategy code
return new RoleMap(resMap);
}
for (Object entry : c) {
RoleDefinition definition = configurator.configure(entry);
resMap.put(definition.getRole(), definition.getAssignments());
}
return new RoleMap(resMap);
}
use of com.michelin.cio.hudson.plugins.rolestrategy.RoleMap in project configuration-as-code-plugin by jenkinsci.
the class RoleBasedAuthorizationStrategyConfigurator method configure.
@Override
public RoleBasedAuthorizationStrategy configure(Object config) throws Exception {
// TODO: API should return a qualified type
final Configurator<RoleDefinition> roleDefinitionConfigurator = (Configurator<RoleDefinition>) Configurator.lookup(RoleDefinition.class);
if (roleDefinitionConfigurator == null) {
throw new IOException("Cannot find configurator for" + RoleDefinition.class);
}
Map map = (Map) config;
Map<String, RoleMap> grantedRoles = new HashMap<>();
Object rolesConfig = map.get("roles");
if (rolesConfig != null) {
grantedRoles.put(RoleBasedAuthorizationStrategy.GLOBAL, retrieveRoleMap(rolesConfig, "global", roleDefinitionConfigurator));
grantedRoles.put(RoleBasedAuthorizationStrategy.PROJECT, retrieveRoleMap(rolesConfig, "items", roleDefinitionConfigurator));
grantedRoles.put(RoleBasedAuthorizationStrategy.SLAVE, retrieveRoleMap(rolesConfig, "agents", roleDefinitionConfigurator));
}
return new RoleBasedAuthorizationStrategy(grantedRoles);
}
Aggregations