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