Search in sources :

Example 1 with CSR

use of io.hops.hopsworks.common.security.CSR in project hopsworks by logicalclocks.

the class DelaTrackerCertController method signCsr.

public CSR signCsr(String userEmail, CSR csr) throws IOException, HopsSecurityException, GenericException, DelaCSRCheckException {
    ClusterCert clusterCert = checkCSR(userEmail, csr);
    CSR signedCert = certificatesController.signDelaClusterCertificate(csr);
    String certSerialNumber;
    try {
        certSerialNumber = String.valueOf(certificatesController.extractSerialNumberFromCert(signedCert.getSignedCert()));
    } catch (CertificateException e) {
        throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CERT_CREATION_ERROR, Level.WARNING, null, null, e);
    }
    clusterCert.setSerialNumber(certSerialNumber);
    clusterCertFacade.update(clusterCert);
    return signedCert;
}
Also used : CSR(io.hops.hopsworks.common.security.CSR) ClusterCert(io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert) CertificateException(java.security.cert.CertificateException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException)

Example 2 with CSR

use of io.hops.hopsworks.common.security.CSR in project hopsworks by logicalclocks.

the class CAProxy method signCSR.

private CSR signCSR(CSR csr, CA_PATH path) throws HopsSecurityException, GenericException {
    try {
        String csrJSON = objectMapper.writeValueAsString(csr);
        HttpPost httpRequest = new HttpPost(path.path);
        httpRequest.setHeader(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE_JSON);
        client.setAuthorizationHeader(httpRequest);
        httpRequest.setEntity(new StringEntity(csrJSON));
        HttpRetryableAction<CSR> retryableAction = new HttpRetryableAction<CSR>() {

            @Override
            public CSR performAction() throws ClientProtocolException, IOException {
                return client.execute(httpRequest, CA_SIGN_RESPONSE_HANDLER);
            }
        };
        return retryableAction.tryAction();
    } catch (JsonProcessingException ex) {
        throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CSR_ERROR, Level.SEVERE, null, null, ex);
    } catch (ClientProtocolException ex) {
        LOG.log(Level.SEVERE, "Could not sign CSR", ex);
        throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CSR_ERROR, Level.SEVERE, null, null, ex.getCause());
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, "Could not sign CSR", ex);
        throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, "Generic error while signing CSR", null, ex);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CSR(io.hops.hopsworks.common.security.CSR) HttpRetryableAction(io.hops.hopsworks.common.proxies.client.HttpRetryableAction) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GenericException(io.hops.hopsworks.exceptions.GenericException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) ClientProtocolException(org.apache.http.client.ClientProtocolException) NotRetryableClientProtocolException(io.hops.hopsworks.common.proxies.client.NotRetryableClientProtocolException)

Example 3 with CSR

use of io.hops.hopsworks.common.security.CSR in project hopsworks by logicalclocks.

the class Cluster method singCertificate.

@POST
@Path("certificate")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RolesAllowed({ "CLUSTER_AGENT" })
public Response singCertificate(CSR csr, @Context HttpServletRequest req) throws HopsSecurityException, GenericException, DelaCSRCheckException, IOException {
    String userEmail = req.getUserPrincipal().getName();
    CSR signedCSR = delaTrackerCertController.signCsr(userEmail, csr);
    return Response.ok().entity(signedCSR).build();
}
Also used : CSR(io.hops.hopsworks.common.security.CSR) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

CSR (io.hops.hopsworks.common.security.CSR)3 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HttpRetryableAction (io.hops.hopsworks.common.proxies.client.HttpRetryableAction)1 NotRetryableClientProtocolException (io.hops.hopsworks.common.proxies.client.NotRetryableClientProtocolException)1 GenericException (io.hops.hopsworks.exceptions.GenericException)1 ClusterCert (io.hops.hopsworks.persistence.entity.user.cluster.ClusterCert)1 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1