Search in sources :

Example 81 with ConsumerType

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

the class ConsumerResource method regenerateIdentityCertificates.

/**
 * Retrieves a single Consumer
 *
 * @param uuid uuid of the consumer sought.
 * @return a Consumer object
 * @httpcode 400
 * @httpcode 404
 * @httpcode 200
 */
@ApiOperation(notes = "Retrieves a single Consumer", value = "regenerateIdentityCertificates")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") })
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.WILDCARD)
@Path("{consumer_uuid}")
public ConsumerDTO regenerateIdentityCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String uuid) {
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(uuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        logShareConsumerRequestWarning("regenerate identity certificate", consumer);
    } else {
        consumer = regenerateIdentityCertificate(consumer);
    }
    return translator.translate(consumer, ConsumerDTO.class);
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) 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)

Example 82 with ConsumerType

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

the class ConsumerResource method list.

@ApiOperation(notes = "Retrieves a list of the Consumers", value = "list", response = Consumer.class, responseContainer = "list")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "consumers")
@SuppressWarnings("checkstyle:indentation")
public CandlepinQuery<ConsumerDTO> list(@QueryParam("username") String userName, @QueryParam("type") Set<String> typeLabels, @QueryParam("owner") String ownerKey, @QueryParam("uuid") List<String> uuids, @QueryParam("hypervisor_id") List<String> hypervisorIds, @QueryParam("fact") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
    if (userName == null && (typeLabels == null || typeLabels.isEmpty()) && ownerKey == null && (uuids == null || uuids.isEmpty()) && (hypervisorIds == null || hypervisorIds.isEmpty()) && (attrFilters == null || attrFilters.isEmpty())) {
        throw new BadRequestException(i18n.tr("Must specify at least one search criteria."));
    }
    Owner owner = null;
    if (ownerKey != null) {
        owner = ownerCurator.lookupByKey(ownerKey);
        if (owner == null) {
            throw new NotFoundException(i18n.tr("owner with key: {0} was not found.", ownerKey));
        }
    }
    List<ConsumerType> types = consumerTypeValidator.findAndValidateTypeLabels(typeLabels);
    CandlepinQuery<Consumer> query = this.consumerCurator.searchOwnerConsumers(owner, userName, types, uuids, hypervisorIds, attrFilters, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
    return this.translator.translateQuery(query, ConsumerDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerType(org.candlepin.model.ConsumerType) 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 83 with ConsumerType

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

the class ConsumerResource method create.

@ApiOperation(notes = "Creates a Consumer. NOTE: Opening this method up " + "to everyone, as we have nothing we can reliably " + "verify in the method signature. Instead we have to " + "figure out what owner this consumer is destined for " + "(due to backward compatability with existing clients " + "which do not specify an owner during registration), " + "and then check the access to the specified owner in " + "the method itself.", value = "create")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") })
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@SecurityHole(noAuth = true)
@Transactional
public ConsumerDTO create(@ApiParam(name = "consumer", required = true) ConsumerDTO dto, @Context Principal principal, @QueryParam("username") String userName, @QueryParam("owner") String ownerKey, @QueryParam("activation_keys") String activationKeys, @QueryParam("identity_cert_creation") @DefaultValue("true") boolean identityCertCreation) throws BadRequestException {
    // fix for duplicate hypervisor/consumer problem
    Consumer consumer = null;
    if (ownerKey != null && dto.getFact("system_uuid") != null && !"true".equalsIgnoreCase(dto.getFact("virt.is_guest"))) {
        Owner owner = ownerCurator.lookupByKey(ownerKey);
        if (owner != null) {
            consumer = consumerCurator.getHypervisor(dto.getFact("system_uuid"), owner);
            if (consumer != null) {
                consumer.setIdCert(generateIdCert(consumer, false));
                this.updateConsumer(consumer.getUuid(), dto, principal);
                return translator.translate(consumer, ConsumerDTO.class);
            }
        }
    }
    if (consumer == null) {
        consumer = new Consumer();
    }
    if (dto.getUuid() != null) {
        consumer.setUuid(dto.getUuid());
    }
    consumer.setOwner(ownerCurator.lookupByKey(ownerKey));
    populateEntity(consumer, dto);
    if (dto.getType() == null) {
        throw new BadRequestException(i18n.tr("Unit type must be specified."));
    }
    ConsumerType ctype = this.consumerTypeCurator.lookupByLabel(dto.getType().getLabel());
    if (ctype == null) {
        throw new BadRequestException(i18n.tr("Invalid unit type: {0}", dto.getType().getLabel()));
    }
    return translator.translate(createConsumerFromDTO(dto, ctype, principal, userName, ownerKey, activationKeys, identityCertCreation), ConsumerDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) SecurityHole(org.candlepin.common.auth.SecurityHole) 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 84 with ConsumerType

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

the class ConsumerResource method exportDataAsync.

/**
 * Initiates an async generation of a compressed file representation of a {@link Consumer} (manifest).
 * The response will contain the id of the job from which its result data will contain the href to
 * download the generated file.
 *
 * @param response the response to send back from the server.
 * @param consumerUuid the uuid of the target consumer.
 * @param cdnLabel the CDN label to store in the meta file.
 * @param webAppPrefix the URL pointing to the manifest's originating web application.
 * @param apiUrl the API URL pointing to the manifest's originating candlepin API.
 * @return the details of the async export job that is to be started.
 */
@ApiOperation(notes = "Initiates an async generation of a Compressed File representation of a Consumer " + "(manifest). The response will contain the id of the job from which its result data " + " will contain the href to download the generated file.", value = "Async Consumer Export (manifest)", response = JobDetail.class)
@ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{consumer_uuid}/export/async")
public JobDetail exportDataAsync(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) @ApiParam(value = "The UUID of the target consumer", required = true) String consumerUuid, @QueryParam("cdn_label") @ApiParam(value = "The lable of the target CDN", required = false) String cdnLabel, @QueryParam("webapp_prefix") @ApiParam(value = "the URL pointing to the manifest's originating web application", required = false) String webAppPrefix, @QueryParam("api_url") @ApiParam(value = "the URL pointing to the manifest's originating candlepin API", required = false) String apiUrl, @QueryParam("ext") @CandlepinParam(type = KeyValueParameter.class) @ApiParam(value = "Key/Value pairs to be passed to the extension adapter when generating a manifest", required = false, example = "ext=version:1.2.3&ext=extension_key:EXT1") List<KeyValueParameter> extensionArgs) {
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        throw new BadRequestException(i18n.tr("Can not export manifest of a share consumer"));
    }
    Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
    return manifestManager.generateManifestAsync(consumerUuid, owner.getKey(), cdnLabel, webAppPrefix, apiUrl, getExtensionParamMap(extensionArgs));
}
Also used : Owner(org.candlepin.model.Owner) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 85 with ConsumerType

use of org.candlepin.model.ConsumerType 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)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16