Search in sources :

Example 6 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class SecurityContextHelper method setCurrentUserWithAuthorities.

public static void setCurrentUserWithAuthorities(String username, final GrantedAuthority[] authorities) {
    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User(username, "", true, authorities), null, authorities));
    SecurityContextHolder.setContext(context);
}
Also used : SecurityContextImpl(org.springframework.security.context.SecurityContextImpl) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken)

Example 7 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class GoAuthenticationProviderTest method setUp.

@Before
public void setUp() throws Exception {
    userService = mock(UserService.class);
    underlyingProvider = mock(AuthenticationProvider.class);
    enforcementProvider = new GoAuthenticationProvider(userService, underlyingProvider);
    auth = new UsernamePasswordAuthenticationToken(new User("user", "pass", true, true, true, true, new GrantedAuthority[] {}), "credentials");
    resultantAuthorization = new UsernamePasswordAuthenticationToken(new User("user-authenticated", "pass", true, true, true, true, new GrantedAuthority[] { GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority() }), "credentials");
    when(underlyingProvider.authenticate(auth)).thenReturn(resultantAuthorization);
}
Also used : User(org.springframework.security.userdetails.User) UserService(com.thoughtworks.go.server.service.UserService) AuthenticationProvider(org.springframework.security.providers.AuthenticationProvider) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Before(org.junit.Before)

Example 8 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldNotUserWithoutValidPassword.

@Test(expected = BadCredentialsException.class)
public void shouldNotUserWithoutValidPassword() throws Exception {
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    UserDetails user = new User("jez", "something", true, true, true, true, new GrantedAuthority[0]);
    provider.additionalAuthenticationChecks(user, new UsernamePasswordAuthenticationToken("jez", "nothing"));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 9 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldAuthenticateUserWithValidPassword.

@Test
public void shouldAuthenticateUserWithValidPassword() throws Exception {
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    UserDetails user = new User("jez", SHA1_BADGER, true, true, true, true, new GrantedAuthority[0]);
    provider.additionalAuthenticationChecks(user, new UsernamePasswordAuthenticationToken("jez", "badger"));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 10 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class ConfigModifyingUserTest method shouldIdentifyLoggedInUserAsModifyingUser_WhenNoModifyingUserIsGiven.

@Test
public void shouldIdentifyLoggedInUserAsModifyingUser_WhenNoModifyingUserIsGiven() {
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
    ConfigModifyingUser user = new ConfigModifyingUser();
    assertThat(user.getUserName(), is("loser_boozer"));
}
Also used : User(org.springframework.security.userdetails.User) SecurityContext(org.springframework.security.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Aggregations

User (org.springframework.security.userdetails.User)17 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)10 Test (org.junit.Test)8 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