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()));
}
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));
}
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);
}
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);
}
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());
}
Aggregations