Search in sources :

Example 1 with GroupPermissionDefinition

use of org.jenkinsci.plugins.casc.integrations.globalmatrixauth.GroupPermissionDefinition in project configuration-as-code-plugin by jenkinsci.

the class ProjectMatrixAuthorizationStrategyConfigurator method configure.

@Override
public ProjectMatrixAuthorizationStrategy configure(Object config) throws Exception {
    Map map = (Map) config;
    Collection o = (Collection<?>) map.get("grantedPermissions");
    Configurator<GroupPermissionDefinition> permissionConfigurator = Configurator.lookup(GroupPermissionDefinition.class);
    Map<Permission, Set<String>> grantedPermissions = new HashMap<>();
    for (Object entry : o) {
        GroupPermissionDefinition gpd = permissionConfigurator.configure(entry);
        // We transform the linear list to a matrix (Where permission is the key instead)
        gpd.grantPermission(grantedPermissions);
    }
    ProjectMatrixAuthorizationStrategy gms = new ProjectMatrixAuthorizationStrategy();
    for (Map.Entry<Permission, Set<String>> permission : grantedPermissions.entrySet()) {
        for (String sid : permission.getValue()) {
            gms.add(permission.getKey(), sid);
        }
    }
    return gms;
}
Also used : GroupPermissionDefinition(org.jenkinsci.plugins.casc.integrations.globalmatrixauth.GroupPermissionDefinition) Permission(hudson.security.Permission) ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy)

Aggregations

Permission (hudson.security.Permission)1 ProjectMatrixAuthorizationStrategy (hudson.security.ProjectMatrixAuthorizationStrategy)1 GroupPermissionDefinition (org.jenkinsci.plugins.casc.integrations.globalmatrixauth.GroupPermissionDefinition)1