Search in sources :

Example 11 with EntitlementCertificate

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

the class ConsumerResourceTest method testcheckForGuestsMigrationSerialList.

@Test
public void testcheckForGuestsMigrationSerialList() {
    Consumer consumer = createConsumer(createOwner());
    List<EntitlementCertificate> certificates = createEntitlementCertificates();
    when(mockEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
    when(mockConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>());
    ConsumerResource consumerResource = Mockito.spy(new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator));
    List<CertificateSerialDto> serials = consumerResource.getEntitlementCertificateSerials(consumer.getUuid());
    verify(consumerResource).revokeOnGuestMigration(consumer);
}
Also used : Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerialDto(org.candlepin.model.CertificateSerialDto) Test(org.junit.Test)

Example 12 with EntitlementCertificate

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

the class ConsumerResourceTest method createEntitlementCertificate.

protected EntitlementCertificate createEntitlementCertificate(String key, String cert) {
    EntitlementCertificate toReturn = new EntitlementCertificate();
    CertificateSerial certSerial = new CertificateSerial(1L, new Date());
    toReturn.setKeyAsBytes(key.getBytes());
    toReturn.setCertAsBytes(cert.getBytes());
    toReturn.setSerial(certSerial);
    return toReturn;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Date(java.util.Date)

Example 13 with EntitlementCertificate

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

the class ConsumerResourceTest method testCheckForGuestsMigrationCertList.

@Test
public void testCheckForGuestsMigrationCertList() {
    Consumer consumer = createConsumer(createOwner());
    List<EntitlementCertificate> certificates = createEntitlementCertificates();
    when(mockEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
    when(mockConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>());
    GuestMigration migrationSpy = Mockito.spy(testMigration);
    migrationProvider = Providers.of(migrationSpy);
    ConsumerResource consumerResource = Mockito.spy(new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator));
    Set<Long> serials = new HashSet<>();
    List<CertificateDTO> certs = consumerResource.getEntitlementCertificates(consumer.getUuid(), "123");
    verify(consumerResource).revokeOnGuestMigration(consumer);
}
Also used : GuestMigration(org.candlepin.resource.util.GuestMigration) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with EntitlementCertificate

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

the class ConsumerResourceTest method testGetCertSerials.

@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<>());
    ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    List<CertificateSerialDto> serials = consumerResource.getEntitlementCertificateSerials(consumer.getUuid());
    verifyCertificateSerialNumbers(serials);
}
Also used : Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerialDto(org.candlepin.model.CertificateSerialDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with EntitlementCertificate

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

Aggregations

EntitlementCertificate (org.candlepin.model.EntitlementCertificate)29 Entitlement (org.candlepin.model.Entitlement)15 Consumer (org.candlepin.model.Consumer)14 CertificateSerial (org.candlepin.model.CertificateSerial)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 Owner (org.candlepin.model.Owner)8 Pool (org.candlepin.model.Pool)8 Product (org.candlepin.model.Product)7 Map (java.util.Map)5 Event (org.candlepin.audit.Event)4 Certificate (org.candlepin.model.Certificate)3 PoolQuantity (org.candlepin.model.PoolQuantity)3 KeyPair (java.security.KeyPair)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)2