use of org.springframework.security.Authentication in project gocd by gocd.
the class ReAuthenticationFilterTest method setupAuthentication.
private Authentication setupAuthentication(boolean authenticatedUsingAuthorizationPlugin) {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new GoUserPrinciple("user", "displayName", "password", true, true, true, true, authorities, "loginName"), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class ReAuthenticationFilterTest method shouldContinueWithChainAndReturnIfAuthenticationDoesNotHavePrincipalDefined.
@Test
public void shouldContinueWithChainAndReturnIfAuthenticationDoesNotHavePrincipalDefined() throws IOException, ServletException {
Authentication authentication = new TestingAuthenticationToken(null, null, new GrantedAuthority[] {});
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
when(systemEnvironment.isReAuthenticationEnabled()).thenReturn(true);
when(systemEnvironment.isReAuthenticationEnabled()).thenReturn(true);
filter.doFilterHttp(request, response, filterChain);
verify(filterChain).doFilter(request, response);
verifyNoMoreInteractions(filterChain);
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class RemoveAdminPermissionFilterIntegrationTest method testShouldContinueWithTheChainIfTheSecurityConfigHasNotChanged.
@Test
public void testShouldContinueWithTheChainIfTheSecurityConfigHasNotChanged() throws IOException, ServletException {
Authentication authentication = setupAuthentication();
RemoveAdminPermissionFilter filter = new RemoveAdminPermissionFilter(goConfigService, timeProvider, pluginRoleService);
filter.doFilterHttp(request, response, chain);
modifyArtifactRoot();
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(true));
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class RemoveAdminPermissionFilterIntegrationTest method setupAuthentication.
private Authentication setupAuthentication() {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new User("loser", "secret", true, true, true, true, authorities), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class RemoveAdminPermissionFilterIntegrationTest method testShouldForceReAuthenticationOnRoleConfigChange.
@Test
public void testShouldForceReAuthenticationOnRoleConfigChange() throws Exception {
final ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
final Username username = new Username("bob");
final RoleConfig admin = new RoleConfig(new CaseInsensitiveString("admin"));
final Authentication authentication = setupAuthentication();
final RemoveAdminPermissionFilter filter = new RemoveAdminPermissionFilter(goConfigService, timeProvider, pluginRoleService);
filter.initialize();
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(true));
roleService.create(username, admin, new HttpLocalizedOperationResult());
verify(session).setAttribute(eq(SECURITY_CONFIG_LAST_CHANGE), argumentCaptor.capture());
when(session.getAttribute(SECURITY_CONFIG_LAST_CHANGE)).thenReturn(argumentCaptor.getValue());
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(false));
}
Aggregations