Пример #1
0
 public void enable(List<String> usernames, LocalizedOperationResult result) {
   synchronized (enableUserMutex) {
     Set<String> potentialEnabledUsers = new HashSet<String>(toUserNames(userDao.enabledUsers()));
     potentialEnabledUsers.addAll(usernames);
     userDao.enableUsers(usernames);
   }
 }
Пример #2
0
  public void create(List<UserSearchModel> userSearchModels, HttpLocalizedOperationResult result) {
    if (userSearchModels.isEmpty()) {
      result.badRequest(LocalizedMessage.string("NO_USERS_SELECTED"));
      return;
    }
    synchronized (enableUserMutex) {
      for (UserSearchModel userSearchModel : userSearchModels) {
        User user = userSearchModel.getUser();

        if (userExists(user)) {
          result.conflict(
              LocalizedMessage.string(
                  "USER_ALREADY_EXISTS", user.getName(), user.getDisplayName(), user.getEmail()));
          return;
        }

        if (user.isAnonymous()) {
          result.badRequest(LocalizedMessage.string("USERNAME_NOT_PERMITTED", user.getName()));
          return;
        }

        if (!userSearchModel.getUserSourceType().equals(UserSourceType.PASSWORD_FILE)
            && validateEmailAndMatcher(result, user)) {
          return;
        }
        userDao.saveOrUpdate(user);
        result.setMessage(LocalizedMessage.string("USER_SUCCESSFULLY_ADDED", user.getName()));
      }
    }
  }
Пример #3
0
  public void addUserIfDoesNotExist(Username userName) {
    synchronized (enableUserMutex) {
      User user = new User(CaseInsensitiveString.str(userName.getUsername()));
      if (!(user.isAnonymous() || userExists(user))) {
        assertUnknownUsersAreAllowedToLogin();

        userDao.saveOrUpdate(user);
      }
    }
  }
Пример #4
0
 public Users findValidSubscribers(final StageConfigIdentifier identifier) {
   Users users = userDao.findNotificationSubscribingUsers();
   return users.filter(
       new Filter<User>() {
         public boolean matches(User user) {
           return user.hasSubscribedFor(identifier.getPipelineName(), identifier.getStageName())
               && securityService.hasViewPermissionForPipeline(
                   user.getName(), identifier.getPipelineName());
         }
       });
 }
Пример #5
0
 public void deleteUser(String username, HttpLocalizedOperationResult result) {
   try {
     userDao.deleteUser(username);
     result.setMessage(LocalizedMessage.string("USER_DELETE_SUCCESSFUL", username));
   } catch (UserNotFoundException e) {
     result.notFound(
         LocalizedMessage.string("USER_NOT_FOUND", username),
         HealthStateType.general(HealthStateScope.GLOBAL));
   } catch (UserEnabledException e) {
     result.badRequest(LocalizedMessage.string("USER_NOT_DISABLED", username));
   }
 }
Пример #6
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()));
   }
 }
Пример #7
0
 public void deleteAll() {
   userDao.deleteAll();
 }
Пример #8
0
 public Collection<User> allUsers() {
   Set<User> result = new HashSet<User>();
   result.addAll(userDao.allUsers());
   return result;
 }
Пример #9
0
 public User findUserByName(String username) {
   return userDao.findUser(username);
 }
Пример #10
0
 private boolean userExists(User user) {
   User foundUser = userDao.findUser(user.getName());
   return !(foundUser instanceof NullUser);
 }
Пример #11
0
 public void saveOrUpdate(User user) throws ValidationException {
   validate(user);
   synchronized (enableUserMutex) {
     userDao.saveOrUpdate(user);
   }
 }
Пример #12
0
 public User load(long id) {
   return userDao.load(id);
 }
Пример #13
0
 public int enabledUserCount() {
   return userDao.enabledUserCount();
 }
Пример #14
0
 private boolean willDisableAllAdmins(List<String> usersToBeDisabled) {
   List<String> enabledUserNames = toUserNames(userDao.enabledUsers());
   enabledUserNames.removeAll(usersToBeDisabled);
   return !userNameListContainsAdmin(enabledUserNames);
 }