use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.
the class RoleConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.
@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
cruiseConfig.server().security().getRoles().add(oldRole);
EntityHashingService entityHashingService = mock(EntityHashingService.class);
when(entityHashingService.md5ForEntity(oldRole)).thenReturn("md5");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
RoleConfigCommand command = new RoleConfigUpdateCommand(goConfigService, updatedRole, null, currentUser, result, entityHashingService, "bad-md5");
assertThat(command.canContinue(cruiseConfig), is(false));
assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
}
use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.
the class RoleConfigUpdateCommandTest method shouldUpdateExistingRole.
@Test
public void shouldUpdateExistingRole() throws Exception {
PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
cruiseConfig.server().security().getRoles().add(oldRole);
RoleConfigCommand command = new RoleConfigUpdateCommand(null, updatedRole, null, null, null, null, null);
command.update(cruiseConfig);
assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("foo")), is(equalTo(updatedRole)));
}
use of com.thoughtworks.go.config.PluginRoleConfig in project gocd by gocd.
the class AuthorizationMessageConverterV1 method getProcessRoleConfigsResponseBody.
@Override
public String getProcessRoleConfigsResponseBody(List<PluginRoleConfig> roles) {
List<Map> list = new ArrayList<>();
for (PluginRoleConfig role : roles) {
LinkedHashMap<String, Object> e = new LinkedHashMap<>();
e.put("name", role.getName().toString());
e.put("configuration", role.getConfigurationAsMap(true));
list.add(e);
}
return GSON.toJson(list);
}
use of com.thoughtworks.go.config.PluginRoleConfig 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.config.PluginRoleConfig in project gocd by gocd.
the class SecurityAuthConfigDeleteCommandTest method shouldNotValidateIfProfileIsInUseByRole.
@Test
public void shouldNotValidateIfProfileIsInUseByRole() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
cruiseConfig.server().security().addRole(new PluginRoleConfig("blackbird", "foo"));
SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
thrown.expect(GoConfigInvalidException.class);
thrown.expectMessage("The security auth config 'foo' is being referenced by role(s): blackbird.");
command.isValid(cruiseConfig);
}
Aggregations