Search in sources :

Example 16 with User

use of org.springframework.security.userdetails.User 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 17 with User

use of org.springframework.security.userdetails.User 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

User (org.springframework.security.userdetails.User)17 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)10 Test (org.junit.Test)7 GrantedAuthority (org.springframework.security.GrantedAuthority)4 SecurityContext (org.springframework.security.context.SecurityContext)4 TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)4 UserDetails (org.springframework.security.userdetails.UserDetails)4 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)2 Before (org.junit.Before)2 Authentication (org.springframework.security.Authentication)2 BadCredentialsException (org.springframework.security.BadCredentialsException)2 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)2 SecurityContextImpl (org.springframework.security.context.SecurityContextImpl)2 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)1 NoPluginsInstalled (com.thoughtworks.go.config.registry.NoPluginsInstalled)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1