Search in sources :

Example 1 with AuthorizationMatrixProperty

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

the class FreeStyleProjectTest method testOnCopiedFrom.

@Test
public void testOnCopiedFrom() {
    Hudson hudson = createMock(Hudson.class);
    AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
    expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    User user = createMock(User.class);
    expect(user.getId()).andReturn(USER).times(2);
    mockStatic(User.class);
    expect(User.current()).andReturn(user);
    replayAll();
    MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
    FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
    freeStyleProject.onCopiedFrom(matrixProjectProject);
    verifyAll();
    assertEquals(freeStyleProject.getNextBuildNumber(), 1);
    assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
    assertNotNull(freeStyleProject.getCreationTime());
    assertEquals(freeStyleProject.getCreatedBy(), USER);
    List properties = freeStyleProject.getAllProperties();
    assertEquals(properties.size(), 1);
    AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
    assertEquals(property.getGrantedPermissions().keySet().size(), 7);
    assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
    assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
Also used : ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) List(java.util.List) MatrixProject(hudson.matrix.MatrixProject) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with AuthorizationMatrixProperty

use of hudson.security.AuthorizationMatrixProperty 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 3 with AuthorizationMatrixProperty

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

the class Job method submit.

/**
     * Derived class can override this to perform additional config submission
     * work.
     */
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    JSONObject json = req.getSubmittedForm();
    description = req.getParameter("description");
    keepDependencies = req.getParameter("keepDependencies") != null;
    properties.clear();
    setCascadingProjectName(StringUtils.trimToNull(req.getParameter("cascadingProjectName")));
    CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
    int i = 0;
    for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
        if (!CascadingUtil.isCascadableJobProperty(d)) {
            String name = "jobProperty" + i;
            JSONObject config = json.getJSONObject(name);
            JobProperty prop = d.newInstance(req, config);
            if (null != prop) {
                prop.setOwner(this);
                if (prop instanceof AuthorizationMatrixProperty) {
                    properties.add(prop);
                } else if (prop instanceof ParametersDefinitionProperty) {
                    parameterDefinitionProperties.add(prop);
                }
            }
        } else {
            BaseProjectProperty property = CascadingUtil.getBaseProjectProperty(this, d.getJsonSafeClassName());
            JobProperty prop = d.newInstance(req, json.getJSONObject(d.getJsonSafeClassName()));
            if (null != prop) {
                prop.setOwner(this);
            }
            property.setValue(prop);
            addCascadingJobProperty(property);
        }
        i++;
    }
    setParameterDefinitionProperties(parameterDefinitionProperties);
    LogRotator logRotator = null;
    if (null != req.getParameter("logrotate")) {
        logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
    }
    setLogRotator(logRotator);
}
Also used : BaseProjectProperty(org.hudsonci.model.project.property.BaseProjectProperty) JSONObject(net.sf.json.JSONObject) LogRotator(hudson.tasks.LogRotator) CopyOnWriteList(hudson.util.CopyOnWriteList) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) ExtensionPoint(hudson.ExtensionPoint)

Example 4 with AuthorizationMatrixProperty

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

the class Job method convertCascadingJobProperties.

/**
     * Method converts JobProperties to cascading values.
     * <p/>
     * If property is {@link AuthorizationMatrixProperty} - it will be skipped.
     * If property is {@link ParametersDefinitionProperty} - it will be added to list of parameterDefinition properties.
     * All the rest properties will be converted to {@link BaseProjectProperty} classes and added
     * to cascadingJobProperties set.
     *
     * @param properties list of {@link JobProperty}
     */
private void convertCascadingJobProperties(CopyOnWriteList<JobProperty<? super JobT>> properties) {
    CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
    for (JobProperty property : properties) {
        if (property instanceof AuthorizationMatrixProperty) {
            continue;
        }
        if (property instanceof ParametersDefinitionProperty) {
            parameterDefinitionProperties.add(property);
            continue;
        }
        BaseProjectProperty projectProperty = CascadingUtil.getBaseProjectProperty(this, property.getDescriptor().getJsonSafeClassName());
        addCascadingJobProperty(projectProperty);
    }
    if (null == getProperty(PARAMETERS_DEFINITION_JOB_PROPERTY_PROPERTY_NAME)) {
        setParameterDefinitionProperties(parameterDefinitionProperties);
    }
}
Also used : BaseProjectProperty(org.hudsonci.model.project.property.BaseProjectProperty) CopyOnWriteList(hudson.util.CopyOnWriteList) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty)

Example 5 with AuthorizationMatrixProperty

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

the class FreeStyleProjectTest method testOnCreatedFromScratch.

@Test
public void testOnCreatedFromScratch() {
    Hudson hudson = createMock(Hudson.class);
    AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
    expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    User user = createMock(User.class);
    expect(user.getId()).andReturn(USER).times(2);
    mockStatic(User.class);
    expect(User.current()).andReturn(user);
    replayAll();
    FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
    freeStyleProject.onCreatedFromScratch();
    verifyAll();
    assertNotNull(freeStyleProject.getCreationTime());
    assertEquals(freeStyleProject.getCreatedBy(), USER);
    List properties = freeStyleProject.getAllProperties();
    assertEquals(properties.size(), 1);
    AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
    assertEquals(property.getGrantedPermissions().keySet().size(), 7);
    assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
    assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
Also used : ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) List(java.util.List) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)6 ProjectMatrixAuthorizationStrategy (hudson.security.ProjectMatrixAuthorizationStrategy)4 Test (org.junit.Test)3 AuthorizationStrategy (hudson.security.AuthorizationStrategy)2 GlobalMatrixAuthorizationStrategy (hudson.security.GlobalMatrixAuthorizationStrategy)2 Permission (hudson.security.Permission)2 CopyOnWriteList (hudson.util.CopyOnWriteList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Set (java.util.Set)2 BaseProjectProperty (org.hudsonci.model.project.property.BaseProjectProperty)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ExtensionPoint (hudson.ExtensionPoint)1 MatrixProject (hudson.matrix.MatrixProject)1 RangeSet (hudson.model.Fingerprint.RangeSet)1 FreeStyleProject (hudson.model.FreeStyleProject)1 LogRotator (hudson.tasks.LogRotator)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 JSONObject (net.sf.json.JSONObject)1