use of hudson.security.Permission in project workflow-cps-plugin by jenkinsci.
the class ReplayActionTest method assertPermissionId.
// same time as Jenkins global config is loaded (e.g., AuthorizationStrategy)
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED, before = InitMilestone.JOB_LOADED)
public static void assertPermissionId() {
String thePermissionId = "hudson.model.Run.Replay";
// An AuthorizationStrategy may be loading a permission by name during Jenkins startup.
Permission thePermission = Permission.fromId(thePermissionId);
// Make sure it finds this addition, even though the PermissionGroup is in core.
assertEquals(ReplayAction.REPLAY, thePermission);
assertEquals(thePermissionId, thePermission.getId());
}
use of hudson.security.Permission in project configuration-as-code-plugin by jenkinsci.
the class GlobalMatrixAuthorizationStrategyConfigurator method configure.
@Override
public GlobalMatrixAuthorizationStrategy 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);
}
// TODO: Once change is in place for GlobalMatrixAuthentication. Switch away from reflection
GlobalMatrixAuthorizationStrategy gms = new GlobalMatrixAuthorizationStrategy();
Field f = gms.getClass().getDeclaredField("grantedPermissions");
f.setAccessible(true);
f.set(gms, grantedPermissions);
return gms;
}
use of hudson.security.Permission in project configuration-as-code-plugin by jenkinsci.
the class GroupPermissionDefinition method grantPermission.
public void grantPermission(Map<Permission, Set<String>> grantedPermissions) {
for (String permission : permissions) {
// Permission pm = Permission.fromId(permission);
Permission pm = PermissionFinder.findPermission(permission);
if (pm != null) {
if (grantedPermissions.containsKey(pm)) {
grantedPermissions.get(pm).add(name);
} else {
HashSet<String> s = new HashSet<>();
s.add(name);
grantedPermissions.put(pm, s);
}
} else {
LOGGER.warning(String.format("Ignoring unknown permission with id: '%s'", permission));
}
}
}
use of hudson.security.Permission in project selenium_java by sergueik.
the class AuditReportsAuthorizationStrategy method getRootACL.
@Override
public ACL getRootACL() {
return new ACL() {
@Override
public boolean hasPermission(final Authentication auth, final Permission requestedPermission) {
final String requestedUser = auth.getName();
final ACL originalACL = template.getRootACL();
boolean retval = originalACL.hasPermission(auth, requestedPermission);
if (retval) {
if (0 == Permission.ID_COMPARATOR.compare(requestedPermission, AuditReportsAuthorizationStrategy.this.permission)) {
retval = retval && requestedUser.equalsIgnoreCase(AuditReportsAuthorizationStrategy.this.user);
}
}
return retval;
}
};
}
use of hudson.security.Permission 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);
}
}
Aggregations