Search in sources :

Example 21 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserService method getAdminAndRoleSelections.

public AdminAndRoleSelections getAdminAndRoleSelections(List<String> users) {
    final SecurityConfig securityConfig = goConfigService.security();
    Set<Role> roles = allRoles(securityConfig);
    final List<TriStateSelection> roleSelections = TriStateSelection.forRoles(roles, users);
    final TriStateSelection adminSelection = TriStateSelection.forSystemAdmin(securityConfig.adminsConfig(), roles, new SecurityService.UserRoleMatcherImpl(securityConfig), users);
    return new AdminAndRoleSelections(adminSelection, roleSelections);
}
Also used : TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection)

Example 22 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method modifyRoles_shouldAddUserToExistingRole.

@Test
public void modifyRoles_shouldAddUserToExistingRole() throws Exception {
    configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("dev")));
    addUser(new User("user-1"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), result);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(true));
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 23 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method modifyRoles_shouldRemoveUserFromRole.

@Test
public void modifyRoles_shouldRemoveUserFromRole() throws Exception {
    addUser(new User("user-1"));
    // add it first
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
    // now remove it
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.remove)), new HttpLocalizedOperationResult());
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(false));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 24 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method modifyRoles_shouldNotCreateRoleIfItHasInvalidCharacters.

@Test
public void modifyRoles_shouldNotCreateRoleIfItHasInvalidCharacters() throws Exception {
    addUser(new User("user-1"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection(".dev+", TriStateSelection.Action.add)), result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), containsString("Failed to add role. Reason - "));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 25 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method shouldAddAdminPrivilegeToMultipleUsers.

@Test
public void shouldAddAdminPrivilegeToMultipleUsers() throws Exception {
    addUser(new User("user"));
    addUser(new User("loser"));
    addUser(new User("boozer"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user", "boozer"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add), new ArrayList<>(), result);
    CruiseConfig cruiseConfig = goConfigDao.load();
    final AdminsConfig adminsConfig = cruiseConfig.server().security().adminsConfig();
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("user"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("loser"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("boozer"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Aggregations

TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)30 Test (org.junit.Test)24 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)12 Username (com.thoughtworks.go.server.domain.Username)5 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)2 Before (org.junit.Before)2 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 AgentConfigsUpdateValidator (com.thoughtworks.go.validation.AgentConfigsUpdateValidator)1 ArrayList (java.util.ArrayList)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ExpectedException (org.junit.rules.ExpectedException)1