Search in sources :

Example 26 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findNByName_whenAskedForTooManyVersions_returnsAllVersions.

@Test
public void findNByName_whenAskedForTooManyVersions_returnsAllVersions() {
    PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
    List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", 2);
    assertThat(credentialVersions.size(), equalTo(1));
    assertThat(credentialVersions.get(0).getUuid(), equalTo(credential1.getUuid()));
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 27 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method save_givenANewCredential_savesTheCredential.

@Test
public void save_givenANewCredential_savesTheCredential() {
    PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential");
    passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "credential-password", ""));
    PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
    credential.setEncryptor(encryptor);
    CredentialVersion savedCredentialVersion = subject.save(credential);
    assertNotNull(savedCredentialVersion);
    PasswordCredentialVersion savedPasswordCredential = (PasswordCredentialVersion) subject.findMostRecent("/my-credential");
    CredentialVersionData credentialVersionData = credentialVersionRepository.findOneByUuid(savedCredentialVersion.getUuid());
    assertThat(savedPasswordCredential.getName(), equalTo(credential.getName()));
    assertThat(savedPasswordCredential.getUuid(), equalTo(credential.getUuid()));
    assertThat(credentialVersionData.getCredential().getName(), equalTo("/my-credential"));
    assertThat(credentialVersionData.getEncryptedValueData().getEncryptedValue(), equalTo("credential-password".getBytes()));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) SshCredentialVersionData(org.cloudfoundry.credhub.entity.SshCredentialVersionData) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 28 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CertificateVersionDataServiceTest method findActive_FindsMostRecentNonTransitionalCredentialVersion.

@Test
public void findActive_FindsMostRecentNonTransitionalCredentialVersion() throws Exception {
    Credential certificate = mock(Credential.class);
    when(dataService.find("/some-ca-name")).thenReturn(certificate);
    CredentialVersionData certificateEntity = mock(CredentialVersionData.class);
    when(versionRepository.findLatestNonTransitionalCertificateVersion(any())).thenReturn(certificateEntity);
    CredentialVersion expectedVersion = mock(CredentialVersion.class);
    when(factory.makeCredentialFromEntity(certificateEntity)).thenReturn(expectedVersion);
    CredentialVersion activeVersion = subject.findActive("/some-ca-name");
    assertThat(activeVersion, equalTo(expectedVersion));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Test(org.junit.Test)

Example 29 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateService method getVersions.

public List<CredentialVersion> getVersions(UUID uuid, boolean current, List<EventAuditRecordParameters> auditRecordParameters) {
    List<CredentialVersion> list;
    String name;
    try {
        if (current) {
            Credential credential = findCertificateCredential(uuid);
            name = credential.getName();
            list = certificateVersionDataService.findActiveWithTransitional(name);
        } else {
            list = certificateVersionDataService.findAllVersions(uuid);
            name = !list.isEmpty() ? list.get(0).getName() : null;
        }
    } catch (IllegalArgumentException e) {
        auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, null));
        throw new InvalidQueryParameterException("error.bad_request", "uuid");
    }
    auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, name));
    if (list.isEmpty() || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), name, PermissionOperation.READ)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    return list;
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) InvalidQueryParameterException(org.cloudfoundry.credhub.exceptions.InvalidQueryParameterException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 30 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CertificateService method findByCredentialUuid.

public CertificateCredentialVersion findByCredentialUuid(String uuid, List<EventAuditRecordParameters> auditRecordParameters) {
    EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
    auditRecordParameters.add(eventAuditRecordParameters);
    CredentialVersion credentialVersion = this.certificateVersionDataService.findByCredentialUUID(uuid);
    if (credentialVersion == null || !(credentialVersion instanceof CertificateCredentialVersion)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    eventAuditRecordParameters.setCredentialName(credentialVersion.getName());
    CertificateCredentialVersion certificate = (CertificateCredentialVersion) credentialVersion;
    if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.READ)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    return certificate;
}
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) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

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