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));
}
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;
}
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);
}
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);
}
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);
}
Aggregations