Search in sources :

Example 1 with Configurator

use of org.jenkinsci.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.

the class ProjectMatrixAuthorizationTest method shouldReturnCustomConfigurator.

@Test
public void shouldReturnCustomConfigurator() {
    Configurator configurator = Configurator.lookup(ProjectMatrixAuthorizationStrategy.class);
    assertNotNull("Failed to find configurator for GlobalMatrixAuthorizationStrategy", configurator);
    assertEquals("Retrieved wrong configurator", ProjectMatrixAuthorizationStrategyConfigurator.class, configurator.getClass());
}
Also used : ProjectMatrixAuthorizationStrategyConfigurator(org.jenkinsci.plugins.casc.integrations.projectmatriaxauth.ProjectMatrixAuthorizationStrategyConfigurator) Configurator(org.jenkinsci.plugins.casc.Configurator) Test(org.junit.Test)

Example 2 with Configurator

use of org.jenkinsci.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.

the class RoleBasedAuthorizationStrategyConfigurator method configure.

@Override
public RoleBasedAuthorizationStrategy configure(Object config) throws Exception {
    // TODO: API should return a qualified type
    final Configurator<RoleDefinition> roleDefinitionConfigurator = (Configurator<RoleDefinition>) Configurator.lookup(RoleDefinition.class);
    if (roleDefinitionConfigurator == null) {
        throw new IOException("Cannot find configurator for" + RoleDefinition.class);
    }
    Map map = (Map) config;
    Map<String, RoleMap> grantedRoles = new HashMap<>();
    Object rolesConfig = map.get("roles");
    if (rolesConfig != null) {
        grantedRoles.put(RoleBasedAuthorizationStrategy.GLOBAL, retrieveRoleMap(rolesConfig, "global", roleDefinitionConfigurator));
        grantedRoles.put(RoleBasedAuthorizationStrategy.PROJECT, retrieveRoleMap(rolesConfig, "items", roleDefinitionConfigurator));
        grantedRoles.put(RoleBasedAuthorizationStrategy.SLAVE, retrieveRoleMap(rolesConfig, "agents", roleDefinitionConfigurator));
    }
    return new RoleBasedAuthorizationStrategy(grantedRoles);
}
Also used : HashMap(java.util.HashMap) Configurator(org.jenkinsci.plugins.casc.Configurator) RootElementConfigurator(org.jenkinsci.plugins.casc.RootElementConfigurator) IOException(java.io.IOException) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) RoleMap(com.michelin.cio.hudson.plugins.rolestrategy.RoleMap) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) RoleMap(com.michelin.cio.hudson.plugins.rolestrategy.RoleMap)

Example 3 with Configurator

use of org.jenkinsci.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.

the class GlobalMatrixAuthorizationTest method shouldReturnCustomConfigurator.

@Test
public void shouldReturnCustomConfigurator() {
    Configurator configurator = Configurator.lookup(GlobalMatrixAuthorizationStrategy.class);
    assertNotNull("Failed to find configurator for GlobalMatrixAuthorizationStrategy", configurator);
    assertEquals("Retrieved wrong configurator", GlobalMatrixAuthorizationStrategyConfigurator.class, configurator.getClass());
}
Also used : Configurator(org.jenkinsci.plugins.casc.Configurator) Test(org.junit.Test)

Example 4 with Configurator

use of org.jenkinsci.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.

the class GlobalMatrixAuthorizationTest method shouldReturnCustomConfiguratorForBaseType.

@Test
public void shouldReturnCustomConfiguratorForBaseType() {
    Configurator c = Configurator.lookupForBaseType(AuthorizationStrategy.class, "globalMatrix");
    assertNotNull("Failed to find configurator for GlobalMatrixAuthorizationStrategy", c);
    assertEquals("Retrieved wrong configurator", GlobalMatrixAuthorizationStrategyConfigurator.class, c.getClass());
    Configurator.lookup(GlobalMatrixAuthorizationStrategy.class);
}
Also used : Configurator(org.jenkinsci.plugins.casc.Configurator) Test(org.junit.Test)

Example 5 with Configurator

use of org.jenkinsci.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.

the class ProjectMatrixAuthorizationTest method shouldReturnCustomConfiguratorForBaseType.

@Test
public void shouldReturnCustomConfiguratorForBaseType() {
    Configurator c = Configurator.lookupForBaseType(AuthorizationStrategy.class, "projectMatrix");
    assertNotNull("Failed to find configurator for ProjectMatrixAuthorizationStrategy", c);
    assertEquals("Retrieved wrong configurator", ProjectMatrixAuthorizationStrategyConfigurator.class, c.getClass());
    Configurator.lookup(ProjectMatrixAuthorizationStrategy.class);
}
Also used : ProjectMatrixAuthorizationStrategyConfigurator(org.jenkinsci.plugins.casc.integrations.projectmatriaxauth.ProjectMatrixAuthorizationStrategyConfigurator) Configurator(org.jenkinsci.plugins.casc.Configurator) Test(org.junit.Test)

Aggregations

Configurator (org.jenkinsci.plugins.casc.Configurator)7 Test (org.junit.Test)6 ProjectMatrixAuthorizationStrategyConfigurator (org.jenkinsci.plugins.casc.integrations.projectmatriaxauth.ProjectMatrixAuthorizationStrategyConfigurator)2 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)1 RoleMap (com.michelin.cio.hudson.plugins.rolestrategy.RoleMap)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 RootElementConfigurator (org.jenkinsci.plugins.casc.RootElementConfigurator)1 Issue (org.jvnet.hudson.test.Issue)1