Search in sources :

Example 1 with Permission

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());
}
Also used : Permission(hudson.security.Permission) Initializer(hudson.init.Initializer)

Example 2 with Permission

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;
}
Also used : Field(java.lang.reflect.Field) Permission(hudson.security.Permission) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy)

Example 3 with Permission

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));
        }
    }
}
Also used : Permission(hudson.security.Permission)

Example 4 with 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;
        }
    };
}
Also used : Authentication(org.acegisecurity.Authentication) Permission(hudson.security.Permission) ACL(hudson.security.ACL)

Example 5 with Permission

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

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