use of com.thoughtworks.go.server.newsecurity.models.AccessToken in project gocd by gocd.
the class WebBasedPluginAuthenticationProviderTest method shouldFetchAccessTokenFromPlugin.
@Test
void shouldFetchAccessTokenFromPlugin() {
when(authorizationExtension.fetchAccessToken(PLUGIN_ID, emptyMap(), singletonMap("code", "some-code"), singletonList(githubSecurityAuthconfig))).thenReturn(singletonMap("access_token", "some-access-token"));
final AccessToken accessToken = authenticationProvider.fetchAccessToken(PLUGIN_ID, emptyMap(), singletonMap("code", "some-code"));
assertThat(accessToken.getCredentials()).containsEntry("access_token", "some-access-token").hasSize(1);
}
use of com.thoughtworks.go.server.newsecurity.models.AccessToken in project gocd by gocd.
the class AuthenticationController method authenticateWithWebBasedPlugin.
@RequestMapping(value = "/plugin/{pluginId}/authenticate")
public RedirectView authenticateWithWebBasedPlugin(@PathVariable("pluginId") String pluginId, HttpServletRequest request) {
if (securityIsDisabledOrAlreadyLoggedIn(request)) {
return new RedirectView("/pipelines", true);
}
LOGGER.debug("Requesting authentication for form auth.");
SavedRequest savedRequest = SessionUtils.savedRequest(request);
try {
final AccessToken accessToken = webBasedPluginAuthenticationProvider.fetchAccessToken(pluginId, getRequestHeaders(request), getParameterMap(request));
AuthenticationToken<AccessToken> authenticationToken = webBasedPluginAuthenticationProvider.authenticate(accessToken, pluginId);
if (authenticationToken == null) {
return unknownAuthenticationError(request);
}
SessionUtils.setAuthenticationTokenAfterRecreatingSession(authenticationToken, request);
} catch (AuthenticationException e) {
LOGGER.error("Failed to authenticate user.", e);
return badAuthentication(request, e.getMessage());
} catch (Exception e) {
return unknownAuthenticationError(request);
}
SessionUtils.removeAuthenticationError(request);
String redirectUrl = savedRequest == null ? "/go/pipelines" : savedRequest.getRedirectUrl();
return new RedirectView(redirectUrl, false);
}
Aggregations