Search in sources :

Example 11 with TestingAuthenticationToken

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;
}
Also used : Authentication(org.springframework.security.Authentication) GrantedAuthority(org.springframework.security.GrantedAuthority) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken)

Example 12 with TestingAuthenticationToken

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);
}
Also used : Authentication(org.springframework.security.Authentication) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 13 with TestingAuthenticationToken

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;
}
Also used : User(org.springframework.security.userdetails.User) Authentication(org.springframework.security.Authentication) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken)

Example 14 with TestingAuthenticationToken

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));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 15 with TestingAuthenticationToken

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));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)17 Test (org.junit.Test)14 GrantedAuthority (org.springframework.security.GrantedAuthority)10 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)9 Authentication (org.springframework.security.Authentication)4 User (org.springframework.security.userdetails.User)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 LdapUserDetailsImpl (org.springframework.security.userdetails.ldap.LdapUserDetailsImpl)3 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 Username (com.thoughtworks.go.server.domain.Username)1