use of org.springframework.security.providers.TestingAuthenticationToken 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.providers.TestingAuthenticationToken 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.providers.TestingAuthenticationToken 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.providers.TestingAuthenticationToken in project gocd by gocd.
the class UserHelperTest method shouldReturnFalseWhenCheckIsAgentIfGrantedAuthorityNotContainsAgentRole.
@Test
public void shouldReturnFalseWhenCheckIsAgentIfGrantedAuthorityNotContainsAgentRole() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(null, null, new GrantedAuthorityImpl[] { new GrantedAuthorityImpl("anything") });
assertThat(UserHelper.matchesRole(authentication, X509AuthoritiesPopulator.ROLE_AGENT), is(false));
}
use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.
the class GoVelocityViewTest method shouldSetAdministratorIfUserIsAdministrator.
@Test
public void shouldSetAdministratorIfUserIsAdministrator() throws Exception {
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_SUPERVISOR.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.ADMINISTRATOR), is(true));
}
Aggregations