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);
}
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));
}
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));
}
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 - "));
}
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));
}
Aggregations