Search in sources :

Example 11 with Permission

use of hudson.security.Permission 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)

Example 12 with Permission

use of hudson.security.Permission in project promoted-builds-plugin by jenkinsci.

the class RemoteApiTest method acl.

@Test
public void acl() throws Exception {
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    ProjectMatrixAuthorizationStrategy pmas = new ProjectMatrixAuthorizationStrategy();
    r.jenkins.setAuthorizationStrategy(pmas);
    pmas.add(Jenkins.READ, "anonymous");
    FreeStyleProject p = r.createFreeStyleProject("p");
    Map<Permission, Set<String>> perms = new HashMap<Permission, Set<String>>();
    perms.put(Item.READ, Collections.singleton("alice"));
    perms.put(Item.CONFIGURE, Collections.singleton("alice"));
    perms.put(Item.DISCOVER, Collections.singleton("bob"));
    p.addProperty(new AuthorizationMatrixProperty(perms));
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    promotion.addProcess("promo").save();
    JenkinsRule.WebClient wc = r.createWebClient();
    wc.assertFails("job/p/promotion/process/promo/config.xml", HttpURLConnection.HTTP_NOT_FOUND);
    wc.login("bob");
    wc.assertFails("job/p/promotion/process/promo/config.xml", HttpURLConnection.HTTP_FORBIDDEN);
    wc.login("alice");
    wc.goToXml("job/p/config.xml");
    wc.goToXml("job/p/promotion/process/promo/config.xml");
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) Permission(hudson.security.Permission) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) FreeStyleProject(hudson.model.FreeStyleProject) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) Test(org.junit.Test)

Aggregations

Permission (hudson.security.Permission)12 ACL (hudson.security.ACL)5 Authentication (org.acegisecurity.Authentication)5 Test (org.junit.Test)4 ProjectMatrixAuthorizationStrategy (hudson.security.ProjectMatrixAuthorizationStrategy)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ExtensionList (hudson.ExtensionList)2 AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)2 BlueUserPermission (io.jenkins.blueocean.rest.model.BlueUserPermission)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 StaplerRequest (org.kohsuke.stapler.StaplerRequest)2 Initializer (hudson.init.Initializer)1 RangeSet (hudson.model.Fingerprint.RangeSet)1 FreeStyleProject (hudson.model.FreeStyleProject)1 User (hudson.model.User)1 GlobalMatrixAuthorizationStrategy (hudson.security.GlobalMatrixAuthorizationStrategy)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 Link (io.jenkins.blueocean.rest.hal.Link)1