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); } }
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())); } } }
public void addUserIfDoesNotExist(Username userName) { synchronized (enableUserMutex) { User user = new User(CaseInsensitiveString.str(userName.getUsername())); if (!(user.isAnonymous() || userExists(user))) { assertUnknownUsersAreAllowedToLogin(); userDao.saveOrUpdate(user); } } }
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()); } }); }
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)); } }
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())); } }
public void deleteAll() { userDao.deleteAll(); }
public Collection<User> allUsers() { Set<User> result = new HashSet<User>(); result.addAll(userDao.allUsers()); return result; }
public User findUserByName(String username) { return userDao.findUser(username); }
private boolean userExists(User user) { User foundUser = userDao.findUser(user.getName()); return !(foundUser instanceof NullUser); }
public void saveOrUpdate(User user) throws ValidationException { validate(user); synchronized (enableUserMutex) { userDao.saveOrUpdate(user); } }
public User load(long id) { return userDao.load(id); }
public int enabledUserCount() { return userDao.enabledUserCount(); }
private boolean willDisableAllAdmins(List<String> usersToBeDisabled) { List<String> enabledUserNames = toUserNames(userDao.enabledUsers()); enabledUserNames.removeAll(usersToBeDisabled); return !userNameListContainsAdmin(enabledUserNames); }