Search in sources :

Example 51 with SecurityAuthConfig

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

the class PreAuthenticatedRequestsProcessingFilterTest method shouldAuthenticateUsersWithCredentials.

@Test
public void shouldAuthenticateUsersWithCredentials() throws IOException, ServletException {
    PreAuthenticatedAuthenticationToken token = mock(PreAuthenticatedAuthenticationToken.class);
    HashMap<String, String[]> params = new HashMap<>();
    params.put("code", new String[] { "some_auth_code" });
    SecurityAuthConfig githubAuthConfig = new SecurityAuthConfig("github", "github.oauth");
    securityConfig.securityAuthConfigs().add(githubAuthConfig);
    when(request.getRequestURI()).thenReturn("/go/plugin/github.oauth/authenticate");
    when(request.getHeaderNames()).thenReturn(Collections.enumeration(Arrays.asList("Authorization")));
    when(request.getHeader("Authorization")).thenReturn("qwe123");
    when(request.getParameterMap()).thenReturn(params);
    when(authorizationExtension.fetchAccessToken("github.oauth", Collections.singletonMap("Authorization", "qwe123"), Collections.singletonMap("code", "some_auth_code"), Collections.singletonList(githubAuthConfig))).thenReturn(Collections.singletonMap("access_token", "token"));
    when(authenticationManager.authenticate(any(PreAuthenticatedAuthenticationToken.class))).thenReturn(token);
    filter.setDefaultTargetUrl("/");
    filter.doFilter(request, response, filterChain);
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    assertThat(authentication, is(token));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HashMap(java.util.HashMap) Authentication(org.springframework.security.Authentication) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Test(org.junit.Test)

Example 52 with SecurityAuthConfig

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

the class AuthorizationMessageConverterV1 method getAuthConfigs.

private List<Map<String, Object>> getAuthConfigs(List<SecurityAuthConfig> authConfigs) {
    List<Map<String, Object>> configs = new ArrayList<>();
    if (authConfigs == null) {
        return configs;
    }
    for (SecurityAuthConfig securityAuthConfig : authConfigs) {
        Map<String, Object> authConfig = new HashedMap();
        authConfig.put("id", securityAuthConfig.getId());
        authConfig.put("configuration", securityAuthConfig.getConfigurationAsMap(true));
        configs.add(authConfig);
    }
    return configs;
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HashedMap(org.apache.commons.collections.map.HashedMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 53 with SecurityAuthConfig

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

the class CurrentUserAccessTokenControllerV1 method createAccessToken.

public String createAccessToken(Request request, Response response) throws Exception {
    String authConfigId = currentUserAuthConfigId(request);
    SecurityAuthConfig authConfig = authConfigService.findProfile(authConfigId);
    if (!extension.supportsPluginAPICallsRequiredForAccessToken(authConfig)) {
        response.status(422);
        return MessageJson.create(String.format("Can not create Access Token. Please upgrade '%s' plugin to use Access Token Feature.", authConfig.getPluginId()));
    }
    final JsonReader reader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    String tokenDescription = reader.optString("description").orElse(null);
    AccessToken created = accessTokenService.create(tokenDescription, currentUsernameString(), currentUserAuthConfigId(request));
    if (!created.persisted()) {
        response.status(422);
    }
    return renderAccessToken(request, response, created);
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) AccessToken(com.thoughtworks.go.domain.AccessToken) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 54 with SecurityAuthConfig

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

the class SecurityAuthConfigControllerV2 method deleteAuthConfig.

public String deleteAuthConfig(Request request, Response response) {
    SecurityAuthConfig securityAuthConfig = fetchEntityFromConfig(request.params("id"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    securityAuthConfigService.delete(currentUsername(), securityAuthConfig, result);
    return handleSimpleMessageResponse(response, result);
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 55 with SecurityAuthConfig

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

the class SecurityAuthConfigControllerV2 method create.

public String create(Request request, Response response) {
    SecurityAuthConfig securityAuthConfig = buildEntityFromRequestBody(request);
    haltIfEntityWithSameIdExists(securityAuthConfig);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    securityAuthConfigService.create(currentUsername(), securityAuthConfig, result);
    return handleCreateOrUpdateResponse(request, response, securityAuthConfig, result);
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Aggregations

SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)81 Test (org.junit.jupiter.api.Test)46 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)28 Test (org.junit.Test)16 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)14 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)14 User (com.thoughtworks.go.plugin.access.authorization.models.User)11 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)9 Username (com.thoughtworks.go.server.domain.Username)9 UserDetails (org.springframework.security.userdetails.UserDetails)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)7 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)5 VerifyConnectionResponse (com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse)5 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)4 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)4 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)4 ValidationResult (com.thoughtworks.go.plugin.domain.common.ValidationResult)4 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)4