Search in sources :

Example 6 with PreAuthenticatedAuthenticationToken

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

the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldCreateUserIfDoesNotExist.

@Test
public void authenticate_shouldCreateUserIfDoesNotExist() {
    Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
    PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
    authenticationProvider.authenticate(authenticationToken);
    ArgumentCaptor<com.thoughtworks.go.domain.User> argumentCaptor = ArgumentCaptor.forClass(com.thoughtworks.go.domain.User.class);
    verify(userService).addUserIfDoesNotExist(argumentCaptor.capture());
    com.thoughtworks.go.domain.User user = argumentCaptor.getValue();
    assertThat(user.getName(), is(this.user.getUsername()));
    assertThat(user.getDisplayName(), is(this.user.getDisplayName()));
    assertThat(user.getEmail(), is(this.user.getEmailId()));
}
Also used : User(com.thoughtworks.go.plugin.access.authorization.models.User) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 7 with PreAuthenticatedAuthenticationToken

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

the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldAuthenticateUserAgainstTheSpecifiedPlugin.

@Test
public void authenticate_shouldAuthenticateUserAgainstTheSpecifiedPlugin() {
    Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
    SecurityAuthConfig githubConfig = new SecurityAuthConfig("github", pluginId);
    PluginRoleConfig adminRole = new PluginRoleConfig("admin", "github", new ConfigurationProperty());
    securityConfig.securityAuthConfigs().add(githubConfig);
    securityConfig.addRole(adminRole);
    PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
    authenticationProvider.authenticate(authenticationToken);
    verify(authorizationExtension).authenticateUser(pluginId, credentials, Collections.singletonList(githubConfig), Collections.singletonList(adminRole));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 8 with PreAuthenticatedAuthenticationToken

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

the class PreAuthenticatedRequestsProcessingFilterTest method shouldIgnoreAuthenticationIfUserIsAlreadyAuthenticated.

@Test
public void shouldIgnoreAuthenticationIfUserIsAlreadyAuthenticated() throws IOException, ServletException {
    when(request.getRequestURI()).thenReturn("/go/plugin/github.oauth/authenticate");
    SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken(null, null, null));
    filter.setAuthenticationManager(authenticationManager);
    filter.doFilter(request, response, filterChain);
    verifyZeroInteractions(authenticationManager);
    verify(filterChain).doFilter(request, response);
}
Also used : PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Test(org.junit.Test)

Example 9 with PreAuthenticatedAuthenticationToken

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

the class WebBasedAuthenticationFilterTest method shouldRedirectToHomePageIfAuthenticatedUserTriesToReauthenticate.

@Test
public void shouldRedirectToHomePageIfAuthenticatedUserTriesToReauthenticate() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken(null, null, null));
    when(request.getRequestURI()).thenReturn("/go/plugin/github.oauth/login");
    filter.doFilter(request, response, filterChain);
    verify(response).sendRedirect("/");
    verifyZeroInteractions(authorizationExtension);
    verifyNoMoreInteractions(filterChain);
}
Also used : PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Test(org.junit.Test)

Example 10 with PreAuthenticatedAuthenticationToken

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

the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldAssignRoleBeforeGrantingAnAuthority.

@Test
public void authenticate_shouldAssignRoleBeforeGrantingAnAuthority() {
    final InOrder inOrder = inOrder(pluginRoleService, authorityGranter);
    Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
    PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
    authenticationProvider.authenticate(authenticationToken);
    inOrder.verify(pluginRoleService).updatePluginRoles(pluginId, user.getUsername(), asList(new CaseInsensitiveString("admin")));
    inOrder.verify(authorityGranter).authorities(user.getUsername());
}
Also used : InOrder(org.mockito.InOrder) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) 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