Search in sources :

Example 16 with PreAuthenticatedAuthenticationToken

use of com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken in project gocd by gocd.

the class PreAuthenticatedAuthenticationProvider method doAuthenticate.

private Authentication doAuthenticate(PreAuthenticatedAuthenticationToken preAuthToken) {
    String pluginId = preAuthToken.getPluginId();
    AuthenticationResponse response = null;
    try {
        response = authenticateUser(preAuthToken);
    } catch (Exception e) {
        handleUnSuccessfulAuthentication(preAuthToken);
    }
    if (!isAuthenticated(response)) {
        handleUnSuccessfulAuthentication(preAuthToken);
    }
    validateUser(response.getUser());
    assignRoles(pluginId, response.getUser().getUsername(), response.getRoles());
    UserDetails userDetails = getUserDetails(response.getUser());
    userService.addUserIfDoesNotExist(toDomainUser(response.getUser()));
    PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(userDetails, preAuthToken.getCredentials(), pluginId, userDetails.getAuthorities());
    result.setAuthenticated(true);
    return result;
}
Also used : UserDetails(org.springframework.security.userdetails.UserDetails) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) BadCredentialsException(org.springframework.security.BadCredentialsException) AuthenticationException(org.springframework.security.AuthenticationException)

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