Search in sources :

Example 16 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class GoVelocityViewTest method shouldSetGroupAdministratorIfUserIsAPipelineGroupAdministrator.

@Test
public void shouldSetGroupAdministratorIfUserIsAPipelineGroupAdministrator() throws Exception {
    securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_GROUP_SUPERVISOR.toString()) }));
    request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
    view.exposeHelpers(velocityContext, request);
    assertThat(velocityContext.get(GoVelocityView.ADMINISTRATOR), is(nullValue()));
    assertThat(velocityContext.get(GoVelocityView.GROUP_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)

Example 17 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class GoVelocityViewTest method principalIsTheUsernameWhenNothingElseAvailable.

@Test
public void principalIsTheUsernameWhenNothingElseAvailable() throws Exception {
    request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
    securityContext.setAuthentication(new TestingAuthenticationToken(new User("Test User", "pwd", true, new GrantedAuthority[] { new GrantedAuthorityImpl("nowt") }), null, null));
    view.exposeHelpers(velocityContext, request);
    assertThat(velocityContext.get(GoVelocityView.PRINCIPAL), is("Test User"));
}
Also used : User(org.springframework.security.userdetails.User) GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) 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