use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionsHandler method getPermissions.
public PermissionsView getPermissions(String name, List<EventAuditRecordParameters> auditRecordParameters) {
CredentialVersion credentialVersion = permissionedCredentialService.findMostRecent(name);
final List<PermissionEntry> permissions = permissionService.getPermissions(credentialVersion, auditRecordParameters, name);
return new PermissionsView(credentialVersion.getName(), permissions);
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class RegenerateHandler method regenerateCertificateAndDirectChildren.
private TreeSet<String> regenerateCertificateAndDirectChildren(String credentialName, List<EventAuditRecordParameters> auditRecordParameters) {
TreeSet<String> results = new TreeSet(String.CASE_INSENSITIVE_ORDER);
CredentialVersion existingCredentialVersion = credentialService.findMostRecent(credentialName);
CertificateGenerateRequest generateRequest = (CertificateGenerateRequest) generationRequestGenerator.createGenerateRequest(existingCredentialVersion, credentialName, auditRecordParameters);
CredentialValue newCredentialValue = credentialGenerator.generate(generateRequest);
CredentialVersion credentialVersion = credentialService.save(existingCredentialVersion, newCredentialValue, generateRequest, auditRecordParameters);
results.add(credentialVersion.getName());
CertificateGenerationParameters generationParameters = (CertificateGenerationParameters) generateRequest.getGenerationParameters();
if (generationParameters.isCa()) {
results.addAll(this.regenerateCertificatesSignedByCA(generateRequest.getName(), auditRecordParameters));
}
return results;
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class SetHandler method handle.
public CredentialView handle(BaseCredentialSetRequest setRequest, List<EventAuditRecordParameters> auditRecordParameters) {
if (setRequest instanceof CertificateSetRequest) {
// fill in the ca value if it's one of ours
CertificateCredentialValue certificateValue = ((CertificateSetRequest) setRequest).getCertificateValue();
String caName = certificateValue.getCaName();
if (caName != null) {
final String caValue = certificateAuthorityService.findActiveVersion(caName).getCertificate();
certificateValue.setCa(caValue);
CertificateReader certificateReader = new CertificateReader(certificateValue.getCertificate());
if (!certificateReader.isSignedByCa(caValue)) {
throw new ParameterizedValidationException("error.certificate_was_not_signed_by_ca_name");
}
}
}
CredentialVersion existingCredentialVersion = credentialService.findMostRecent(setRequest.getName());
final CredentialVersion credentialVersion = credentialService.save(existingCredentialVersion, setRequest.getCredentialValue(), setRequest, auditRecordParameters);
final boolean isNewCredential = existingCredentialVersion == null;
if (isNewCredential || setRequest.isOverwrite()) {
permissionService.savePermissions(credentialVersion, setRequest.getAdditionalPermissions(), auditRecordParameters, isNewCredential, setRequest.getName());
}
return CredentialView.fromEntity(credentialVersion);
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCredentialService method findVersionByUuid.
public CredentialVersion findVersionByUuid(String credentialUUID, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
auditRecordParameters.add(eventAuditRecordParameters);
CredentialVersion credentialVersion = credentialVersionDataService.findByUuid(credentialUUID);
if (credentialVersion == null) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
String credentialName = credentialVersion.getName();
eventAuditRecordParameters.setCredentialName(credentialName);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credentialName, READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return credentialVersionDataService.findByUuid(credentialUUID);
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleUpdateTransitionalVersion.
public List<CertificateView> handleUpdateTransitionalVersion(String certificateId, UpdateTransitionalVersionRequest requestBody, List<EventAuditRecordParameters> auditRecordParameters) {
List<CredentialVersion> credentialList;
UUID versionUUID = null;
if (requestBody.getVersionUuid() != null) {
versionUUID = UUID.fromString(requestBody.getVersionUuid());
}
credentialList = permissionedCertificateService.updateTransitionalVersion(UUID.fromString(certificateId), versionUUID, auditRecordParameters);
List<CertificateView> list = credentialList.stream().map(credential -> new CertificateView((CertificateCredentialVersion) credential)).collect(Collectors.toList());
return list;
}
Aggregations