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()));
}
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));
}
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));
}
Aggregations