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);
}
}
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");
}
Aggregations