public static List<UserVO> listUsersByAccount(long accountId) { return s_userDao.listByAccount(accountId); }
/** * Searches for a user with the given userId. If no user is found we throw an {@link InvalidParameterValueException}. */ protected UserVO retrieveAndValidateUser(UpdateUserCmd updateUserCmd) { Long userId = updateUserCmd.getId(); UserVO user = _userDao.getUser(userId); if (user == null) { throw new InvalidParameterValueException("Unable to find user with id: " + userId); } return user; }
private void enableAdminUser(final String password) { String encodedPassword = null; final UserVO adminUser = _userDao.getUser(2); if (adminUser == null) { final String msg = "CANNOT find admin user"; s_logger.error(msg); throw new CloudRuntimeException(msg); } if (adminUser.getState() == Account.State.disabled) { // This means its a new account, set the password using the // authenticator for (final UserAuthenticator authenticator : _userPasswordEncoders) { encodedPassword = authenticator.encode(password); if (encodedPassword != null) { break; } } adminUser.setPassword(encodedPassword); adminUser.setState(Account.State.enabled); _userDao.persist(adminUser); s_logger.info("Admin user enabled"); } }
@Override public void markUserRegistered(long userId) { UserVO userForUpdate = _userDao.createForUpdate(); userForUpdate.setRegistered(true); _userDao.update(Long.valueOf(userId), userForUpdate); }
private String createUserSecretKey(long userId) { try { UserVO updatedUser = _userDao.createForUpdate(); String encodedKey = null; int retryLimit = 10; UserVO userBySecretKey = null; do { KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1"); SecretKey key = generator.generateKey(); encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded()); userBySecretKey = _userDao.findUserBySecretKey(encodedKey); retryLimit--; } while ((userBySecretKey != null) && (retryLimit >= 0)); if (userBySecretKey != null) { return null; } updatedUser.setSecretKey(encodedKey); _userDao.update(userId, updatedUser); return encodedKey; } catch (NoSuchAlgorithmException ex) { s_logger.error("error generating secret key for user id=" + userId, ex); } return null; }
@Override public Boolean doInTransaction(TransactionStatus status) { UserVO newUser = new UserVO(user); user.setExternalEntity(user.getUuid()); user.setUuid(UUID.randomUUID().toString()); user.setApiKey(null); user.setSecretKey(null); _userDao.update(user.getId(), user); newUser.setAccountId(newAccountId); boolean success = _userDao.remove(user.getId()); UserVO persisted = _userDao.persist(newUser); return success && persisted.getUuid().equals(user.getExternalEntity()); } });
@Override public boolean authorizeUser(Long userId, String entityId, boolean enable) { UserVO user = _userDao.getUser(userId); if (user != null) { if (enable) { user.setExternalEntity(entityId); user.setSource(User.Source.SAML2); } else { if (user.getSource().equals(User.Source.SAML2)) { user.setSource(User.Source.SAML2DISABLED); } else { return false; } } _userDao.update(user.getId(), user); return true; } return false; }
List<UserVO> users = _userDao.listByAccount(accountId); for (UserVO user : users) { if (!_userDao.remove(user.getId())) { s_logger.error("Unable to delete user: " + user + " as a part of account " + account + " cleanup"); accountCleanupNeeded = true;
User user = _userDao.findById(userId); if (user == null || user.getRemoved() != null) { throw new InvalidParameterValueException("Unable to find user by id"); List<UserVO> allUsersByAccount = _userDao.listByAccount(user.getAccountId()); for (UserVO oneUser : allUsersByAccount) { if (oneUser.getState().equals(State.enabled)) {
public void addUser(User user) userDao.saveUser(user); public List<User> getUser() return userDao.getUser(); public User getUser(int id) return userDao.getUser(id); public void updateUser(User user) userDao.updateUser(user);
@Override public void execute() { List<UserVO> users = new ArrayList<UserVO>(); if (getUserId() != null) { UserVO user = _userDao.getUser(getUserId()); if (user != null) { Account account = _accountService.getAccount(user.getAccountId()); _accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, true, account); users.add(user); } } else if (CallContext.current().getCallingAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) { users = _userDao.listAll(); } ListResponse<SamlAuthorizationResponse> response = new ListResponse<SamlAuthorizationResponse>(); List<SamlAuthorizationResponse> authorizationResponses = new ArrayList<SamlAuthorizationResponse>(); for (User user: users) { SamlAuthorizationResponse authorizationResponse = new SamlAuthorizationResponse(user.getUuid(), user.getSource().equals(User.Source.SAML2), user.getExternalEntity()); authorizationResponse.setObjectName("samlauthorization"); authorizationResponses.add(authorizationResponse); } response.setResponses(authorizationResponses); response.setResponseName(getCommandName()); setResponseObject(response); } }
@Override public UserVO getSystemUser() { if (_systemUser == null) { _systemUser = _userDao.findById(User.UID_SYSTEM); } return _systemUser; }
final User user = _userDao.findByUuid(userUuid); final Domain domain = _domainDao.findByUuid(domainUuid); final UserAccount nextUserAccount = _accountService.getUserAccountById(user.getId()); List<SamlUserAccountResponse> accountResponses = new ArrayList<SamlUserAccountResponse>(); for (UserAccountVO userAccount: switchableAccounts) { User user = _userDao.getUser(userAccount.getId()); Domain domain = _domainService.getDomain(userAccount.getDomainId()); SamlUserAccountResponse accountResponse = new SamlUserAccountResponse();
domainUser = userDAO.getUser(login); roles = userDAO.getUserRoles(userid);
protected UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID, User.Source source) { if (s_logger.isDebugEnabled()) { s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone); } String encodedPassword = null; for (UserAuthenticator authenticator : _userPasswordEncoders) { encodedPassword = authenticator.encode(password); if (encodedPassword != null) { break; } } if (encodedPassword == null) { throw new CloudRuntimeException("Failed to encode password"); } if (userUUID == null) { userUUID = UUID.randomUUID().toString(); } UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, userUUID, source)); CallContext.current().putContextParameter(User.class, user.getUuid()); return user; }
@Override @ActionEvent(eventType = EventTypes.EVENT_USER_UPDATE, eventDescription = "Updating User") public UserAccount updateUser(UpdateUserCmd updateUserCmd) { UserVO user = retrieveAndValidateUser(updateUserCmd); s_logger.debug("Updating user with Id: " + user.getUuid()); validateAndUpdateApiAndSecretKeyIfNeeded(updateUserCmd, user); Account account = retrieveAndValidateAccount(user); validateAndUpdateFirstNameIfNeeded(updateUserCmd, user); validateAndUpdateLastNameIfNeeded(updateUserCmd, user); validateAndUpdateUsernameIfNeeded(updateUserCmd, user, account); validateUserPasswordAndUpdateIfNeeded(updateUserCmd.getPassword(), user, updateUserCmd.getCurrentPassword()); String email = updateUserCmd.getEmail(); if (StringUtils.isNotBlank(email)) { user.setEmail(email); } String timezone = updateUserCmd.getTimezone(); if (StringUtils.isNotBlank(timezone)) { user.setTimezone(timezone); } _userDao.update(user.getId(), user); return _userAccountDao.findById(user.getId()); }
private boolean doSetUserStatus(long userId, State state) { UserVO userForUpdate = _userDao.createForUpdate(); userForUpdate.setState(state); return _userDao.update(Long.valueOf(userId), userForUpdate); }
@Override public User getActiveUser(long userId) { return _userDao.findById(userId); }