Search in sources :

Example 1 with UpdateConsumerCheckIn

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);
    }
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 2 with UpdateConsumerCheckIn

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;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinkedList(java.util.LinkedList) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) IdentityCertificate(org.candlepin.model.IdentityCertificate) Certificate(org.candlepin.model.Certificate) ContentAccessCertificate(org.candlepin.model.ContentAccessCertificate) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with UpdateConsumerCheckIn

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;
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) CertificateSerialDto(org.candlepin.model.CertificateSerialDto) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ContentAccessCertificate(org.candlepin.model.ContentAccessCertificate) IOException(java.io.IOException) ConsumerType(org.candlepin.model.ConsumerType) LinkedList(java.util.LinkedList) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Wrapped(org.jboss.resteasy.annotations.providers.jaxb.Wrapped) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with UpdateConsumerCheckIn

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);
}
Also used : Owner(org.candlepin.model.Owner) BadRequestException(org.candlepin.common.exceptions.BadRequestException) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) Transactional(com.google.inject.persist.Transactional)

Example 5 with UpdateConsumerCheckIn

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));
        }
    }
}
Also used : GuestMigration(org.candlepin.resource.util.GuestMigration) CandlepinException(org.candlepin.common.exceptions.CandlepinException) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) GeneralSecurityException(java.security.GeneralSecurityException) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) IseException(org.candlepin.common.exceptions.IseException) AutobindDisabledForOwnerException(org.candlepin.controller.AutobindDisabledForOwnerException) CandlepinException(org.candlepin.common.exceptions.CandlepinException) IOException(java.io.IOException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ExportCreationException(org.candlepin.sync.ExportCreationException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) PropertyValidationException(org.candlepin.util.PropertyValidationException) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT) Transactional(com.google.inject.persist.Transactional)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6 UpdateConsumerCheckIn (org.candlepin.auth.UpdateConsumerCheckIn)6 Path (javax.ws.rs.Path)5 BadRequestException (org.candlepin.common.exceptions.BadRequestException)5 Consumer (org.candlepin.model.Consumer)5 Consumes (javax.ws.rs.Consumes)4 ConsumerType (org.candlepin.model.ConsumerType)4 DeletedConsumer (org.candlepin.model.DeletedConsumer)4 Transactional (com.google.inject.persist.Transactional)3 IOException (java.io.IOException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 ContentAccessCertificate (org.candlepin.model.ContentAccessCertificate)2