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