-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Certificate API - Follow Key Vault behavior more accurately (#505)
- Sets new defaults for key usages - Sets new defaults for extended key usages - Sets new defaults for certificate lifetime actions - Renames ips to upns in SANS to correct a mistake - Clears up confusion between certificate policy and issuance policy - Makes sure renewal can change certificate content type - Splits certificate controller into two smaller controllers - Fixes get certificate policy controller to return issuance policy - Fixes JSON mapping of key usage enum - Removes unintended issuance policy change behavior at certificate import - Adds new tests Resolves #503 {minor} Signed-off-by: Esta Nagy <[email protected]>
- Loading branch information
Showing
44 changed files
with
1,095 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
.../com/github/nagyesta/lowkeyvault/controller/common/CommonCertificatePolicyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.github.nagyesta.lowkeyvault.controller.common; | ||
|
||
import com.github.nagyesta.lowkeyvault.mapper.v7_3.certificate.CertificateEntityToV73IssuancePolicyModelConverter; | ||
import com.github.nagyesta.lowkeyvault.mapper.v7_3.certificate.CertificateEntityToV73PendingCertificateOperationModelConverter; | ||
import com.github.nagyesta.lowkeyvault.mapper.v7_3.certificate.LifetimeActionsPolicyToV73ModelConverter; | ||
import com.github.nagyesta.lowkeyvault.model.v7_3.certificate.CertificatePolicyModel; | ||
import com.github.nagyesta.lowkeyvault.model.v7_3.certificate.KeyVaultPendingCertificateModel; | ||
import com.github.nagyesta.lowkeyvault.service.certificate.CertificateVaultFake; | ||
import com.github.nagyesta.lowkeyvault.service.certificate.ReadOnlyKeyVaultCertificateEntity; | ||
import com.github.nagyesta.lowkeyvault.service.certificate.id.CertificateEntityId; | ||
import com.github.nagyesta.lowkeyvault.service.certificate.id.VersionedCertificateEntityId; | ||
import com.github.nagyesta.lowkeyvault.service.vault.VaultFake; | ||
import com.github.nagyesta.lowkeyvault.service.vault.VaultService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.lang.NonNull; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.Pattern; | ||
import java.net.URI; | ||
import java.util.function.Function; | ||
|
||
@Slf4j | ||
public abstract class CommonCertificatePolicyController | ||
extends BaseEntityReadController<CertificateEntityId, VersionedCertificateEntityId, | ||
ReadOnlyKeyVaultCertificateEntity, CertificateVaultFake> { | ||
|
||
private final CertificateEntityToV73PendingCertificateOperationModelConverter pendingOperationConverter; | ||
private final CertificateEntityToV73IssuancePolicyModelConverter issuancePolicyConverter; | ||
private final LifetimeActionsPolicyToV73ModelConverter lifetimeActionsConverter; | ||
|
||
protected CommonCertificatePolicyController( | ||
@lombok.NonNull final CertificateEntityToV73PendingCertificateOperationModelConverter pendingOperationConverter, | ||
@lombok.NonNull final CertificateEntityToV73IssuancePolicyModelConverter issuancePolicyConverter, | ||
@lombok.NonNull final LifetimeActionsPolicyToV73ModelConverter lifetimeActionsConverter, | ||
@NonNull final VaultService vaultService, | ||
@NonNull final Function<VaultFake, CertificateVaultFake> toEntityVault) { | ||
super(vaultService, toEntityVault); | ||
this.pendingOperationConverter = pendingOperationConverter; | ||
this.issuancePolicyConverter = issuancePolicyConverter; | ||
this.lifetimeActionsConverter = lifetimeActionsConverter; | ||
} | ||
|
||
public ResponseEntity<KeyVaultPendingCertificateModel> pendingCreate( | ||
@Valid @Pattern(regexp = NAME_PATTERN) final String certificateName, | ||
final URI baseUri) { | ||
log.info("Received request to {} get pending create certificate: {} using API version: {}", | ||
baseUri.toString(), certificateName, apiVersion()); | ||
final CertificateVaultFake vaultFake = getVaultByUri(baseUri); | ||
final VersionedCertificateEntityId entityId = vaultFake | ||
.getEntities().getLatestVersionOfEntity(entityId(baseUri, certificateName)); | ||
final ReadOnlyKeyVaultCertificateEntity readOnlyEntity = vaultFake | ||
.getEntities().getReadOnlyEntity(entityId); | ||
return ResponseEntity.ok(pendingOperationConverter.convert(readOnlyEntity, baseUri)); | ||
} | ||
|
||
public ResponseEntity<KeyVaultPendingCertificateModel> pendingDelete( | ||
@Valid @Pattern(regexp = NAME_PATTERN) final String certificateName, | ||
final URI baseUri) { | ||
log.info("Received request to {} get pending delete certificate: {} using API version: {}", | ||
baseUri.toString(), certificateName, apiVersion()); | ||
final CertificateVaultFake vaultFake = getVaultByUri(baseUri); | ||
final VersionedCertificateEntityId entityId = vaultFake.getDeletedEntities() | ||
.getLatestVersionOfEntity(entityId(baseUri, certificateName)); | ||
final ReadOnlyKeyVaultCertificateEntity readOnlyEntity = vaultFake | ||
.getDeletedEntities().getReadOnlyEntity(entityId); | ||
return ResponseEntity.ok(pendingOperationConverter.convert(readOnlyEntity, baseUri)); | ||
} | ||
|
||
public ResponseEntity<CertificatePolicyModel> getPolicy( | ||
@Valid @Pattern(regexp = NAME_PATTERN) final String certificateName, | ||
final URI baseUri) { | ||
log.info("Received request to {} get certificate policy: {} with version: -LATEST- using API version: {}", | ||
baseUri.toString(), certificateName, apiVersion()); | ||
final CertificateVaultFake vaultFake = getVaultByUri(baseUri); | ||
final VersionedCertificateEntityId latest = vaultFake.getEntities().getLatestVersionOfEntity(entityId(baseUri, certificateName)); | ||
final ReadOnlyKeyVaultCertificateEntity entity = vaultFake.getEntities().getReadOnlyEntity(latest); | ||
final CertificatePolicyModel model = issuancePolicyConverter.convert(entity, baseUri); | ||
lifetimeActionsConverter.populateLifetimeActions(vaultFake, latest, model::setLifetimeActions); | ||
return ResponseEntity.ok(model); | ||
} | ||
|
||
@Override | ||
protected VersionedCertificateEntityId versionedEntityId(final URI baseUri, final String name, final String version) { | ||
return new VersionedCertificateEntityId(baseUri, name, version); | ||
} | ||
|
||
@Override | ||
protected CertificateEntityId entityId(final URI baseUri, final String name) { | ||
return new CertificateEntityId(baseUri, name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.