use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.
the class UsersController method changePassword.
private void changePassword(Users user, String newPassword, String confirmedPassword) throws UserException {
if (userValidator.isValidPassword(newPassword, confirmedPassword)) {
try {
Secret secret = securityUtils.generateSecret(newPassword);
authController.changePassword(user, secret);
} catch (Exception ex) {
throw new UserException(RESTCodes.UserErrorCode.PASSWORD_RESET_UNSUCCESSFUL, Level.SEVERE, null, ex.getMessage(), ex);
}
}
}
use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.
the class UsersController method resetPassword.
/**
* Use to reset password to a temporary random password
* @param id
* @return
* @throws UserException
* @throws MessagingException
*/
public String resetPassword(Integer id, String initiator) throws UserException, MessagingException {
Users user = userFacade.find(id);
if (!user.getMode().equals(UserAccountType.M_ACCOUNT_TYPE)) {
throw new UserException(RESTCodes.UserErrorCode.OPERATION_NOT_ALLOWED, Level.FINE, "Can not reset password of a" + " remote user");
}
String randomPwd = securityUtils.generateRandomString(UserValidator.TEMP_PASSWORD_LENGTH);
user.setStatus(UserAccountStatus.TEMP_PASSWORD);
changePasswordAsAdmin(user, randomPwd);
String subject = UserAccountsEmailMessages.ACCOUNT_PASSWORD_RESET;
String msg = UserAccountsEmailMessages.buildResetByAdminMessage(initiator);
emailBean.sendEmail(user.getEmail(), Message.RecipientType.TO, subject, msg);
return randomPwd;
}
use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.
the class UsersController method removeRole.
public void removeRole(String role, Integer id) throws UserException {
Users p = userFacade.find(id);
BbcGroup bbcGroup = bbcGroupFacade.findByGroupName(role);
if (bbcGroup != null && p.getBbcGroupCollection().contains(bbcGroup)) {
// remove from table only
userFacade.removeGroup(p.getEmail(), bbcGroup.getGid());
// remove from the user entity
p.getBbcGroupCollection().remove(bbcGroup);
} else if (bbcGroup != null) {
throw new UserException(RESTCodes.UserErrorCode.ROLE_NOT_FOUND, Level.FINE, "Role could not be granted.");
}
// trigger user account handlers
UserAccountHandler.runUserAccountUpdateHandlers(userAccountHandlers, p);
}
use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.
the class SecretsController method get.
/**
* Gets a decrypted Secret
* @param user The user associated with the secret
* @param secretName The Secret identifier
* @return The Secret decrypted along with some metadata
* @throws UserException
*/
public SecretPlaintext get(Users user, String secretName) throws UserException {
checkIfUserIsNull(user);
checkIfNameIsNullOrEmpty(secretName);
SecretId id = new SecretId(user.getUid(), secretName);
Secret storedSecret = secretsFacade.findById(id);
checkIfSecretIsNull(storedSecret, secretName, user);
try {
return decrypt(user, storedSecret);
} catch (IOException | GeneralSecurityException ex) {
throw new UserException(RESTCodes.UserErrorCode.SECRET_ENCRYPTION_ERROR, Level.SEVERE, "Error decrypting Secret", "Could not decrypt Secret " + secretName, ex);
}
}
use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.
the class SecretsController method createSecretForProject.
/**
* @param user
* @param secretName
* @param secret
* @param projectIdScope
* @return
* @throws UserException
*/
public Secret createSecretForProject(Users user, String secretName, String secret, Integer projectIdScope) throws UserException, ProjectException {
Project project = projectFacade.find(projectIdScope);
if (project == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Project with ID " + projectIdScope + " does not exist!", "User " + user.getUsername() + " requested shared Secret " + secretName + " but Project with ID " + projectIdScope + "does not exist");
}
if (!projectTeamFacade.isUserMemberOfProject(project, user)) {
throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_NOT_FOUND, Level.FINE, "User not a member of " + "project with ID " + projectIdScope + ".");
}
SecretId secretId = new SecretId(user.getUid(), secretName);
if (secretsFacade.findById(secretId) != null) {
throw new UserException(RESTCodes.UserErrorCode.SECRET_EXISTS, Level.FINE, "Secret already exists", "Secret with name " + secretName + " already exists for user " + user.getUsername());
}
return validateAndCreateSecret(secretId, user, secret, VisibilityType.PROJECT, projectIdScope);
}
Aggregations