Search in sources :

Example 1 with CertificateDTO

use of org.candlepin.dto.api.v1.CertificateDTO in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testRegenerateEntitlementCertificateWithValidConsumerByEntitlement.

/**
 * Test verifies that list of certs changes after regeneration
 */
@SuppressWarnings("unchecked")
@Test
public void testRegenerateEntitlementCertificateWithValidConsumerByEntitlement() {
    GuestMigration testMigration = new GuestMigration(consumerCurator);
    Provider<GuestMigration> migrationProvider = Providers.of(testMigration);
    ConsumerResource cr = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, null, null, this.entitlementCurator, null, null, null, null, null, null, null, null, this.poolManager, null, null, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, mock(ConsumerBindUtil.class), null, null, null, null, consumerEnricher, migrationProvider, this.modelTranslator);
    Response rsp = consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    List<EntitlementDTO> resultList = (List<EntitlementDTO>) rsp.getEntity();
    EntitlementDTO ent = resultList.get(0);
    assertEquals(1, ent.getCertificates().size());
    CertificateDTO entCertBefore = ent.getCertificates().iterator().next();
    cr.regenerateEntitlementCertificates(this.consumer.getUuid(), ent.getId(), false);
    Entitlement entWithRefreshedCerts = entitlementCurator.find(ent.getId());
    ent = this.modelTranslator.translate(entWithRefreshedCerts, EntitlementDTO.class);
    assertEquals(1, ent.getCertificates().size());
    CertificateDTO entCertAfter = ent.getCertificates().iterator().next();
    assertFalse(entCertBefore.equals(entCertAfter));
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) GuestMigration(org.candlepin.resource.util.GuestMigration) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) ConsumerBindUtil(org.candlepin.resource.util.ConsumerBindUtil) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) List(java.util.List) ArrayList(java.util.ArrayList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 2 with CertificateDTO

use of org.candlepin.dto.api.v1.CertificateDTO 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 3 with CertificateDTO

use of org.candlepin.dto.api.v1.CertificateDTO 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 4 with CertificateDTO

use of org.candlepin.dto.api.v1.CertificateDTO in project candlepin by candlepin.

the class CdnResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO.
 * This method will not set the ID field.
 *
 * @param entity
 *  The entity instance to populate
 *
 * @param dto
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
private void populateEntity(Cdn entity, CdnDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the Cdn model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the Cdn dto is null");
    }
    if (dto.getName() != null) {
        entity.setName(dto.getName());
    }
    if (dto.getUrl() != null) {
        entity.setUrl(dto.getUrl());
    }
    if (dto.getCertificate() != null) {
        CertificateDTO certDTO = dto.getCertificate();
        CdnCertificate cdnCert;
        if (certDTO.getKey() != null && certDTO.getCert() != null) {
            cdnCert = new CdnCertificate();
            cdnCert.setCert(certDTO.getCert());
            cdnCert.setKey(certDTO.getKey());
            if (certDTO.getSerial() != null) {
                CertificateSerialDTO certSerialDTO = certDTO.getSerial();
                CertificateSerial certSerial = new CertificateSerial();
                certSerial.setExpiration(certSerialDTO.getExpiration());
                if (certSerialDTO.getSerial() != null) {
                    certSerial.setSerial(certSerialDTO.getSerial().longValue());
                }
                if (certSerialDTO.isCollected() != null) {
                    certSerial.setCollected(certSerialDTO.isCollected());
                }
                if (certSerialDTO.isRevoked() != null) {
                    certSerial.setRevoked(certSerialDTO.isRevoked());
                }
                cdnCert.setSerial(certSerial);
            }
            entity.setCertificate(cdnCert);
        } else {
            throw new BadRequestException(i18n.tr("cdn certificate has null key or cert."));
        }
    }
}
Also used : CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerialDTO(org.candlepin.dto.api.v1.CertificateSerialDTO) CertificateSerial(org.candlepin.model.CertificateSerial) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Example 5 with CertificateDTO

use of org.candlepin.dto.api.v1.CertificateDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testRegenerateIdCerts.

@Test
public void testRegenerateIdCerts() throws GeneralSecurityException, IOException {
    // using lconsumer simply to avoid hiding consumer. This should
    // get renamed once we refactor this test suite.
    IdentityCertServiceAdapter mockIdSvc = Mockito.mock(IdentityCertServiceAdapter.class);
    EventSink sink = Mockito.mock(EventSinkImpl.class);
    Consumer consumer = createConsumer(createOwner());
    consumer.setIdCert(createIdCert());
    IdentityCertificate ic = consumer.getIdCert();
    assertNotNull(ic);
    when(mockIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, mockIdSvc, null, null, sink, eventFactory, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    ConsumerDTO fooc = cr.regenerateIdentityCertificates(consumer.getUuid());
    assertNotNull(fooc);
    CertificateDTO ic1 = fooc.getIdCert();
    assertNotNull(ic1);
    assertFalse(ic.getId().equals(ic1.getId()));
}
Also used : IdentityCertServiceAdapter(org.candlepin.service.IdentityCertServiceAdapter) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) EventSink(org.candlepin.audit.EventSink) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Aggregations

CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)6 Test (org.junit.Test)4 CertificateSerial (org.candlepin.model.CertificateSerial)3 Consumer (org.candlepin.model.Consumer)3 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)3 IdentityCertificate (org.candlepin.model.IdentityCertificate)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 CertificateSerialDTO (org.candlepin.dto.api.v1.CertificateSerialDTO)2 CertificateDTO (org.candlepin.dto.manifest.v1.CertificateDTO)2 ConsumerType (org.candlepin.model.ConsumerType)2 GuestMigration (org.candlepin.resource.util.GuestMigration)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 GeneralSecurityException (java.security.GeneralSecurityException)1