use of com.thoughtworks.go.server.security.userdetail.GoUserPrinciple in project gocd by gocd.
the class UserHelperTest method shouldGetDisplayNameForAPasswordFileUser.
@Test
public void shouldGetDisplayNameForAPasswordFileUser() {
GrantedAuthority[] authorities = { new GrantedAuthorityImpl("anything") };
TestingAuthenticationToken authentication = new TestingAuthenticationToken(new GoUserPrinciple("user", "Full Name", "password", true, true, true, true, authorities), null, authorities);
assertThat(UserHelper.getUserName(authentication), is(new Username(new CaseInsensitiveString("user"), "Full Name")));
}
use of com.thoughtworks.go.server.security.userdetail.GoUserPrinciple 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 com.thoughtworks.go.server.security.userdetail.GoUserPrinciple 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 com.thoughtworks.go.server.security.userdetail.GoUserPrinciple in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldStripOutAuthoritiesThatIsSpecifiedInPasswordFile.
@Test
public void shouldStripOutAuthoritiesThatIsSpecifiedInPasswordFile() throws Exception {
setupFile("jez=" + SHA1_BADGER + ",ROLE_OF_GOD");
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"));
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
final GoUserPrinciple details = (GoUserPrinciple) provider.retrieveUser("jez", null);
assertThat(details.getUsername(), is("jez"));
assertThat(details.getDisplayName(), is("Jezz Humbles"));
assertThat(details.getAuthorities().length, is(2));
assertThat(details.getAuthorities()[0].getAuthority(), Is.is(GoAuthority.ROLE_SUPERVISOR.name()));
assertThat(details.getAuthorities()[1].getAuthority(), is(GoAuthority.ROLE_USER.name()));
}
use of com.thoughtworks.go.server.security.userdetail.GoUserPrinciple in project gocd by gocd.
the class PluginAuthenticationProviderTest method reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfLoginNameInGoUserPrinciple.
@Test
public void reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfLoginNameInGoUserPrinciple() throws Exception {
String pluginId1 = "cd.go.ldap";
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
addPluginSupportingPasswordBasedAuthentication(pluginId1);
when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(new AuthenticationResponse(new User("username", "bob", "bob@example.com"), Arrays.asList("blackbird", "admins")));
GoUserPrinciple principal = new GoUserPrinciple("username", "Display", "password", true, true, true, true, new GrantedAuthority[] {}, null);
UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(principal, "password"));
assertNotNull(userDetails);
verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
Aggregations