use of org.springframework.security.userdetails.UserDetails in project gocd by gocd.
the class FileAuthenticationProvider method retrieveUser.
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
final String passwordFilePath = goConfigService.security().passwordFileConfig().path();
try {
UserMap userMap = UserMapEditor.addUsersFromProperties(new UserMap(), addDummyRoleToPropertiesIfRequired(stripShaFromPasswordsIfRequired(loadPasswordFile(passwordFilePath))));
final UserDetails details = userMap.getUser(username);
return userStrippedOfAnyAuthoritiesSpecifiedInFile(username, details);
} catch (IOException e) {
throw new UsernameNotFoundException("Trying to authenticate user " + username + " but could not open file: " + passwordFilePath);
}
}
use of org.springframework.security.userdetails.UserDetails 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.UserDetails 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.UserDetails in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldRetrieveDetailsIfUsernameSpecifiedInFile.
@Test
public void shouldRetrieveDetailsIfUsernameSpecifiedInFile() throws Exception {
setupFile("jez=" + SHA1_BADGER);
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("jez")))).thenReturn(true);
when(userService.findUserByName("jez")).thenReturn(new com.thoughtworks.go.domain.User("jez", "Jezz Humbles", "jez@humble.com"));
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
final UserDetails details = provider.retrieveUser("jez", null);
assertThat(details.getAuthorities()[0].getAuthority(), is("ROLE_SUPERVISOR"));
assertThat(details.isAccountNonExpired(), is(true));
assertThat(details.isAccountNonLocked(), is(true));
assertThat(details.isCredentialsNonExpired(), is(true));
assertThat(details.isEnabled(), is(true));
assertThat(details.getUsername(), is("jez"));
assertThat(details.getPassword(), is(SHA1_BADGER));
}
use of org.springframework.security.userdetails.UserDetails in project gocd by gocd.
the class OauthAuthenticationProviderTest method shouldReturnOAUTH_USERAsTheGrantedAuthority.
@Test
public void shouldReturnOAUTH_USERAsTheGrantedAuthority() {
when(dataSource.findOauthTokenByAccessToken("token-string")).thenReturn(oauthTokenDto("user-id"));
GrantedAuthority[] grantedAuthorities = { GoAuthority.ROLE_OAUTH_USER.asAuthority() };
OauthAuthenticationToken authentication = provider.authenticate(new OauthAuthenticationToken("token-string"));
assertThat(authentication.isAuthenticated(), is(true));
UserDetails userDetails = authentication.getPrincipal();
assertThat(userDetails.getUsername(), is("user-id"));
assertThat(userDetails.getAuthorities(), is(grantedAuthorities));
assertThat(authentication.getAuthorities(), is(grantedAuthorities));
}
Aggregations