use of com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken in project gocd by gocd.
the class PreAuthenticatedRequestsProcessingFilter method attemptAuthentication.
@Override
public Authentication attemptAuthentication(HttpServletRequest request) throws AuthenticationException {
PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(null, fetchAuthorizationServerAccessToken(request), pluginId(request));
Authentication authResult = this.getAuthenticationManager().authenticate(authRequest);
return authResult;
}
use of com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldPerformOperationInSequence.
@Test
public void authenticate_shouldPerformOperationInSequence() {
final InOrder inOrder = inOrder(authorizationExtension, pluginRoleService, authorityGranter, userService);
Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
authenticationProvider.authenticate(authenticationToken);
inOrder.verify(authorizationExtension).authenticateUser(eq(pluginId), eq(credentials), any(List.class), any(List.class));
inOrder.verify(pluginRoleService).updatePluginRoles(pluginId, user.getUsername(), asList(new CaseInsensitiveString("admin")));
inOrder.verify(authorityGranter).authorities(user.getUsername());
inOrder.verify(userService).addUserIfDoesNotExist(any(com.thoughtworks.go.domain.User.class));
}
use of com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldHandleFailedAuthentication.
@Test
public void authenticate_shouldHandleFailedAuthentication() {
PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, Collections.singletonMap("access_token", "invalid_token"), pluginId);
AuthenticationResponse authenticationResponse = new AuthenticationResponse(null, null);
when(authorizationExtension.authenticateUser(any(String.class), any(Map.class), any(List.class), any(List.class))).thenReturn(authenticationResponse);
thrown.expect(BadCredentialsException.class);
thrown.expectMessage("Unable to authenticate user using the external access token.");
authenticationProvider.authenticate(authenticationToken);
}
use of com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldErrorOutInAbsenceOfCredentials.
@Test
public void authenticate_shouldErrorOutInAbsenceOfCredentials() {
thrown.expect(BadCredentialsException.class);
thrown.expectMessage("No pre-authenticated credentials found in request.");
authenticationProvider.authenticate(new PreAuthenticatedAuthenticationToken(null, null, null));
}
use of com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldAssignRolesToUser.
@Test
public void authenticate_shouldAssignRolesToUser() {
Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
authenticationProvider.authenticate(authenticationToken);
verify(pluginRoleService).updatePluginRoles(pluginId, user.getUsername(), CaseInsensitiveString.caseInsensitiveStrings("admin"));
}
Aggregations