ConsumerResource { @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); revokeOnGuestMigration(consumer); poolManager.regenerateDirtyEntitlements(consumer); List<CertificateSerialDTO> allCerts = new LinkedList<>(); for (Long id : entCertService.listEntitlementSerialIds(consumer)) { allCerts.add(new CertificateSerialDTO().setSerial(BigInteger.valueOf(id))); } try { ContentAccessCertificate cac = this.contentAccessManager.getCertificate(consumer); if (cac != null) { allCerts.add(new CertificateSerialDTO().setSerial( BigInteger.valueOf(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; } @Inject @SuppressWarnings({"checkstyle:parameternumber"})  ConsumerResource(ConsumerCurator consumerCurator,
        ConsumerTypeCurator consumerTypeCurator,
        OwnerProductCurator ownerProductCurator,
        SubscriptionServiceAdapter subAdapter,
        EntitlementCurator entitlementCurator,
        IdentityCertServiceAdapter identityCertService,
        EntitlementCertServiceAdapter entCertServiceAdapter,
        I18n i18n,
        EventSink sink,
        EventFactory eventFactory,
        EventAdapter eventAdapter,
        UserServiceAdapter userService,
        PoolManager poolManager,
        ConsumerRules consumerRules,
        OwnerCurator ownerCurator,
        ActivationKeyCurator activationKeyCurator,
        Entitler entitler,
        ComplianceRules complianceRules,
        SystemPurposeComplianceRules systemPurposeComplianceRules,
        DeletedConsumerCurator deletedConsumerCurator,
        EnvironmentCurator environmentCurator,
        DistributorVersionCurator distributorVersionCurator,
        Configuration config,
        ContentCurator contentCurator,
        CdnCurator cdnCurator,
        CalculatedAttributesUtil calculatedAttributesUtil,
        ConsumerBindUtil consumerBindUtil,
        ManifestManager manifestManager,
        ContentAccessManager contentAccessManager,
        FactValidator factValidator,
        ConsumerTypeValidator consumerTypeValidator,
        ConsumerEnricher consumerEnricher,
        Provider<GuestMigration> migrationProvider,
        ModelTranslator translator,
        JobManager jobManager); void sanitizeConsumerFacts(ConsumerDTO consumerDTO); void sanitizeConsumerFacts(Consumer consumer); @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") 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") List<KeyValueParameter> attrFilters,
        @Context PageRequest pageRequest); @ApiOperation( notes = "Checks for the existence of a Consumer. This method is used to check if a consumer" + " is available on a particular shard. There is no need to do a full " + "GET for the consumer for this check.", value = "") @ApiResponses({ @ApiResponse(code = 404, message = "If the consumer doesn't exist or cannot be accessed"), @ApiResponse(code = 204, message = "If the consumer exists and can be accessed") }) @HEAD @Produces(MediaType.WILDCARD) @Path("{consumer_uuid}/exists") void consumerExists(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid); @ApiOperation( notes = "Checks for the existence of a Consumer in bulk. This API return UUIDs of non-existing" + "consumer", value = "") @ApiResponses({ @ApiResponse(code = 404, message = "Returns all consumer UUIDs that doesn't exist or " + "cannot be accessed"), @ApiResponse(code = 204, message = "If all consumer UUIDs exists and can be accessed"), @ApiResponse(code = 400, message = "When no UUIDs are provided") }) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("exists") Response consumerExistsBulk(Set<String> consumerUuids); @ApiOperation(notes = "Retrieves a single Consumer", value = "getConsumer") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("{consumer_uuid}") ConsumerDTO getConsumer(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid); @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 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); Consumer createConsumerFromDTO(ConsumerDTO consumer, ConsumerType type, Principal principal,
        String userName, Owner owner, String activationKeys, boolean identityCertCreation); @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 void updateConsumer(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid,
        @ApiParam(name = "consumer", required = true) ConsumerDTO dto,
        @Context Principal principal); boolean performConsumerUpdates(ConsumerDTO updated, Consumer toUpdate,
        GuestMigration guestMigration); @Transactional boolean performConsumerUpdates(ConsumerDTO updated, Consumer toUpdate,
        GuestMigration guestMigration, boolean isIdCert); boolean checkForFactsUpdate(Consumer existing, Consumer incoming); boolean checkForFactsUpdate(Consumer existing, ConsumerDTO incomingDTO); @ApiOperation(notes = "Removes a Consumer", value = "deleteConsumer") @ApiResponses({ @ApiResponse(code = 403, message = "Invalid access rights to unregister the Consumer."), @ApiResponse(code = 404, message = "Target consumer does not exist."), @ApiResponse(code = 410, message = "Target consumer was already deleted.")}) @DELETE @Produces(MediaType.APPLICATION_JSON) @Path("{consumer_uuid}") @Transactional void deleteConsumer(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid,
        @Context Principal principal); @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 List<CertificateDTO> getEntitlementCertificates(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("serials") String serials); @ApiOperation(notes = "Retrieves the body of the Content Access Certificate for the Consumer", value = "getContentAccessBody", response = String.class) @ApiResponses({ @ApiResponse(code = 404, message = ""), @ApiResponse(code = 304, message = "") }) @GET @Path("{consumer_uuid}/accessible_content") @Produces(MediaType.APPLICATION_JSON) Response getContentAccessBody(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @HeaderParam("If-Modified-Since") @DefaultValue("Thu, 01 Jan 1970 00:00:00 GMT")
        @DateFormat({"EEE, dd MMM yyyy HH:mm:ss z"}) Date since); @ApiOperation(notes = "Retrieves a Compressed File of Entitlement Certificates", value = "exportCertificates") @ApiResponses({ @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Produces("application/zip") @Path("/{consumer_uuid}/certificates") File exportCertificates(
        @Context HttpServletResponse response,
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("serials") String serials); @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 List<CertificateSerialDTO> getEntitlementCertificateSerials(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid); @ApiOperation(notes = "If a pool ID is specified, we know we're binding to that exact pool. " + "Specifying an entitle date in this case makes no sense and will throw an " + "error. If a list of product IDs are specified, we attempt to auto-bind to" + " subscriptions which will provide those products. An optional date can be" + " specified allowing the consumer to get compliant for some date in the " + "future. If no date is specified we assume the current date. If neither a " + "pool nor an ID is specified, this is a healing request. The path is similar " + "to the bind by products, but in this case we use the installed products on " + "the consumer, and their current compliant status, to determine which product" + " IDs should be requested. The entitle date is used the same as with bind by " + "products. The response will contain a list of Entitlement objects if async is" + " false, or a JobDetail object if async is true.", value = "Bind Entitlements") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 403, message = "Binds Entitlements"), @ApiResponse(code = 404, message = "") }) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/entitlements") @SuppressWarnings("checkstyle:indentation") Response bind(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("pool") @Verify(value = Pool.class, nullable = true,
            subResource = SubResource.ENTITLEMENTS) String poolIdString,
        @QueryParam("product") String[] productIds,
        @QueryParam("quantity") Integer quantity,
        @QueryParam("email") String email,
        @QueryParam("email_locale") String emailLocale,
        @QueryParam("async") @DefaultValue("false") boolean async,
        @QueryParam("entitle_date") String entitleDateStr,
        @QueryParam("from_pool") List<String> fromPools); @ApiOperation(notes = "Retrieves a list of Pools and quantities that would be the " + "result of an auto-bind. This is a dry run of an autobind. It allows the client " + "to see what would be the result of an autobind without executing it. It can only" + " do this for the prevously established list of installed products for the consumer" + " If a service level is included in the request, then that level will override " + "the one stored on the consumer. If no service level is included then the existing " + "one will be used. The Response has a list of PoolQuantity objects", value = "dryBind") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/entitlements/dry-run") List<PoolQuantityDTO> dryBind(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("service_level") String serviceLevel); @ApiOperation(notes = "Retrives a list of Entitlements", value = "listEntitlements") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/entitlements") List<EntitlementDTO> listEntitlements(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("product") String productId,
        @QueryParam("regen") @DefaultValue("true") Boolean regen,
        @QueryParam("matches") String matches,
        @QueryParam("attribute") List<KeyValueParameter> attrFilters,
        @Context PageRequest pageRequest); @ApiOperation(notes = "Retrieves the Owner associated to a Consumer", value = "getOwner") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/owner") OwnerDTO getOwner(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid); @ApiOperation( notes = "Unbinds all Entitlements for a Consumer Result contains the " + "total number of entitlements unbound.", value = "unbindAll") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @DELETE @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/entitlements") DeleteResult unbindAll(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid); @ApiOperation(notes = "Removes an Entitlement from a Consumer By the Entitlement ID", value = "unbind") @ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") }) @DELETE @Produces(MediaType.WILDCARD) @Path("/{consumer_uuid}/entitlements/{dbid}") void unbind(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @PathParam("dbid") @Verify(Entitlement.class) String dbid,
        @Context Principal principal); @ApiOperation(notes = "Removes an Entitlement from a Consumer By the Certificate Serial", value = "unbindBySerial") @ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") }) @DELETE @Produces(MediaType.WILDCARD) @Path("/{consumer_uuid}/certificates/{serial}") void unbindBySerial(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @PathParam("serial") Long serial); @ApiOperation(notes = "Removes all Entitlements from a Consumer. By Pool Id", value = "unbindByPool") @ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") }) @DELETE @Produces(MediaType.WILDCARD) @Path("/{consumer_uuid}/entitlements/pool/{pool_id}") void unbindByPool(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @PathParam("pool_id") String poolId); @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 void regenerateEntitlementCertificates(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("entitlement") String entitlementId,
        @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen); @Deprecated @ApiOperation( notes = "Retrieves a Compressed File representation of a Consumer (manifest).", value = "Consumer Export (manifest)", response = File.class) @ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") }) @Produces("application/zip") @GET @Path("{consumer_uuid}/export") File exportData(
        @Context HttpServletResponse response,
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @QueryParam("cdn_label") String cdnLabel,
        @QueryParam("webapp_prefix") String webAppPrefix,
        @QueryParam("api_url") String apiUrl,
        @QueryParam("ext")
        @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); @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") AsyncJobStatusDTO 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")
        @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); @ApiOperation( notes = "Downloads an asynchronously generated consumer export file (manifest).", value = "Async Consumer Export (manifest) Download", response = File.class) @ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Produces("application/zip") @Path("{consumer_uuid}/export/{export_id}") void downloadExistingExport(
        @Context HttpServletResponse response,
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @PathParam("export_id") String exportId); static String buildAsyncDownloadManifestHref(String consumerUuid, String manifestId); @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}") ConsumerDTO regenerateIdentityCertificates(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid); @ApiOperation(notes = "Retrieves a list of Guest Consumers of a Consumer", value = "getGuests") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/guests") List<ConsumerDTO> getGuests(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid); @ApiOperation(notes = "Retrieves a Host Consumer of a Consumer", value = "getHost") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/host") ConsumerDTO getHost(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @Context Principal principal); @ApiOperation(notes = "Retrieves the Release of a Consumer", value = "getRelease") @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{consumer_uuid}/release") Release getRelease(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid); @ApiOperation(notes = "Retireves the Compliance Status of a Consumer.", value = "getComplianceStatus") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("{consumer_uuid}/compliance") @Transactional ComplianceStatusDTO getComplianceStatus(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid,
        @ApiParam("Date to get compliance information for, default is now.")
        @QueryParam("on_date") String onDate); @ApiOperation(notes = "Retrieves the System Purpose Compliance Status of a Consumer.", value = "getSystemPurposeComplianceStatus") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("{consumer_uuid}/purpose_compliance") @Transactional SystemPurposeComplianceStatusDTO getSystemPurposeComplianceStatus(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String uuid,
        @ApiParam("Date to get compliance information for, default is now.")
        @QueryParam("on_date") String onDate); @ApiOperation(notes = "Retrieves a Compliance Status list for a list of Consumers", value = "getComplianceStatusList") @GET @Produces(MediaType.APPLICATION_JSON) @Path("/compliance") @Transactional Map<String, ComplianceStatusDTO> getComplianceStatusList(
        @QueryParam("uuid") @Verify(value = Consumer.class, nullable = true) List<String> uuids); @ApiOperation( notes = "Removes the Deletion Record for a Consumer Allowed for a superadmin." + " The main use case for this would be if a user accidently deleted a " + "non-RHEL hypervisor, causing it to no longer be auto-detected via virt-who.", value = "removeDeletionRecord") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @DELETE @Path("{consumer_uuid}/deletionrecord") @Produces(MediaType.APPLICATION_JSON) @Transactional void removeDeletionRecord(@PathParam("consumer_uuid") String uuid);  }
@Test public void testGetCertSerials() { Consumer consumer = createConsumer(createOwner()); List<EntitlementCertificate> certificates = createEntitlementCertificates(); List<Long> serialIds = new ArrayList<>(); for (EntitlementCertificate ec : certificates) { serialIds.add(ec.getSerial().getId()); } when(mockEntitlementCertServiceAdapter.listEntitlementSerialIds(consumer)).thenReturn(serialIds); when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>()); List<CertificateSerialDTO> serials = consumerResource .getEntitlementCertificateSerials(consumer.getUuid()); verifyCertificateSerialNumbers(serials); }