Search in sources :

Example 11 with Credential

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);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters)

Example 12 with Credential

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);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 13 with Credential

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;
}
Also used : CredentialView(org.cloudfoundry.credhub.view.CredentialView) PermissionedCertificateService(org.cloudfoundry.credhub.service.PermissionedCertificateService) BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialsView(org.cloudfoundry.credhub.view.CertificateCredentialsView) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CreateVersionRequest(org.cloudfoundry.credhub.request.CreateVersionRequest) UUID(java.util.UUID) CertificateView(org.cloudfoundry.credhub.view.CertificateView) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Collectors(java.util.stream.Collectors) CertificateCredentialView(org.cloudfoundry.credhub.view.CertificateCredentialView) CertificateRegenerateRequest(org.cloudfoundry.credhub.request.CertificateRegenerateRequest) UpdateTransitionalVersionRequest(org.cloudfoundry.credhub.request.UpdateTransitionalVersionRequest) List(java.util.List) Credential(org.cloudfoundry.credhub.entity.Credential) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) AuditingOperationCode(org.cloudfoundry.credhub.audit.AuditingOperationCode) Service(org.springframework.stereotype.Service) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) CertificateService(org.cloudfoundry.credhub.service.CertificateService) UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateView(org.cloudfoundry.credhub.view.CertificateView)

Example 14 with Credential

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"));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with 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);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue)

Aggregations

Credential (org.cloudfoundry.credhub.entity.Credential)49 Test (org.junit.Test)30 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 UUID (java.util.UUID)13 UserContext (org.cloudfoundry.credhub.auth.UserContext)13 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)13 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)9 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)9 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)9 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)7 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)5 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)4 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 AuditingOperationCode (org.cloudfoundry.credhub.audit.AuditingOperationCode)3 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)3 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)3 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)3