Search in sources :

Example 1 with MatrixAuthorizationStrategy

use of org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy in project acceptance-test-harness by jenkinsci.

the class SAMLPluginTest method configureAuthorization.

private void configureAuthorization(GlobalSecurityConfig sc) {
    // Authorization
    MatrixAuthorizationStrategy mas = sc.useAuthorizationStrategy(MatrixAuthorizationStrategy.class);
    // groups coming from the SAML IdP
    // admins
    MatrixRow group1 = mas.addUser("group1");
    group1.admin();
    // readers
    MatrixRow group2 = mas.addUser("group2");
    group2.on(OVERALL_READ);
    // after save the user has no login, so automatic redirect to the auth service
    sc.save();
}
Also used : MatrixRow(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow) MatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)

Example 2 with MatrixAuthorizationStrategy

use of org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy in project acceptance-test-harness by jenkinsci.

the class WarningsPluginTest method configureSecurity.

// TODO: Create a new security mock that can be used by other plugins
private void configureSecurity(final String admin, final String user) {
    GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.configure(() -> {
        MockSecurityRealm realm = security.useRealm(MockSecurityRealm.class);
        realm.configure(admin, user);
        MatrixAuthorizationStrategy mas = security.useAuthorizationStrategy(MatrixAuthorizationStrategy.class);
        mas.addUser(admin).admin();
        mas.addUser(user).developer();
    });
}
Also used : MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) MatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)

Example 3 with MatrixAuthorizationStrategy

use of org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy in project acceptance-test-harness by jenkinsci.

the class ScriptSecurityPluginTest method setUp.

@Before
public void setUp() {
    final GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.open();
    {
        MockSecurityRealm realm = security.useRealm(MockSecurityRealm.class);
        realm.configure(ADMIN, USER);
        MatrixAuthorizationStrategy mas = security.useAuthorizationStrategy(MatrixAuthorizationStrategy.class);
        mas.addUser(ADMIN).admin();
        mas.addUser(USER).developer();
    }
    security.save();
}
Also used : MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) MatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy) Before(org.junit.Before)

Example 4 with MatrixAuthorizationStrategy

use of org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy in project acceptance-test-harness by jenkinsci.

the class MatrixAuthPluginTest method helloWorld.

/**
 * Test scenario:
 *
 * - we create admin user "alice" and regular limited user "bob"
 * - alice creates a new project
 * - bob shouldn't be able to see it
 */
@Test
public void helloWorld() throws Exception {
    GlobalSecurityConfig sc = new GlobalSecurityConfig(jenkins);
    sc.open();
    {
        MockSecurityRealm ms = sc.useRealm(MockSecurityRealm.class);
        ms.configure("alice", "bob");
        MatrixAuthorizationStrategy mas = sc.useAuthorizationStrategy(MatrixAuthorizationStrategy.class);
        MatrixRow a = mas.addUser("alice");
        a.admin();
        MatrixRow bob = mas.addUser("bob");
        bob.on(OVERALL_READ);
    }
    sc.save();
    jenkins.login().doLogin("alice");
    FreeStyleJob j = jenkins.jobs.create();
    j.save();
    jenkins.logout();
    // if we login as Bob, he shouldn't see the job
    jenkins.login().doLogin("bob");
    // check for job's existence
    assertFalse(j.open().getTitle().contains(j.name));
    jenkins.logout();
    // control assertion: alice should see the link
    jenkins.login().doLogin("alice");
    assertTrue(j.open().getTitle().contains(j.name));
}
Also used : MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) MatrixRow(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) MatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy) ProjectBasedMatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectBasedMatrixAuthorizationStrategy) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 5 with MatrixAuthorizationStrategy

use of org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method setUpSecurity.

/**
 * Set up global security. Two users 'admin', with admin permission,
 * and 'user', with permissions necessary to manipulate jobs, will be generated.
 * Script security for Job DSL scripts will be enabled.
 * @return The global security configuration.
 */
private GlobalSecurityConfig setUpSecurity() {
    GlobalSecurityConfig sc = new GlobalSecurityConfig(jenkins);
    sc.configure(() -> {
        MockSecurityRealm ms = sc.useRealm(MockSecurityRealm.class);
        ms.configure(ADMIN, USER);
        MatrixAuthorizationStrategy mas = sc.useAuthorizationStrategy(MatrixAuthorizationStrategy.class);
        MatrixRow a = mas.addUser(ADMIN);
        a.admin();
        MatrixRow b = mas.addUser(USER);
        b.developer();
        sc.setJobDslScriptSecurity(true);
    });
    return sc;
}
Also used : MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) MatrixRow(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) MatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)

Aggregations

MatrixAuthorizationStrategy (org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)6 MockSecurityRealm (org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm)4 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)4 MatrixRow (org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow)3 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)1 ProjectDefaultBuildAccessControl (org.jenkinsci.test.acceptance.plugins.authorize_project.ProjectDefaultBuildAccessControl)1 ProjectBasedMatrixAuthorizationStrategy (org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectBasedMatrixAuthorizationStrategy)1 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)1 Before (org.junit.Before)1 Test (org.junit.Test)1