Search in sources :

Example 11 with CredentialVersion

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);
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 12 with CredentialVersion

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;
}
Also used : CertificateGenerateRequest(org.cloudfoundry.credhub.request.CertificateGenerateRequest) CertificateGenerationParameters(org.cloudfoundry.credhub.domain.CertificateGenerationParameters) CredentialValue(org.cloudfoundry.credhub.credential.CredentialValue) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 13 with CredentialVersion

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);
}
Also used : CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) CertificateSetRequest(org.cloudfoundry.credhub.request.CertificateSetRequest) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateReader(org.cloudfoundry.credhub.util.CertificateReader)

Example 14 with 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);
}
Also used : EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 15 with CredentialVersion

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;
}
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)

Aggregations

CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)50 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)35 Test (org.junit.Test)33 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)27 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)17 RsaCredentialVersion (org.cloudfoundry.credhub.domain.RsaCredentialVersion)14 UserCredentialVersion (org.cloudfoundry.credhub.domain.UserCredentialVersion)13 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)11 JsonCredentialVersion (org.cloudfoundry.credhub.domain.JsonCredentialVersion)10 Credential (org.cloudfoundry.credhub.entity.Credential)8 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)7 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)6 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)5 ResultActions (org.springframework.test.web.servlet.ResultActions)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)4 UserContext (org.cloudfoundry.credhub.auth.UserContext)3