Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 public void modifyRolesAndUserAdminPrivileges(
     final List<String> users,
     final TriStateSelection adminPrivilege,
     final List<TriStateSelection> roleSelections,
     LocalizedOperationResult result) {
   Users allUsers = userDao.allUsers();
   for (String user : users) {
     if (!allUsers.containsUserNamed(user)) {
       result.badRequest(LocalizedMessage.string("USER_DOES_NOT_EXIST_IN_DB", user));
       return;
     }
   }
   try {
     final GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
     command.addCommand(goConfigService.modifyRolesCommand(users, roleSelections));
     command.addCommand(goConfigService.modifyAdminPrivilegesCommand(users, adminPrivilege));
     goConfigService.updateConfig(command);
   } catch (Exception e) {
     result.badRequest(LocalizedMessage.string("INVALID_ROLE_NAME", e.getMessage()));
   }
 }
Esempio n. 3
0
  private List<UserModel> allUsersForDisplay() {
    Collection<User> users = allUsers();
    ArrayList<UserModel> userModels = new ArrayList<UserModel>();
    for (User user : users) {
      String userName = user.getName();

      ArrayList<String> roles = new ArrayList<String>();
      for (Role role : goConfigService.rolesForUser(new CaseInsensitiveString(userName))) {
        roles.add(CaseInsensitiveString.str(role.getName()));
      }

      userModels.add(
          new UserModel(
              user,
              roles,
              securityService.isUserAdmin(new Username(new CaseInsensitiveString(userName)))));
    }
    return userModels;
  }
Esempio n. 4
0
 private void assertUnknownUsersAreAllowedToLogin() {
   if (goConfigService.isOnlyKnownUserAllowedToLogin()) {
     throw new OnlyKnownUsersAllowedException("Please ask the administrator to add you to Go");
   }
 }