use of org.candlepin.auth.UpdateConsumerCheckIn in project candlepin by candlepin.
the class ConsumerResource method regenerateEntitlementCertificates.
@ApiOperation(notes = "Regenerates the Entitlement Certificates for a Consumer", value = "regenerateEntitlementCertificates")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@PUT
@Produces(MediaType.WILDCARD)
@Consumes(MediaType.WILDCARD)
@Path("/{consumer_uuid}/certificates")
@UpdateConsumerCheckIn
public void regenerateEntitlementCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("entitlement") String entitlementId, @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert regen", consumer);
return;
}
if (entitlementId != null) {
Entitlement e = verifyAndLookupEntitlement(entitlementId);
poolManager.regenerateCertificatesOf(e, lazyRegen);
} else {
poolManager.regenerateCertificatesOf(consumer, lazyRegen);
}
}
use of org.candlepin.auth.UpdateConsumerCheckIn in project candlepin by candlepin.
the class ConsumerResource method getEntitlementCertificates.
@ApiOperation(notes = "Retrieves a list of Entitlement Certificates for the Consumer", value = "getEntitlementCertificates")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates")
@Produces(MediaType.APPLICATION_JSON)
@UpdateConsumerCheckIn
public List<CertificateDTO> getEntitlementCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("serials") String serials) {
log.debug("Getting client certificates for consumer: {}", consumerUuid);
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert fetch", consumer);
return new ArrayList<>();
}
revokeOnGuestMigration(consumer);
poolManager.regenerateDirtyEntitlements(consumer);
Set<Long> serialSet = this.extractSerials(serials);
List<CertificateDTO> returnCerts = new LinkedList<>();
List<EntitlementCertificate> allCerts = entCertService.listForConsumer(consumer);
for (EntitlementCertificate cert : allCerts) {
if (serialSet.isEmpty() || serialSet.contains(cert.getSerial().getId())) {
returnCerts.add(translator.translate(cert, CertificateDTO.class));
}
}
// we want to insert the content access cert to this list if appropriate
try {
Certificate cert = contentAccessCertService.getCertificate(consumer);
if (cert != null) {
returnCerts.add(translator.translate(cert, CertificateDTO.class));
}
} catch (IOException ioe) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
} catch (GeneralSecurityException gse) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), gse);
}
return returnCerts;
}
use of org.candlepin.auth.UpdateConsumerCheckIn in project candlepin by candlepin.
the class ConsumerResource method getEntitlementCertificateSerials.
@ApiOperation(notes = "Retrieves a list of Certiticate Serials Return the " + "client certificate metadata a for the given consumer. This is a small" + " subset of data clients can use to determine which certificates they" + " need to update/fetch.", value = "getEntitlementCertificateSerials")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates/serials")
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "serials")
@UpdateConsumerCheckIn
public List<CertificateSerialDto> getEntitlementCertificateSerials(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid) {
log.debug("Getting client certificate serials for consumer: {}", consumerUuid);
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert serial fetch", consumer);
return new ArrayList<>();
}
revokeOnGuestMigration(consumer);
poolManager.regenerateDirtyEntitlements(consumer);
List<CertificateSerialDto> allCerts = new LinkedList<>();
for (Long id : entCertService.listEntitlementSerialIds(consumer)) {
allCerts.add(new CertificateSerialDto(id));
}
// add content access cert if needed
try {
ContentAccessCertificate cac = contentAccessCertService.getCertificate(consumer);
if (cac != null) {
allCerts.add(new CertificateSerialDto(cac.getSerial().getId()));
}
} catch (IOException ioe) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
} catch (GeneralSecurityException gse) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate", gse));
}
return allCerts;
}
use of org.candlepin.auth.UpdateConsumerCheckIn in project candlepin by candlepin.
the class HypervisorResource method hypervisorUpdateAsync.
@ApiOperation(notes = "Creates or Updates the list of Hypervisor hosts Allows agents such" + " as virt-who to update hosts' information . This is typically used when a host is" + " unable to register to candlepin via subscription manager. In situations where " + "consumers already exist it is probably best not to allow creation of new hypervisor" + " consumers. Most consumers do not have a hypervisorId attribute, so that should be" + " added manually when necessary by the management environment. Default is true. " + "If false is specified, hypervisorIds that are not found will result in a failed " + "state of the job.", value = "hypervisorUpdateAsync")
@ApiResponses({ @ApiResponse(code = 202, message = "") })
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@Path("/{owner}")
@UpdateConsumerCheckIn
@SuppressWarnings("checkstyle:indentation")
public JobDetail hypervisorUpdateAsync(String hypervisorJson, @Context Principal principal, @PathParam("owner") @Verify(value = Owner.class, require = Access.READ_ONLY, subResource = SubResource.HYPERVISOR) String ownerKey, @ApiParam("specify whether or not to create missing hypervisors." + "Default is true. If false is specified, hypervisorIds that are not found" + "will result in failed entries in the resulting HypervisorCheckInResult") @QueryParam("create_missing") @DefaultValue("true") boolean createMissing, @QueryParam("reporter_id") String reporterId) {
if (hypervisorJson == null || hypervisorJson.isEmpty()) {
log.debug("Host/Guest mapping provided during hypervisor update was null.");
throw new BadRequestException(i18n.tr("Host to guest mapping was not provided for hypervisor update."));
}
log.info("Hypervisor update by principal: " + principal);
Owner owner = this.getOwner(ownerKey);
return HypervisorUpdateJob.forOwner(owner, hypervisorJson, createMissing, principal, reporterId);
}
use of org.candlepin.auth.UpdateConsumerCheckIn in project candlepin by candlepin.
the class ConsumerResource method updateConsumer.
// While this is a PUT, we are treating it as a PATCH until this operation
// becomes more prevalent. We only update the portions of the consumer that appear
// to be set.
@ApiOperation(notes = "Updates a Consumer", value = "updateConsumer")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{consumer_uuid}")
@Transactional
@UpdateConsumerCheckIn
public void updateConsumer(@PathParam("consumer_uuid") @Verify(Consumer.class) String uuid, @ApiParam(name = "consumer", required = true) ConsumerDTO dto, @Context Principal principal) {
Consumer toUpdate = consumerCurator.verifyAndLookupConsumer(uuid);
dto.setUuid(uuid);
// Sanitize the inbound facts before applying the update
this.sanitizeConsumerFacts(dto);
ConsumerType toUpdateType = this.consumerTypeCurator.getConsumerType(toUpdate);
if (toUpdateType.isType(ConsumerTypeEnum.SHARE)) {
validateShareConsumerUpdate(toUpdate, dto, principal);
}
GuestMigration guestMigration = migrationProvider.get();
guestMigration.buildMigrationManifest(dto, toUpdate);
if (performConsumerUpdates(dto, toUpdate, guestMigration)) {
try {
if (guestMigration.isMigrationPending()) {
guestMigration.migrate();
} else {
consumerCurator.update(toUpdate);
}
} catch (CandlepinException ce) {
// If it is one of ours, rethrow it.
throw ce;
} catch (Exception e) {
log.error("Problem updating unit:", e);
throw new BadRequestException(i18n.tr("Problem updating unit {0}", dto));
}
}
}
Aggregations