Search in sources :

Example 1 with CertificateSizeException

use of org.candlepin.util.CertificateSizeException in project candlepin by candlepin.

the class EntitlementCertificateGenerator method regenerateCertificatesOf.

/**
 * Regenerates the certificates for the specified entitlement.
 *
 * @param entitlement
 *  The entitlement for which to regenerate certificates
 *
 * @param lazy
 *  Whether or not to generate the certificate immediately, or mark it dirty and allow it to be
 *  regenerated on-demand
 */
@Transactional
public void regenerateCertificatesOf(Entitlement entitlement, boolean lazy) {
    if (lazy) {
        log.info("Marking certificates dirty for entitlement: {}", entitlement);
        entitlement.setDirty(true);
        return;
    }
    log.debug("Revoking entitlementCertificates of: {}", entitlement);
    Entitlement tempE = new Entitlement();
    tempE.setCertificates(entitlement.getCertificates());
    entitlement.setCertificates(null);
    // below call creates new certificates and saves it to the backend.
    try {
        EntitlementCertificate generated = this.generateEntitlementCertificate(entitlement.getPool(), entitlement);
        entitlement.setDirty(false);
        this.entitlementCurator.merge(entitlement);
        for (EntitlementCertificate ec : tempE.getCertificates()) {
            log.debug("Deleting entitlementCertificate: #{}", ec.getId());
            this.entitlementCertificateCurator.delete(ec);
        }
        // send entitlement changed event.
        this.eventSink.queueEvent(this.eventFactory.entitlementChanged(entitlement));
        log.debug("Generated entitlementCertificate: #{}", generated.getId());
    } catch (CertificateSizeException cse) {
        entitlement.setCertificates(tempE.getCertificates());
        log.warn("The certificate cannot be regenerated at this time: {}", cse.getMessage());
    }
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSizeException(org.candlepin.util.CertificateSizeException) Entitlement(org.candlepin.model.Entitlement) Transactional(com.google.inject.persist.Transactional)

Example 2 with CertificateSizeException

use of org.candlepin.util.CertificateSizeException in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapter method prepareV1Extensions.

public Set<X509ExtensionWrapper> prepareV1Extensions(Set<Product> products, Pool pool, Consumer consumer, Integer quantity, String contentPrefix, Map<String, EnvironmentContent> promotedContent) {
    Set<X509ExtensionWrapper> result = new LinkedHashSet<>();
    Set<String> entitledProductIds = entCurator.listEntitledProductIds(consumer, pool);
    int contentCounter = 0;
    boolean enableEnvironmentFiltering = config.getBoolean(ConfigProperties.ENV_CONTENT_FILTERING);
    Product skuProd = pool.getProduct();
    for (Product prod : Collections2.filter(products, X509Util.PROD_FILTER_PREDICATE)) {
        log.debug("Adding X509 extensions for product: {}", prod);
        result.addAll(extensionUtil.productExtensions(prod));
        Set<ProductContent> filteredContent = extensionUtil.filterProductContent(prod, consumer, promotedContent, enableEnvironmentFiltering, entitledProductIds);
        filteredContent = extensionUtil.filterContentByContentArch(filteredContent, consumer, prod);
        // Keep track of the number of content sets that are being added.
        contentCounter += filteredContent.size();
        log.debug("Adding X509 extensions for content: {}", filteredContent);
        result.addAll(extensionUtil.contentExtensions(filteredContent, contentPrefix, promotedContent, consumer, skuProd));
    }
    // informative error message to the user.
    if (contentCounter > X509ExtensionUtil.V1_CONTENT_LIMIT) {
        String cause = i18n.tr("Too many content sets for certificate {0}. A newer " + "client may be available to address this problem. " + "See knowledge database https://access.redhat.com/knowledge/node/129003 for more " + "information.", pool.getProductName());
        throw new CertificateSizeException(cause);
    }
    result.addAll(extensionUtil.subscriptionExtensions(pool));
    result.addAll(extensionUtil.entitlementExtensions(quantity));
    result.addAll(extensionUtil.consumerExtensions(consumer));
    if (log.isDebugEnabled()) {
        for (X509ExtensionWrapper eWrapper : result) {
            log.debug("Extension {} with value {}", eWrapper.getOid(), eWrapper.getValue());
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CertificateSizeException(org.candlepin.util.CertificateSizeException) Product(org.candlepin.model.Product) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) ProductContent(org.candlepin.model.ProductContent)

Aggregations

CertificateSizeException (org.candlepin.util.CertificateSizeException)2 Transactional (com.google.inject.persist.Transactional)1 LinkedHashSet (java.util.LinkedHashSet)1 Entitlement (org.candlepin.model.Entitlement)1 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)1 Product (org.candlepin.model.Product)1 ProductContent (org.candlepin.model.ProductContent)1 X509ExtensionWrapper (org.candlepin.pki.X509ExtensionWrapper)1