Search in sources :

Example 1 with ClusterCert

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

the class ClusterController method registerClusterWithUser.

public void registerClusterWithUser(ClusterDTO cluster, HttpServletRequest req, boolean autoValidate) throws MessagingException, UserException {
    isValidCluster(cluster);
    Optional<Users> clusterAgent = verifyClusterAgent(cluster, req);
    if (!clusterAgent.isPresent()) {
        throw new IllegalArgumentException("User not registerd.");
    }
    ClusterCert clusterCert = createClusterCert(cluster, clusterAgent.get());
    if (autoValidate) {
        autoActivateCluster(clusterCert);
    } else {
        sendEmail(cluster, req, clusterCert.getId() + clusterCert.getValidationKey(), clusterAgent.get(), "REGISTRATION");
    }
    LOGGER.log(Level.INFO, "New cluster added with email: {0}, and username: {1}", new Object[] { clusterAgent.get().getEmail(), clusterAgent.get().getUsername() });
}
Also used : ClusterCert(io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert) Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 2 with ClusterCert

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

the class ClusterController method getCluster.

public ClusterCert getCluster(ClusterDTO cluster, HttpServletRequest req) throws UserException {
    isValidCluster(cluster);
    Users clusterAgent = userBean.findByEmail(cluster.getEmail());
    if (clusterAgent == null) {
        throw new IllegalArgumentException("Cluster not registerd.");
    }
    checkUserPasswordAndStatus(cluster, clusterAgent, req);
    ClusterCert clusterCert = clusterCertFacade.getByOrgUnitNameAndOrgName(cluster.getOrganizationName(), cluster.getOrganizationalUnitName());
    if (clusterCert == null) {
        throw new IllegalArgumentException("Cluster not registerd.");
    }
    return clusterCert;
}
Also used : ClusterCert(io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert) Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 3 with ClusterCert

use of io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert 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 4 with ClusterCert

use of io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert 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 5 with ClusterCert

use of io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert 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

ClusterCert (io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert)11 Users (io.hops.hopsworks.persistence.entity.user.Users)7 Date (java.util.Date)3 ClusterYmlDTO (io.hops.hopsworks.cluster.ClusterYmlDTO)1 CSR (io.hops.hopsworks.common.security.CSR)1 DelaCSRCheckException (io.hops.hopsworks.exceptions.DelaCSRCheckException)1 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 X500Name (org.bouncycastle.asn1.x500.X500Name)1