Search in sources :

Example 21 with UserException

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);
        }
    }
}
Also used : Secret(io.hops.hopsworks.common.security.utils.Secret) UserException(io.hops.hopsworks.exceptions.UserException) MessagingException(javax.mail.MessagingException) WriterException(com.google.zxing.WriterException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) UserException(io.hops.hopsworks.exceptions.UserException) ConstraintViolationException(javax.validation.ConstraintViolationException)

Example 22 with UserException

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;
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException)

Example 23 with UserException

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);
}
Also used : BbcGroup(io.hops.hopsworks.persistence.entity.user.BbcGroup) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException)

Example 24 with UserException

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);
    }
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret) SecretId(io.hops.hopsworks.persistence.entity.user.security.secrets.SecretId) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) UserException(io.hops.hopsworks.exceptions.UserException)

Example 25 with UserException

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);
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) SecretId(io.hops.hopsworks.persistence.entity.user.security.secrets.SecretId) UserException(io.hops.hopsworks.exceptions.UserException)

Aggregations

UserException (io.hops.hopsworks.exceptions.UserException)77 Users (io.hops.hopsworks.persistence.entity.user.Users)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Produces (javax.ws.rs.Produces)15 Path (javax.ws.rs.Path)12 IOException (java.io.IOException)11 ApiOperation (io.swagger.annotations.ApiOperation)10 ServiceException (io.hops.hopsworks.exceptions.ServiceException)9 MessagingException (javax.mail.MessagingException)9 GET (javax.ws.rs.GET)9 ProjectException (io.hops.hopsworks.exceptions.ProjectException)8 Project (io.hops.hopsworks.persistence.entity.project.Project)8 EJBException (javax.ejb.EJBException)8 FacesContext (javax.faces.context.FacesContext)8 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)7 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 BbcGroup (io.hops.hopsworks.persistence.entity.user.BbcGroup)6 Secret (io.hops.hopsworks.persistence.entity.user.security.secrets.Secret)6 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)5 KafkaException (io.hops.hopsworks.exceptions.KafkaException)5