Search in sources :

Example 31 with Authentication

use of org.springframework.security.Authentication in project gocd by gocd.

the class UserHelperTest method stubSecurityContextForGrantedAuthorities.

private static void stubSecurityContextForGrantedAuthorities(GrantedAuthority[] grantedAuthorities) {
    SecurityContext context = mock(SecurityContext.class);
    Authentication authentication = mock(Authentication.class);
    when(context.getAuthentication()).thenReturn(authentication);
    when(authentication.getAuthorities()).thenReturn(grantedAuthorities);
    SecurityContextHolder.setContext(context);
}
Also used : Authentication(org.springframework.security.Authentication) SecurityContext(org.springframework.security.context.SecurityContext)

Aggregations

Authentication (org.springframework.security.Authentication)31 Test (org.junit.Test)16 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)5 NullUser (com.thoughtworks.go.domain.NullUser)4 GrantedAuthority (org.springframework.security.GrantedAuthority)4 TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)4 User (com.thoughtworks.go.domain.User)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 PreAuthenticatedAuthenticationToken (com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 Expectations (org.jmock.Expectations)2 AuthenticationException (org.springframework.security.AuthenticationException)2 User (org.springframework.security.userdetails.User)2 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)1 User (com.thoughtworks.go.plugin.access.authentication.models.User)1 DefaultGoApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse)1 Username (com.thoughtworks.go.server.domain.Username)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1