use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class CrlResource method unrevoke.
@ApiOperation(notes = "Deletes a Certificate from the Revocation List", value = "unrevoke")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void unrevoke(@QueryParam("serial") String[] serialIds) throws CRLException, IOException {
String filePath = getCrlFilePath();
File crlFile = new File(filePath);
try {
List<BigInteger> serials = new LinkedList<>();
for (CertificateSerial serial : certificateSerialCurator.listBySerialIds(serialIds)) {
serials.add(serial.getSerial());
}
if (serials.size() > 0) {
this.crlFileUtil.updateCRLFile(crlFile, null, serials);
}
} catch (IOException e) {
throw new IseException(e.getMessage(), e);
}
}
use of org.candlepin.model.CertificateSerial 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.model.CertificateSerial in project candlepin by candlepin.
the class EntitlementTranslatorTest method initSourceObject.
@Override
protected Entitlement initSourceObject() {
Entitlement source = new Entitlement();
source.setId("ent-id");
source.setQuantity(1);
source.setDeletedFromPool(false);
source.setOwner(this.ownerTranslatorTest.initSourceObject());
source.setPool(this.poolTranslatorTest.initSourceObject());
HashSet<EntitlementCertificate> certs = new HashSet<>();
EntitlementCertificate entCert = new EntitlementCertificate();
entCert.setId("ent-cert-id");
entCert.setEntitlement(source);
entCert.setKey("ent-cert-key");
entCert.setCert("ent-cert-cert");
entCert.setSerial(new CertificateSerial());
certs.add(entCert);
source.setCertificates(certs);
Consumer consumer = new Consumer();
consumer.setUuid("consumer-uuid");
source.setConsumer(consumer);
source.setEndDate(new Date());
source.setStartDate(new Date());
return source;
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class StubEntitlementCertServiceAdapter method generateEntitlementCerts.
@Override
public Map<String, EntitlementCertificate> generateEntitlementCerts(Consumer consumer, Map<String, PoolQuantity> poolQuantityMap, Map<String, Entitlement> entitlements, Map<String, Product> products, boolean save) throws GeneralSecurityException, IOException {
Map<String, EntitlementCertificate> result = new HashMap<>();
for (Entry<String, Entitlement> entry : entitlements.entrySet()) {
Entitlement entitlement = entry.getValue();
Product product = products.get(entry.getKey());
log.debug("Generating entitlement cert for:");
log.debug(" consumer: " + consumer.getUuid());
log.debug(" product: " + product.getUuid());
log.debug(" end date: " + entitlement.getEndDate());
EntitlementCertificate cert = new EntitlementCertificate();
CertificateSerial serial = new CertificateSerial(entitlement.getEndDate());
serialCurator.create(serial);
cert.setSerial(serial);
cert.setKeyAsBytes(("---- STUB KEY -----" + Math.random()).getBytes());
cert.setCertAsBytes(("---- STUB CERT -----" + Math.random()).getBytes());
cert.setEntitlement(entitlement);
entitlement.getCertificates().add(cert);
log.debug("Generated cert: " + serial.getId());
log.debug("Key: " + cert.getKey());
log.debug("Cert: " + cert.getCert());
if (save) {
cert = entCertCurator.create(cert);
}
result.put(entry.getKey(), cert);
}
return result;
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testDetachedEntitlementDataNotAddedToCertV1.
@Test
public void testDetachedEntitlementDataNotAddedToCertV1() throws Exception {
KeyPair keyPair = new BouncyCastlePKIUtility(null, null, null).generateNewKeyPair();
when(keyPairCurator.getConsumerKeyPair(any(Consumer.class))).thenReturn(keyPair);
when(mockedPKI.getPemEncoded(any(X509Certificate.class))).thenReturn("".getBytes());
when(mockedPKI.getPemEncoded(any(Key.class))).thenReturn("".getBytes());
final CertificateSerial serial = mock(CertificateSerial.class);
when(serial.getId()).thenReturn(1L);
pool.setId("poolId");
doAnswer(new Answer<Map<String, CertificateSerial>>() {
@Override
public Map<String, CertificateSerial> answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Map<String, CertificateSerial> map = (Map<String, CertificateSerial>) args[0];
map.put("poolId", serial);
return null;
}
}).when(serialCurator).saveOrUpdateAll(anyMap());
EntitlementCertificate cert = certServiceAdapter.generateEntitlementCert(entitlement, product);
assertTrue(!cert.getCert().contains("ENTITLEMENT DATA"));
}
Aggregations