use of org.candlepin.model.Environment in project candlepin by candlepin.
the class EnvironmentResource method create.
@ApiOperation(notes = "Creates an Environment", value = "create")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@SecurityHole(noAuth = true)
@Path("/{env_id}/consumers")
public ConsumerDTO create(@PathParam("env_id") String envId, @ApiParam(name = "consumer", required = true) ConsumerDTO consumer, @Context Principal principal, @QueryParam("username") String userName, @QueryParam("owner") String ownerKey, @QueryParam("activation_keys") String activationKeys) throws BadRequestException {
Environment e = lookupEnvironment(envId);
consumer.setEnvironment(translator.translate(e, EnvironmentDTO.class));
return this.consumerResource.create(consumer, principal, userName, e.getOwner().getKey(), activationKeys, true);
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class OwnerResource method createEnv.
/**
* Creates an Environment for an Owner
*
* @return an Environment object
* @httpcode 404
* @httpcode 200
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/environments")
@ApiOperation(notes = "Creates an Environment for an Owner", value = "Create environment")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public EnvironmentDTO createEnv(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @ApiParam(name = "environment", required = true) EnvironmentDTO envDTO) {
Environment env = new Environment();
OwnerDTO ownerDTO = new OwnerDTO().setKey(ownerKey);
envDTO.setOwner(ownerDTO);
populateEntity(env, envDTO);
env = envCurator.create(env);
return translator.translate(env, EnvironmentDTO.class);
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class OwnerResource method listEnvironments.
/**
* Retrieves a list of Environments for an Owner
*
* @param envName Optional environment name filter to search for.
* @return a list of Environment objects
* @httpcode 200
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/environments")
@Wrapped(element = "environments")
@ApiOperation(notes = "Retrieves a list of Environments for an Owner", value = "List environments")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public CandlepinQuery<EnvironmentDTO> listEnvironments(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @ApiParam("Environment name filter to search for.") @QueryParam("name") String envName) {
Owner owner = findOwnerByKey(ownerKey);
CandlepinQuery<Environment> query = envName == null ? envCurator.listForOwner(owner) : envCurator.listForOwnerByName(owner, envName);
return translator.translateQuery(query, EnvironmentDTO.class);
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class DefaultContentAccessCertServiceAdapter method getCertificate.
@Transactional
public ContentAccessCertificate getCertificate(Consumer consumer) throws GeneralSecurityException, IOException {
Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
// appropriate cert generation
if (!ORG_ENV_ACCESS_MODE.equals(owner.getContentAccessMode()) || !this.consumerIsCertV3Capable(consumer)) {
return null;
}
ContentAccessCertificate existing = consumer.getContentAccessCert();
ContentAccessCertificate result = new ContentAccessCertificate();
String pem = "";
if (existing != null && existing.getSerial().getExpiration().getTime() < (new Date()).getTime()) {
consumer.setContentAccessCert(null);
contentAccessCertificateCurator.delete(existing);
existing = null;
}
if (existing == null) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, -1);
Date startDate = cal.getTime();
cal.add(Calendar.YEAR, 1);
Date endDate = cal.getTime();
CertificateSerial serial = new CertificateSerial(endDate);
// We need the sequence generated id before we create the Certificate,
// otherwise we could have used cascading create
serialCurator.create(serial);
KeyPair keyPair = keyPairCurator.getConsumerKeyPair(consumer);
byte[] pemEncodedKeyPair = pki.getPemEncoded(keyPair.getPrivate());
X509Certificate x509Cert = createX509Certificate(consumer, owner, BigInteger.valueOf(serial.getId()), keyPair, startDate, endDate);
existing = new ContentAccessCertificate();
existing.setSerial(serial);
existing.setKeyAsBytes(pemEncodedKeyPair);
existing.setConsumer(consumer);
log.info("Setting PEM encoded cert.");
pem = new String(this.pki.getPemEncoded(x509Cert));
existing.setCert(pem);
consumer.setContentAccessCert(existing);
contentAccessCertificateCurator.create(existing);
consumerCurator.merge(consumer);
} else {
pem = existing.getCert();
}
Environment env = this.environmentCurator.getConsumerEnvironment(consumer);
// we need to see if this is newer than the previous result
OwnerEnvContentAccess oeca = ownerEnvContentAccessCurator.getContentAccess(owner.getId(), env == null ? null : env.getId());
if (oeca == null) {
String contentJson = createPayloadAndSignature(owner, env);
oeca = new OwnerEnvContentAccess(owner, env, contentJson);
ownerEnvContentAccessCurator.saveOrUpdate(oeca);
}
pem += oeca.getContentJson();
result.setCert(pem);
result.setCreated(existing.getCreated());
result.setUpdated(existing.getUpdated());
result.setId(existing.getId());
result.setConsumer(existing.getConsumer());
result.setKey(existing.getKey());
result.setSerial(existing.getSerial());
return result;
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class DefaultContentAccessCertServiceAdapter method createX509Certificate.
public X509Certificate createX509Certificate(Consumer consumer, Owner owner, BigInteger serialNumber, KeyPair keyPair, Date startDate, Date endDate) throws GeneralSecurityException, IOException {
// fake a product dto as a container for the org content
org.candlepin.model.dto.Product container = new org.candlepin.model.dto.Product();
org.candlepin.model.dto.Content dContent = new org.candlepin.model.dto.Content();
List<org.candlepin.model.dto.Content> dtoContents = new ArrayList<>();
dtoContents.add(dContent);
Environment environment = this.environmentCurator.getConsumerEnvironment(consumer);
dContent.setPath(getContentPrefix(owner, environment));
container.setContent(dtoContents);
Set<X509ExtensionWrapper> extensions = prepareV3Extensions();
Set<X509ByteExtensionWrapper> byteExtensions = prepareV3ByteExtensions(container);
X509Certificate x509Cert = this.pki.createX509Certificate(createDN(consumer, owner), extensions, byteExtensions, startDate, endDate, keyPair, serialNumber, null);
return x509Cert;
}
Aggregations