use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method getByName.
public List<Credential> getByName(String name, List<EventAuditRecordParameters> auditRecordParameters) {
auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_FIND, name));
final Credential certificate = certificateDataService.findByName(name);
if (certificate == null || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return Collections.singletonList(certificate);
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method updateTransitionalVersion.
public List<CredentialVersion> updateTransitionalVersion(UUID certificateUuid, UUID newTransitionalVersionUuid, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_UPDATE, null);
auditRecordParameters.add(eventAuditRecordParameters);
Credential credential = findCertificateCredential(certificateUuid);
String name = credential.getName();
eventAuditRecordParameters.setCredentialName(name);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), name, PermissionOperation.WRITE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
certificateVersionDataService.unsetTransitionalVerison(certificateUuid);
if (newTransitionalVersionUuid != null) {
CertificateCredentialVersion version = certificateVersionDataService.findVersion(newTransitionalVersionUuid);
if (versionDoesNotBelongToCertificate(credential, version)) {
throw new ParameterizedValidationException("error.credential.mismatched_credential_and_version");
}
certificateVersionDataService.setTransitionalVersion(newTransitionalVersionUuid);
}
return certificateVersionDataService.findActiveWithTransitional(name);
}
use of org.cloudfoundry.credhub.entity.Credential 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;
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findMostRecent_givenACredentialNameWithoutVersions_returnsNull.
@Test
public void findMostRecent_givenACredentialNameWithoutVersions_returnsNull() {
credentialDataService.save(new Credential("/my-unused-CREDENTIAL"));
assertNull(subject.findMostRecent("/my-unused-CREDENTIAL"));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method setupTestFixtureForFindMostRecent.
private void setupTestFixtureForFindMostRecent() {
Credential credential = credentialDataService.save(new Credential("/my-CREDENTIAL"));
namedPasswordCredential1 = new PasswordCredentialVersionData();
namedPasswordCredential1.setCredential(credential);
namedPasswordCredential1.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("/my-old-password".getBytes()).setNonce(new byte[] {}));
passwordCredential2 = new PasswordCredentialVersionData();
passwordCredential2.setCredential(credential);
passwordCredential2.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("/my-new-password".getBytes()).setNonce(new byte[] {}));
subject.save(namedPasswordCredential1);
// 1 second later
fakeTimeSetter.accept(345346L);
subject.save(passwordCredential2);
}
Aggregations