Search in sources :

Example 1 with ProjectMatrixAuthorizationStrategy

use of hudson.security.ProjectMatrixAuthorizationStrategy in project hudson-2.x by hudson.

the class Job method grantProjectMatrixPermissions.

/**
     * Grants project permissions to the user.
     *
     * @param user user
     */
protected void grantProjectMatrixPermissions(User user) {
    if (Hudson.getInstance().getAuthorizationStrategy() instanceof ProjectMatrixAuthorizationStrategy) {
        Map<Permission, Set<String>> grantedPermissions = new HashMap<Permission, Set<String>>();
        Set<String> users = Sets.newHashSet(user.getId());
        grantedPermissions.put(Item.BUILD, users);
        grantedPermissions.put(Item.CONFIGURE, users);
        grantedPermissions.put(Item.DELETE, users);
        grantedPermissions.put(Item.READ, users);
        grantedPermissions.put(Item.WORKSPACE, users);
        grantedPermissions.put(Run.DELETE, users);
        grantedPermissions.put(Run.UPDATE, users);
        AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(grantedPermissions);
        amp.setOwner(this);
        properties.add(amp);
    }
}
Also used : RangeSet(hudson.model.Fingerprint.RangeSet) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Permission(hudson.security.Permission) ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty)

Example 2 with ProjectMatrixAuthorizationStrategy

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

AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)2 Permission (hudson.security.Permission)2 ProjectMatrixAuthorizationStrategy (hudson.security.ProjectMatrixAuthorizationStrategy)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 RangeSet (hudson.model.Fingerprint.RangeSet)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 Test (org.junit.Test)1 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)1