Search in sources :

Example 1 with RepositoryInvalidInputException

use of com.intel.mtwilson.tag.repository.RepositoryInvalidInputException in project OpenAttestation by OpenAttestation.

the class MtWilsonImportTagCertificate method run.

@Override
@RequiresPermissions("tag_certificates:import")
public void run() {
    log.debug("RPC:MtWilsonImportTagCertificate - Got request to deploy certificate with ID {}.", certificateId);
    CertificateLocator locator = new CertificateLocator();
    locator.id = certificateId;
    try (CertificateDAO dao = TagJdbi.certificateDao()) {
        Certificate obj = dao.findById(certificateId);
        if (obj != null) {
            log.debug("RPC:MtWilsonImportTagCertificate - Sha1 of the certificate about to be deployed is {}.", obj.getSha1());
            AssetTagCertCreateRequest request = new AssetTagCertCreateRequest();
            request.setCertificate(obj.getCertificate());
            Global.mtwilson().importAssetTagCertificate(request);
            log.info("RPC:MtWilsonImportTagCertificate - Certificate with id {} has been deployed successfully.");
        } else {
            log.error("RPC:MtWilsonImportTagCertificate - Specified Certificate with id {} is not valid.", certificateId);
            throw new RepositoryInvalidInputException(locator);
        }
    } catch (RepositoryException re) {
        throw re;
    } catch (Exception ex) {
        log.error("RPC:MtWilsonImportTagCertificate - Error during certificate deployment.", ex);
        throw new RepositoryException(ex);
    }
}
Also used : CertificateLocator(com.intel.mtwilson.datatypes.CertificateLocator) CertificateDAO(com.intel.mtwilson.tag.dao.jdbi.CertificateDAO) AssetTagCertCreateRequest(com.intel.mtwilson.datatypes.AssetTagCertCreateRequest) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) Certificate(com.intel.mtwilson.datatypes.Certificate) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions)

Example 2 with RepositoryInvalidInputException

use of com.intel.mtwilson.tag.repository.RepositoryInvalidInputException 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

Certificate (com.intel.mtwilson.datatypes.Certificate)2 CertificateLocator (com.intel.mtwilson.datatypes.CertificateLocator)2 CertificateDAO (com.intel.mtwilson.tag.dao.jdbi.CertificateDAO)2 RepositoryException (com.intel.mtwilson.tag.repository.RepositoryException)2 RepositoryInvalidInputException (com.intel.mtwilson.tag.repository.RepositoryInvalidInputException)2 ApiClient (com.intel.mtwilson.ApiClient)1 AssetTagCertCreateRequest (com.intel.mtwilson.datatypes.AssetTagCertCreateRequest)1 AssetTagCertRevokeRequest (com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1