Search in sources :

Example 16 with EnvironmentContent

use of org.candlepin.model.EnvironmentContent in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapter method createX509Certificate.

// TODO: productModels not used by V1 certificates. This whole v1/v3 split needs
// a re-org. Passing them here because it eliminates a substantial performance hit
// recalculating this for the entitlement body in v3 certs.
public X509Certificate createX509Certificate(Consumer consumer, Owner owner, Pool pool, Entitlement ent, Product product, Set<Product> products, List<org.candlepin.model.dto.Product> productModels, BigInteger serialNumber, KeyPair keyPair, boolean useContentPrefix) throws GeneralSecurityException, IOException {
    // oidutil is busted at the moment, so do this manually
    Set<X509ExtensionWrapper> extensions;
    Set<X509ByteExtensionWrapper> byteExtensions = new LinkedHashSet<>();
    products.add(product);
    Map<String, EnvironmentContent> promotedContent = getPromotedContent(consumer);
    String contentPrefix = getContentPrefix(consumer, owner, useContentPrefix);
    if (shouldGenerateV3(consumer)) {
        extensions = prepareV3Extensions();
        byteExtensions = prepareV3ByteExtensions(product, productModels, contentPrefix, promotedContent);
    } else {
        extensions = prepareV1Extensions(products, pool, consumer, ent.getQuantity(), contentPrefix, promotedContent);
    }
    Date endDate = setupEntitlementEndDate(pool, consumer);
    ent.setEndDateOverride(endDate);
    Calendar calNow = Calendar.getInstance();
    Calendar calMinusHour = Calendar.getInstance();
    calMinusHour.add(Calendar.HOUR, -1);
    Date startDate = pool.getStartDate();
    if (pool.getStartDate().getTime() > calMinusHour.getTime().getTime() && pool.getStartDate().getTime() < calNow.getTime().getTime()) {
        startDate = calMinusHour.getTime();
    }
    X509Certificate x509Cert = this.pki.createX509Certificate(createDN(ent, owner), extensions, byteExtensions, startDate, endDate, keyPair, serialNumber, null);
    return x509Cert;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Calendar(java.util.Calendar) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) EnvironmentContent(org.candlepin.model.EnvironmentContent) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate)

Example 17 with EnvironmentContent

use of org.candlepin.model.EnvironmentContent in project candlepin by candlepin.

the class EnvironmentResource method promoteContent.

@ApiOperation(notes = "Promotes a Content into an Environment. This call accepts multiple " + "content sets to promote at once, after which all affected certificates for consumers" + " in the environment will be regenerated. Consumers registered to this environment " + "will now receive this content in their entitlement certificates. Because the" + " certificate regeneraiton can be quite time consuming, this is done as an " + "asynchronous job. The content will be promoted and immediately available for new " + "entitlements, but existing entitlements could take some time to be regenerated and " + "sent down to clients as they check in.", value = "promoteContent")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{env_id}/content")
public JobDetail promoteContent(@PathParam("env_id") @Verify(Environment.class) String envId, @ApiParam(name = "contentToPromote", required = true) List<org.candlepin.model.dto.EnvironmentContent> contentToPromote, @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen) {
    Environment env = lookupEnvironment(envId);
    // there be a problem with the request.
    for (org.candlepin.model.dto.EnvironmentContent promoteMe : contentToPromote) {
        log.debug("EnvironmentContent to promote: {}:{}", promoteMe.getEnvironmentId(), promoteMe.getContentId());
        EnvironmentContent existing = this.envContentCurator.lookupByEnvironmentAndContent(env, promoteMe.getContentId());
        if (existing != null) {
            throw new ConflictException(i18n.tr("The content with id {0} has already been promoted in this environment.", promoteMe.getContentId()));
        }
    }
    Set<String> contentIds = new HashSet<>();
    try {
        contentIds = batchCreate(contentToPromote, env);
        clearContentAccessCerts(env);
    } catch (PersistenceException pe) {
        if (rdbmsExceptionTranslator.isConstraintViolationDuplicateEntry(pe)) {
            log.info("Concurrent content promotion will cause this request to fail.", pe);
            throw new ConflictException(i18n.tr("Some of the content is already associated with Environment: {0}", contentToPromote));
        } else {
            throw pe;
        }
    }
    JobDataMap map = new JobDataMap();
    map.put(RegenEnvEntitlementCertsJob.ENV, env);
    map.put(RegenEnvEntitlementCertsJob.CONTENT, contentIds);
    map.put(RegenEnvEntitlementCertsJob.LAZY_REGEN, lazyRegen);
    JobDetail detail = newJob(RegenEnvEntitlementCertsJob.class).withIdentity("regen_entitlement_cert_of_env" + Util.generateUUID()).usingJobData(map).build();
    return detail;
}
Also used : JobDataMap(org.quartz.JobDataMap) ConflictException(org.candlepin.common.exceptions.ConflictException) EnvironmentContent(org.candlepin.model.EnvironmentContent) JobDetail(org.quartz.JobDetail) RegenEnvEntitlementCertsJob(org.candlepin.pinsetter.tasks.RegenEnvEntitlementCertsJob) PersistenceException(javax.persistence.PersistenceException) Environment(org.candlepin.model.Environment) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)9 Environment (org.candlepin.model.Environment)9 HashMap (java.util.HashMap)6 Content (org.candlepin.model.Content)6 Date (java.util.Date)4 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KeyPair (java.security.KeyPair)3 Entitlement (org.candlepin.model.Entitlement)3 Product (org.candlepin.model.Product)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 BigInteger (java.math.BigInteger)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2