use of com.thoughtworks.go.server.security.AuthorityGranter 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 com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldThrowExceptionIfUsernameIsNotSpecifiedInFile.
@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionIfUsernameIsNotSpecifiedInFile() throws Exception {
setupFile("jez=" + SHA1_BADGER);
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
provider.retrieveUser("blah", null);
}
use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldReturnUserPrincipleWithTheRightDisplayName.
@Test
public void shouldReturnUserPrincipleWithTheRightDisplayName() throws Exception {
setupFile(String.format("jez=%s\ncharan=%s\nbabe=%s", SHA1_BADGER, SHA1_BADGER, SHA1_BADGER));
when(userService.findUserByName("jez")).thenReturn(new com.thoughtworks.go.domain.User("jez", "Jezz Humbles", "jez@humble.com"));
when(userService.findUserByName("charan")).thenReturn(new com.thoughtworks.go.domain.User("charan", "", "ch@ar.an"));
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, new AuthorityGranter(securityService), userService, securityService);
GoUserPrinciple details = (GoUserPrinciple) provider.retrieveUser("jez", null);
assertThat(details.getUsername(), is("jez"));
assertThat(details.getDisplayName(), is("Jezz Humbles"));
details = (GoUserPrinciple) provider.retrieveUser("charan", null);
assertThat(details.getUsername(), is("charan"));
assertThat(details.getDisplayName(), is("charan"));
details = (GoUserPrinciple) provider.retrieveUser("babe", null);
assertThat(details.getUsername(), is("babe"));
assertThat(details.getDisplayName(), is("babe"));
}
use of com.thoughtworks.go.server.security.AuthorityGranter 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 com.thoughtworks.go.server.security.AuthorityGranter 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));
}
Aggregations