Search in sources :

Example 1 with AssetTagCertRevokeRequest

use of com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest in project OpenAttestation by OpenAttestation.

the class RevokeTagCertificate method revokeCert.

@POST
public //@RequiresPermissions("tag_certificates:delete")         
void revokeCert(@QueryParam("certId") String certId) {
    log.debug("RPC: RevokeTagCertificate - Got request to revocation of certificate: {}", certId);
    setCertificateId(UUID.valueOf(certId));
    try (CertificateDAO dao = TagJdbi.certificateDao()) {
        CertificateLocator locator = new CertificateLocator();
        locator.id = certificateId;
        Certificate obj = dao.findById(certificateId);
        if (obj != null) {
            // tries jvm properties, environment variables, then mtwilson.properties;  you can set location of mtwilson.properties with -Dmtwilson.home=/path/to/dir
            org.apache.commons.configuration.Configuration conf = ConfigurationUtil.getConfiguration();
            ApiClient mtwilson = new ApiClient(conf);
            log.debug("RPC: RevokeTagCertificate - Sha1 of the certificate about to be revoked is {}.", obj.getSha1());
            dao.updateRevoked(certificateId, true);
            AssetTagCertRevokeRequest request = new AssetTagCertRevokeRequest();
            request.setSha1OfAssetCert(obj.getSha1().toByteArray());
            mtwilson.revokeAssetTagCertificate(request);
            //Global.mtwilson().revokeAssetTagCertificate(request);
            log.info("RPC: RevokeTagCertificate - Certificate with id {} has been revoked successfully.");
        } else {
            log.error("RPC: RevokeTagCertificate - Certificate with id {} does not exist.", certificateId);
            throw new RepositoryInvalidInputException(locator);
        }
    } catch (RepositoryException re) {
        throw re;
    } catch (Exception ex) {
        log.error("RPC: RevokeTagCertificate - Error during certificate revocation.", ex);
        throw new RepositoryException(ex);
    }
}
Also used : CertificateLocator(com.intel.mtwilson.datatypes.CertificateLocator) AssetTagCertRevokeRequest(com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest) CertificateDAO(com.intel.mtwilson.tag.dao.jdbi.CertificateDAO) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) ApiClient(com.intel.mtwilson.ApiClient) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) WebApplicationException(javax.ws.rs.WebApplicationException) Certificate(com.intel.mtwilson.datatypes.Certificate) POST(javax.ws.rs.POST)

Aggregations

ApiClient (com.intel.mtwilson.ApiClient)1 AssetTagCertRevokeRequest (com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest)1 Certificate (com.intel.mtwilson.datatypes.Certificate)1 CertificateLocator (com.intel.mtwilson.datatypes.CertificateLocator)1 CertificateDAO (com.intel.mtwilson.tag.dao.jdbi.CertificateDAO)1 RepositoryException (com.intel.mtwilson.tag.repository.RepositoryException)1 RepositoryInvalidInputException (com.intel.mtwilson.tag.repository.RepositoryInvalidInputException)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1