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;
}
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;
}
Aggregations