Search in sources :

Example 21 with PluginRoleConfig

use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.

the class RoleConfigCreateCommandTest method update_shouldAddPluginRoleConfigToRoles.

@Test
public void update_shouldAddPluginRoleConfigToRoles() throws Exception {
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    PluginRoleConfig role = new PluginRoleConfig("blackbird", "ldap");
    RoleConfigCreateCommand command = new RoleConfigCreateCommand(null, role, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("blackbird")), equalTo(role));
}
Also used : BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 22 with PluginRoleConfig

use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.

the class RoleConfigUpdateCommandTest method shouldNotContinueIfExistingRoleIsDeleted.

@Test
public void shouldNotContinueIfExistingRoleIsDeleted() throws Exception {
    PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    RoleConfigCommand command = new RoleConfigUpdateCommand(goConfigService, updatedRole, null, currentUser, result, entityHashingService, "bad-md5");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertFalse(result.isSuccessful());
    assertThat(result.httpCode(), is(404));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 23 with PluginRoleConfig

use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.

the class SecurityAuthConfigDeleteCommandTest method shouldNotValidateIfProfileIsInUseByRole.

@Test
public void shouldNotValidateIfProfileIsInUseByRole() throws Exception {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
    cruiseConfig.server().security().addRole(new PluginRoleConfig("blackbird", "foo"));
    SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
    thrown.expect(GoConfigInvalidException.class);
    thrown.expectMessage("The security auth config 'foo' is being referenced by role(s): blackbird.");
    command.isValid(cruiseConfig);
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 24 with PluginRoleConfig

use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.

the class AuthorizationMessageConverterV1 method getProcessRoleConfigsResponseBody.

@Override
public String getProcessRoleConfigsResponseBody(List<PluginRoleConfig> roles) {
    List<Map> list = new ArrayList<>();
    for (PluginRoleConfig role : roles) {
        LinkedHashMap<String, Object> e = new LinkedHashMap<>();
        e.put("name", role.getName().toString());
        e.put("configuration", role.getConfigurationAsMap(true));
        list.add(e);
    }
    return GSON.toJson(list);
}
Also used : PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 25 with PluginRoleConfig

use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.

the class RoleConfigurationValidatorTest method shouldAddConfigurationAndMapErrorsInAbsenceOfConfiguration.

@Test
public void shouldAddConfigurationAndMapErrorsInAbsenceOfConfiguration() throws Exception {
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("view"));
    PluginRoleConfig roleConfig = new PluginRoleConfig("admin", "auth_id", property);
    ValidationResult result = new ValidationResult();
    result.addError(new ValidationError("password", "password is required"));
    when(extension.validateRoleConfiguration("pluginId", Collections.singletonMap("username", "view"))).thenReturn(result);
    validator.validate(roleConfig, "pluginId");
    assertTrue(roleConfig.hasErrors());
    assertThat(roleConfig.getProperty("password").errors().get("password").get(0), is("password is required"));
    assertNull(roleConfig.getProperty("password").getValue());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Aggregations

PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)26 Test (org.junit.Test)22 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)8 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)6 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4 User (com.thoughtworks.go.plugin.access.authorization.models.User)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)2 Users (com.thoughtworks.go.config.security.users.Users)2 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)2 PreAuthenticatedAuthenticationToken (com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 HashedMap (org.apache.commons.collections.map.HashedMap)2 UserDetails (org.springframework.security.userdetails.UserDetails)2