Search in sources :

Example 11 with UserException

use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.

the class OnlineFeaturestoreController method initConnection.

/**
 * Initializes a JDBC connection MySQL Server using an online featurestore user and password
 *
 * @param databaseName name of the MySQL database to open a connection to
 * @param project      the project of the user making the request
 * @param user         the user making the request
 * @return conn the JDBC connection
 * @throws FeaturestoreException
 */
private Connection initConnection(String databaseName, Project project, Users user) throws FeaturestoreException {
    String jdbcString = "";
    String dbUsername = onlineDbUsername(project, user);
    String password = "";
    try {
        password = secretsController.get(user, dbUsername).getPlaintext();
    } catch (UserException e) {
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.FEATURESTORE_ONLINE_SECRETS_ERROR, Level.SEVERE, "Problem getting secrets for the JDBC connection to the online FS");
    }
    try {
        return DriverManager.getConnection(getJdbcURL(databaseName), dbUsername, password);
    } catch (SQLException | ServiceDiscoveryException e) {
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.COULD_NOT_INITIATE_MYSQL_CONNECTION_TO_ONLINE_FEATURESTORE, Level.SEVERE, "project: " + project.getName() + ", database: " + databaseName + ", db user:" + dbUsername + ", jdbcString: " + jdbcString, e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) UserException(io.hops.hopsworks.exceptions.UserException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 12 with UserException

use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.

the class OnlineFeaturestoreController method createOnlineFeaturestoreUserSecret.

/**
 * Stores the online-featurestore password as a Hopsworks secret for the user
 *
 * @param dbuser the database-user
 * @param user the user to store the secret for
 * @param project the project of the online feature store
 * @return the password
 * @throws FeaturestoreException
 */
private String createOnlineFeaturestoreUserSecret(String dbuser, Users user, Project project) throws FeaturestoreException {
    String onlineFsPw = RandomStringUtils.randomAlphabetic(FeaturestoreConstants.ONLINE_FEATURESTORE_PW_LENGTH);
    try {
        // Delete if the secret already exsits
        secretsController.delete(user, dbuser);
        secretsController.add(user, dbuser, onlineFsPw, VisibilityType.PRIVATE, project.getId());
    } catch (UserException e) {
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.FEATURESTORE_ONLINE_SECRETS_ERROR, Level.SEVERE, "Problem adding online featurestore password to hopsworks secretsmgr");
    }
    return onlineFsPw;
}
Also used : UserException(io.hops.hopsworks.exceptions.UserException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 13 with UserException

use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.

the class LoginBean method login.

public String login() {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    this.user = userFacade.findByEmail(this.credentials.getUsername());
    if (user == null) {
        context.addMessage(null, new FacesMessage("Login failed. User " + this.credentials.getUsername()));
        return "";
    }
    try {
        auditedUserAuth.login(user, this.credentials.getPassword(), this.credentials.getOtp(), request);
    } catch (UserException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        context.addMessage(null, new FacesMessage("Login failed."));
        return "";
    } catch (EJBException ie) {
        String msg = ie.getCausedByException().getMessage();
        if (msg != null && !msg.isEmpty() && msg.contains("Second factor required.")) {
            setTwoFactor(true);
        }
        context.addMessage(null, new FacesMessage(msg));
        return "login";
    } catch (ServletException e) {
        authController.registerAuthenticationFailure(user);
        context.addMessage(null, new FacesMessage("Login failed."));
        return "";
    }
    return "monitoring";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) FacesContext(javax.faces.context.FacesContext) UserException(io.hops.hopsworks.exceptions.UserException) EJBException(javax.ejb.EJBException) FacesMessage(javax.faces.application.FacesMessage)

Example 14 with UserException

use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.

the class AccountVerification method validate.

private boolean validate(String key) {
    FacesContext ctx = FacesContext.getCurrentInstance();
    HttpServletRequest req = (HttpServletRequest) ctx.getExternalContext().getRequest();
    try {
        auditedUserAccountAction.validateKey(key, req);
        return true;
    } catch (PersistenceException ex) {
        dbDown = true;
    } catch (EJBException | IllegalArgumentException e) {
        return false;
    } catch (UserException ue) {
        if (RESTCodes.UserErrorCode.ACCOUNT_INACTIVE.equals(ue.getErrorCode())) {
            this.alreadyValidated = true;
        } else if (RESTCodes.UserErrorCode.ACCOUNT_ALREADY_VERIFIED.equals(ue.getErrorCode())) {
            this.alreadyRegistered = true;
        } else {
            this.userNotFound = true;
        }
    }
    return false;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FacesContext(javax.faces.context.FacesContext) PersistenceException(javax.persistence.PersistenceException) UserException(io.hops.hopsworks.exceptions.UserException) EJBException(javax.ejb.EJBException)

Example 15 with UserException

use of io.hops.hopsworks.exceptions.UserException in project hopsworks by logicalclocks.

the class ConfigureLdap method deleteRemoteUserFromAllProjects.

public void deleteRemoteUserFromAllProjects(Users user) {
    RemoteUser remoteUser = remoteUserFacade.findByUsers(user);
    try {
        ldapConfigHelper.getRemoteGroupMappingHelper().removeFromAllProjects(remoteUser);
        initRemoteUsers();
        MessagesController.addInfoMessage("Removing user from all projects completed with success.");
    } catch (UserException e) {
        MessagesController.addErrorMessage(e.getMessage());
    }
}
Also used : RemoteUser(io.hops.hopsworks.persistence.entity.remote.user.RemoteUser) 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