Search in sources :

Example 6 with PluginRoleConfig

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

the class RoleConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.

@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
    PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
    cruiseConfig.server().security().getRoles().add(oldRole);
    EntityHashingService entityHashingService = mock(EntityHashingService.class);
    when(entityHashingService.md5ForEntity(oldRole)).thenReturn("md5");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    RoleConfigCommand command = new RoleConfigUpdateCommand(goConfigService, updatedRole, null, currentUser, result, entityHashingService, "bad-md5");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 7 with PluginRoleConfig

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

the class RoleConfigUpdateCommandTest method shouldUpdateExistingRole.

@Test
public void shouldUpdateExistingRole() throws Exception {
    PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
    PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
    cruiseConfig.server().security().getRoles().add(oldRole);
    RoleConfigCommand command = new RoleConfigUpdateCommand(null, updatedRole, null, null, null, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("foo")), is(equalTo(updatedRole)));
}
Also used : PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 8 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 9 with PluginRoleConfig

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

the class PluginAuthenticationProviderTest method shouldCreateGoUserPrincipalWhenAnAuthorizationPluginIsAbleToAuthenticateUser.

@Test
public void shouldCreateGoUserPrincipalWhenAnAuthorizationPluginIsAbleToAuthenticateUser() {
    String pluginId1 = "plugin-id-1";
    String pluginId2 = "plugin-id-2";
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", pluginId2));
    securityConfig.addRole(new PluginRoleConfig("admin", "github", ConfigurationPropertyMother.create("foo")));
    when(store.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId1, pluginId2)));
    when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), null)).thenReturn(NULL_AUTH_RESPONSE);
    AuthenticationResponse response = new AuthenticationResponse(new User("username", "display-name", "test@test.com"), Collections.emptyList());
    when(authorizationExtension.authenticateUser(pluginId2, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId2), securityConfig.getPluginRoles(pluginId2))).thenReturn(response);
    UserDetails userDetails = provider.retrieveUser("username", authenticationToken);
    assertThat(userDetails, is(instanceOf(GoUserPrinciple.class)));
    GoUserPrinciple goUserPrincipal = (GoUserPrinciple) userDetails;
    assertThat(goUserPrincipal.getUsername(), is("username"));
    assertThat(goUserPrincipal.getDisplayName(), is("display-name"));
    assertThat(goUserPrincipal.getAuthorities().length, is(1));
    assertThat(goUserPrincipal.getAuthorities()[0], is(userAuthority));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) User(com.thoughtworks.go.plugin.access.authentication.models.User) UserDetails(org.springframework.security.userdetails.UserDetails) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Example 10 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)

Aggregations

PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)11 Test (org.junit.Test)8 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 User (com.thoughtworks.go.plugin.access.authentication.models.User)3 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 HashedMap (org.apache.commons.collections.map.HashedMap)2 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)1 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)1 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)1 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 EntityHashingService (com.thoughtworks.go.server.service.EntityHashingService)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 Authentication (org.springframework.security.Authentication)1 UserDetails (org.springframework.security.userdetails.UserDetails)1