Search in sources :

Example 1 with AuthorizationStrategy

use of hudson.security.AuthorizationStrategy 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 AuthorizationStrategy

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

the class FreeStyleProjectTest method testOnCreatedFromScratchGlobalMatrixAuthorizationStrategy.

@Test
public void testOnCreatedFromScratchGlobalMatrixAuthorizationStrategy() {
    Hudson hudson = createMock(Hudson.class);
    AuthorizationStrategy authorizationStrategy = createMock(GlobalMatrixAuthorizationStrategy.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(1);
    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(), 0);
}
Also used : ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) List(java.util.List) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with AuthorizationStrategy

use of hudson.security.AuthorizationStrategy in project blueocean-plugin by jenkinsci.

the class BlueOceanConfigStatePreloader method getStateJson.

/**
     * {@inheritDoc}
     */
@Override
public String getStateJson() {
    StringWriter writer = new StringWriter();
    Jenkins jenkins = Jenkins.getInstance();
    String version = Jenkins.getVersion() != null ? Jenkins.getVersion().toString() : Jenkins.VERSION;
    AuthorizationStrategy authorizationStrategy = jenkins.getAuthorizationStrategy();
    boolean allowAnonymousRead = true;
    if (authorizationStrategy instanceof FullControlOnceLoggedInAuthorizationStrategy) {
        allowAnonymousRead = ((FullControlOnceLoggedInAuthorizationStrategy) authorizationStrategy).isAllowAnonymousRead();
    }
    new JSONBuilder(writer).object().key("version").value(getBlueOceanPluginVersion()).key("jenkinsConfig").object().key("version").value(version).key("security").object().key("enabled").value(jenkins.isUseSecurity()).key("loginUrl").value(jenkins.getSecurityRealm() == SecurityRealm.NO_AUTHENTICATION ? null : jenkins.getSecurityRealm().getLoginUrl()).key("authorizationStrategy").object().key("allowAnonymousRead").value(allowAnonymousRead).endObject().key("enableJWT").value(BlueOceanConfigProperties.BLUEOCEAN_FEATURE_JWT_AUTHENTICATION).endObject().endObject().key("features").object().key("organizations.enabled").value(Boolean.getBoolean("blueocean.features.organizations.enabled")).endObject().endObject();
    return writer.toString();
}
Also used : Jenkins(jenkins.model.Jenkins) AuthorizationStrategy(hudson.security.AuthorizationStrategy) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) JSONBuilder(net.sf.json.util.JSONBuilder) StringWriter(java.io.StringWriter)

Example 4 with AuthorizationStrategy

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

the class FreeStyleProjectTest method testOnCopiedFromGlobalMatrixAuthorizationStrategy.

@Test
public void testOnCopiedFromGlobalMatrixAuthorizationStrategy() {
    Hudson hudson = createMock(Hudson.class);
    AuthorizationStrategy authorizationStrategy = createMock(GlobalMatrixAuthorizationStrategy.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(1);
    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);
    assertEquals(freeStyleProject.getAllProperties().size(), 0);
}
Also used : ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) MatrixProject(hudson.matrix.MatrixProject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with AuthorizationStrategy

use of hudson.security.AuthorizationStrategy 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

AuthorizationStrategy (hudson.security.AuthorizationStrategy)5 GlobalMatrixAuthorizationStrategy (hudson.security.GlobalMatrixAuthorizationStrategy)4 ProjectMatrixAuthorizationStrategy (hudson.security.ProjectMatrixAuthorizationStrategy)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 List (java.util.List)3 MatrixProject (hudson.matrix.MatrixProject)2 AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)2 FullControlOnceLoggedInAuthorizationStrategy (hudson.security.FullControlOnceLoggedInAuthorizationStrategy)1 StringWriter (java.io.StringWriter)1 Jenkins (jenkins.model.Jenkins)1 JSONBuilder (net.sf.json.util.JSONBuilder)1