Search in sources :

Example 26 with UsernamePasswordAuthenticationToken

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

the class UserServiceIntegrationTest method addUserIfDoesNotExist_shouldAddUserIfDoesNotExist.

@Test
public void addUserIfDoesNotExist_shouldAddUserIfDoesNotExist() throws Exception {
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(getAuthUser("new_user"), "credentials", new GrantedAuthority[] { GoAuthority.ROLE_USER.asAuthority() });
    assertThat(userDao.findUser("new_user"), isANullUser());
    userService.addUserIfDoesNotExist(UserHelper.getUser(auth));
    User loadedUser = userDao.findUser("new_user");
    assertThat(loadedUser, is(new User("new_user", "new_user", "")));
    assertThat(loadedUser, not(isANullUser()));
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 27 with UsernamePasswordAuthenticationToken

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

the class UserServiceIntegrationTest method addUserIfDoesNotExist_shouldNotAddUserIfExists.

@Test
public void addUserIfDoesNotExist_shouldNotAddUserIfExists() throws Exception {
    User user = new User("old_user");
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(getAuthUser("old_user"), "credentials", new GrantedAuthority[] { GoAuthority.ROLE_USER.asAuthority() });
    addUser(user);
    userService.addUserIfDoesNotExist(UserHelper.getUser(auth));
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 28 with UsernamePasswordAuthenticationToken

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

the class IntegrationTestsFixture method login.

public static void login(String username, String password) {
    UserDetails principal = new User(username, password, true, true, true, true, new GrantedAuthority[0]);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(principal, password));
}
Also used : UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken)

Aggregations

UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)28 Test (org.junit.Test)20 User (org.springframework.security.userdetails.User)10 UserDetails (org.springframework.security.userdetails.UserDetails)8 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)5 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)5 User (com.thoughtworks.go.plugin.access.authorization.models.User)5 Authentication (org.springframework.security.Authentication)5 SecurityContext (org.springframework.security.context.SecurityContext)4 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 GrantedAuthority (org.springframework.security.GrantedAuthority)2 SecurityContextImpl (org.springframework.security.context.SecurityContextImpl)2 AuthenticationProvider (org.springframework.security.providers.AuthenticationProvider)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