Search in sources :

Example 31 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class ClusterController method validateRequest.

public void validateRequest(String key, HttpServletRequest req, OP_TYPE type) throws HopsSecurityException, GenericException {
    Integer clusterCertId = extractClusterCertId(key);
    ClusterCert clusterCert = clusterCertFacade.find(clusterCertId);
    if (clusterCert == null) {
        throw new IllegalStateException("Agent not found.");
    }
    long diff = getDateDiffHours(clusterCert.getValidationKeyDate());
    String validationKey = extractValidationKey(key);
    Users agent = clusterCert.getAgentId();
    if (agent == null) {
        throw new IllegalStateException("Agent not found.");
    }
    if (!validationKey.equals(clusterCert.getValidationKey())) {
        throw new IllegalStateException("Validation key not found.");
    }
    if (diff > VALIDATION_KEY_EXPIRY_DATE) {
        removeUserIfNotValidated(agent);
        throw new IllegalStateException("Expired valdation key.");
    }
    if (type.equals(OP_TYPE.REGISTER) && clusterCert.getRegistrationStatus().equals(RegistrationStatusEnum.REGISTRATION_PENDING)) {
        if (agent.getStatus() == UserAccountStatus.NEW_MOBILE_ACCOUNT) {
            agent.setStatus(UserAccountStatus.ACTIVATED_ACCOUNT);
            userBean.update(agent);
        }
        clusterCert.setValidationKey(null);
        clusterCert.setValidationKeyDate(null);
        clusterCert.setRegistrationStatus(RegistrationStatusEnum.REGISTERED);
        clusterCertFacade.update(clusterCert);
    } else if (clusterCert.getRegistrationStatus().equals(RegistrationStatusEnum.UNREGISTRATION_PENDING)) {
        revokeCert(clusterCert);
        removeClusterCert(clusterCert);
    }
}
Also used : ClusterCert(io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert) Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 32 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class ClusterController method activateClusterAgent.

private void activateClusterAgent(ClusterDTO cluster) {
    Users clusterAgent = userBean.findByEmail(cluster.getEmail());
    if (clusterAgent == null) {
        throw new IllegalArgumentException("Cluster not registerd.");
    }
    if (clusterAgent.getStatus().equals(UserAccountStatus.ACTIVATED_ACCOUNT)) {
        return;
    }
    if (clusterAgent.getStatus().equals(UserAccountStatus.NEW_MOBILE_ACCOUNT)) {
        clusterAgent.setStatus(UserAccountStatus.ACTIVATED_ACCOUNT);
        userBean.update(clusterAgent);
        return;
    }
    throw new IllegalStateException("Trying to activate account in state:" + clusterAgent.getStatus());
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 33 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class ClusterController method registerClusterNewUser.

public void registerClusterNewUser(ClusterDTO cluster, HttpServletRequest req, boolean autoValidate) throws MessagingException, UserException {
    isValidNewCluster(cluster);
    Users clusterAgent = createClusterAgent(cluster, req);
    ClusterCert clusterCert = createClusterCert(cluster, clusterAgent);
    if (autoValidate) {
        activateClusterAgent(cluster);
        autoActivateCluster(clusterCert);
    } else {
        sendEmail(cluster, req, clusterCert.getId() + clusterCert.getValidationKey(), clusterAgent, "REGISTRATION");
    }
    LOGGER.log(Level.INFO, "New cluster added with email: {0}, and username: {1}", new Object[] { clusterAgent.getEmail(), clusterAgent.getUsername() });
}
Also used : ClusterCert(io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert) Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 34 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class ClusterController method getAllClusters.

public List<ClusterCert> getAllClusters(ClusterDTO cluster, HttpServletRequest req) throws UserException {
    if (cluster == null) {
        throw new NullPointerException("Cluster not assigned.");
    }
    if (cluster.getEmail() == null || cluster.getEmail().isEmpty()) {
        throw new IllegalArgumentException("Cluster email not set.");
    }
    if (cluster.getChosenPassword() == null || cluster.getChosenPassword().isEmpty()) {
        throw new IllegalArgumentException("Cluster password not set.");
    }
    Users clusterAgent = userBean.findByEmail(cluster.getEmail());
    if (clusterAgent == null) {
        throw new IllegalArgumentException("No registerd cluster found for user.");
    }
    checkUserPasswordAndStatus(cluster, clusterAgent, req);
    return clusterCertFacade.getByAgent(clusterAgent);
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 35 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class ClusterController method getAllClusterYml.

public List<ClusterYmlDTO> getAllClusterYml(ClusterDTO cluster, HttpServletRequest req) throws UserException {
    if (cluster == null) {
        throw new NullPointerException("Cluster not assigned.");
    }
    if (cluster.getEmail() == null || cluster.getEmail().isEmpty()) {
        throw new IllegalArgumentException("Cluster email not set.");
    }
    if (cluster.getChosenPassword() == null || cluster.getChosenPassword().isEmpty()) {
        throw new IllegalArgumentException("Cluster password not set.");
    }
    Users clusterAgent = userBean.findByEmail(cluster.getEmail());
    if (clusterAgent == null) {
        throw new IllegalArgumentException("No registerd cluster found for user.");
    }
    checkUserPasswordAndStatus(cluster, clusterAgent, req);
    List<ClusterCert> clusterCerts = clusterCertFacade.getByAgent(clusterAgent);
    List<ClusterYmlDTO> clusterYmlDTOs = new ArrayList<>();
    for (ClusterCert cCert : clusterCerts) {
        clusterYmlDTOs.add(new ClusterYmlDTO(cCert.getAgentId().getEmail(), cCert.getCommonName(), cCert.getOrganizationName(), cCert.getOrganizationalUnitName(), cCert.getRegistrationStatus(), cCert.getRegistrationDate(), cCert.getSerialNumber()));
    }
    return clusterYmlDTOs;
}
Also used : ClusterYmlDTO(io.hops.hopsworks.cluster.ClusterYmlDTO) ArrayList(java.util.ArrayList) ClusterCert(io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert) Users(io.hops.hopsworks.persistence.entity.user.Users)

Aggregations

Users (io.hops.hopsworks.persistence.entity.user.Users)325 Produces (javax.ws.rs.Produces)195 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)169 Path (javax.ws.rs.Path)167 ApiOperation (io.swagger.annotations.ApiOperation)158 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)150 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)116 GET (javax.ws.rs.GET)86 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)78 POST (javax.ws.rs.POST)65 Consumes (javax.ws.rs.Consumes)52 Project (io.hops.hopsworks.persistence.entity.project.Project)48 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)44 DELETE (javax.ws.rs.DELETE)34 UserException (io.hops.hopsworks.exceptions.UserException)33 PUT (javax.ws.rs.PUT)33 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)26 GenericEntity (javax.ws.rs.core.GenericEntity)24 RESTApiJsonResponse (io.hops.hopsworks.api.util.RESTApiJsonResponse)21 IOException (java.io.IOException)21