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 PluginAuthenticationProviderTest method shouldCreateGoUserPrincipalWhenAnAuthenticationPluginIsAbleToAuthenticateUser.
@Test
public void shouldCreateGoUserPrincipalWhenAnAuthenticationPluginIsAbleToAuthenticateUser() {
String pluginId1 = "plugin-id-1";
String pluginId2 = "plugin-id-2";
when(authenticationPluginRegistry.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId1, pluginId2)));
when(authenticationExtension.authenticateUser(pluginId1, "username", "password")).thenReturn(null);
when(authenticationExtension.authenticateUser(pluginId2, "username", "password")).thenReturn(new User("username", null, null));
UserDetails userDetails = provider.retrieveUser("username", authenticationToken);
assertThat(userDetails, is(instanceOf(GoUserPrinciple.class)));
GoUserPrinciple goUserPrincipal = (GoUserPrinciple) userDetails;
assertThat(goUserPrincipal.getUsername(), is("username"));
assertThat(goUserPrincipal.getDisplayName(), is("username"));
assertThat(goUserPrincipal.getAuthorities().length, is(1));
assertThat(goUserPrincipal.getAuthorities()[0], is(userAuthority));
}
use of org.springframework.security.userdetails.UserDetails in project gocd by gocd.
the class PluginAuthenticationProviderTest method shouldCreateGoUserPrincipalWhenAnAuthorizationPluginIsAbleToAuthenticateUser.
@Test
public void shouldCreateGoUserPrincipalWhenAnAuthorizationPluginIsAbleToAuthenticateUser() {
String pluginId1 = "plugin-id-1";
String pluginId2 = "plugin-id-2";
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", pluginId2));
securityConfig.addRole(new PluginRoleConfig("admin", "github", ConfigurationPropertyMother.create("foo")));
when(store.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId1, pluginId2)));
when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), null)).thenReturn(NULL_AUTH_RESPONSE);
AuthenticationResponse response = new AuthenticationResponse(new User("username", "display-name", "test@test.com"), Collections.emptyList());
when(authorizationExtension.authenticateUser(pluginId2, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId2), securityConfig.getPluginRoles(pluginId2))).thenReturn(response);
UserDetails userDetails = provider.retrieveUser("username", authenticationToken);
assertThat(userDetails, is(instanceOf(GoUserPrinciple.class)));
GoUserPrinciple goUserPrincipal = (GoUserPrinciple) userDetails;
assertThat(goUserPrincipal.getUsername(), is("username"));
assertThat(goUserPrincipal.getDisplayName(), is("display-name"));
assertThat(goUserPrincipal.getAuthorities().length, is(1));
assertThat(goUserPrincipal.getAuthorities()[0], is(userAuthority));
}
use of org.springframework.security.userdetails.UserDetails in project gocd by gocd.
the class X509AuthoritiesPopulatorTest method shouldReturnUserDetailsWithCorrectAuthorityIfAgentCertificateHasOu.
@Test
public void shouldReturnUserDetailsWithCorrectAuthorityIfAgentCertificateHasOu() {
X509Certificate agentCertificate = new X509CertificateGenerator().createCertificateWithDn("CN=hostname, OU=agent").getFirstCertificate();
UserDetails userDetails = populator.getUserDetails(agentCertificate);
GrantedAuthority[] actual = userDetails.getAuthorities();
GrantedAuthority expected = new GrantedAuthorityImpl(ROLE_AGENT);
assertThat(actual.length, is(1));
assertThat(actual[0], is(expected));
}
Aggregations