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));
}
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);
}
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;
}
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."));
}
}
}
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()));
}
Aggregations