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() });
}
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;
}
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);
}
}
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() });
}
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;
}
Aggregations