Search in sources :

Example 1 with PreAuthenticatedAuthenticationToken

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;
}
Also used : Authentication(org.springframework.security.Authentication) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken)

Example 2 with PreAuthenticatedAuthenticationToken

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));
}
Also used : InOrder(org.mockito.InOrder) User(com.thoughtworks.go.plugin.access.authorization.models.User) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Arrays.asList(java.util.Arrays.asList) List(java.util.List) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 3 with PreAuthenticatedAuthenticationToken

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);
}
Also used : PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Arrays.asList(java.util.Arrays.asList) List(java.util.List) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Map(java.util.Map) Test(org.junit.Test)

Example 4 with PreAuthenticatedAuthenticationToken

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));
}
Also used : PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Test(org.junit.Test)

Example 5 with PreAuthenticatedAuthenticationToken

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"));
}
Also used : PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

PreAuthenticatedAuthenticationToken (com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken)16 Test (org.junit.Test)14 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)11 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 User (com.thoughtworks.go.plugin.access.authorization.models.User)3 Arrays.asList (java.util.Arrays.asList)3 List (java.util.List)3 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 Map (java.util.Map)2 InOrder (org.mockito.InOrder)2 Authentication (org.springframework.security.Authentication)2 HashMap (java.util.HashMap)1 AuthenticationException (org.springframework.security.AuthenticationException)1 BadCredentialsException (org.springframework.security.BadCredentialsException)1 UserDetails (org.springframework.security.userdetails.UserDetails)1