Search in sources :

Example 36 with CredentialVersion

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

the class PermissionsHandler method setPermissions.

public void setPermissions(PermissionsRequest request, List<EventAuditRecordParameters> auditRecordParameters) {
    CredentialVersion credentialVersion = permissionedCredentialService.findMostRecent(request.getCredentialName());
    permissionService.savePermissions(credentialVersion, request.getPermissions(), auditRecordParameters, false, request.getCredentialName());
}
Also used : CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 37 with CredentialVersion

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

the class RegenerateHandler method handleRegenerate.

public CredentialView handleRegenerate(String credentialName, List<EventAuditRecordParameters> auditRecordParameters) {
    CredentialVersion existingCredentialVersion = credentialService.findMostRecent(credentialName);
    BaseCredentialGenerateRequest generateRequest = generationRequestGenerator.createGenerateRequest(existingCredentialVersion, credentialName, auditRecordParameters);
    CredentialValue credentialValue = credentialGenerator.generate(generateRequest);
    final CredentialVersion credentialVersion = credentialService.save(existingCredentialVersion, credentialValue, generateRequest, auditRecordParameters);
    return CredentialView.fromEntity(credentialVersion);
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CredentialValue(org.cloudfoundry.credhub.credential.CredentialValue) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 38 with CredentialVersion

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

the class CredentialVersionDataService method findActiveByName.

public List<CredentialVersion> findActiveByName(String name) {
    Credential credential = credentialDataService.find(name);
    CredentialVersionData credentialVersionData;
    ArrayList<CredentialVersion> result = newArrayList();
    if (credential != null) {
        credentialVersionData = credentialVersionRepository.findFirstByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid());
        if (credentialVersionData.getCredentialType().equals(CertificateCredentialVersionData.CREDENTIAL_TYPE)) {
            return certificateVersionDataService.findActiveWithTransitional(name);
        }
        result.add(credentialFactory.makeCredentialFromEntity(credentialVersionData));
        return result;
    } else {
        return newArrayList();
    }
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 39 with CredentialVersion

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

the class CredentialsControllerTypeSpecificGenerateTest method parameters.

@Parameterized.Parameters(name = "{0}")
public static Collection<Object> parameters() {
    credentialUuid = UUID.randomUUID();
    Collection<Object> params = new ArrayList<>();
    TestParameterizer passwordParameters = new TestParameterizer("password", "{\"exclude_number\": true}") {

        ResultMatcher jsonAssertions() {
            return multiJsonPath("$.value", FAKE_PASSWORD);
        }

        void credentialAssertions(CredentialVersion credential) {
            PasswordCredentialVersion passwordCredential = (PasswordCredentialVersion) credential;
            assertThat(passwordCredential.getGenerationParameters().isExcludeNumber(), equalTo(true));
            assertThat(passwordCredential.getPassword(), equalTo(FAKE_PASSWORD));
        }

        CredentialVersion createCredential(Encryptor encryptor) {
            return new PasswordCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPasswordAndGenerationParameters(FAKE_PASSWORD, new StringGenerationParameters().setExcludeNumber(true)).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
        }
    };
    TestParameterizer userParameterizer = new TestParameterizer("user", "null") {

        ResultMatcher jsonAssertions() {
            return multiJsonPath("$.value.username", USERNAME, "$.value.password", FAKE_PASSWORD);
        }

        void credentialAssertions(CredentialVersion credential) {
            UserCredentialVersion userCredential = (UserCredentialVersion) credential;
            assertThat(userCredential.getUsername(), equalTo(USERNAME));
            assertThat(userCredential.getPassword(), equalTo(FAKE_PASSWORD));
        }

        CredentialVersion createCredential(Encryptor encryptor) {
            return new UserCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPassword(FAKE_PASSWORD).setUsername(USERNAME).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
        }
    };
    TestParameterizer certificateParameterizer = new TestParameterizer("certificate", "{\"common_name\":\"my-common-name\",\"self_sign\":true}") {

        ResultMatcher jsonAssertions() {
            return multiJsonPath("$.value.certificate", "certificate", "$.value.private_key", "private_key", "$.value.ca", "ca");
        }

        void credentialAssertions(CredentialVersion credential) {
            CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) credential;
            assertThat(certificateCredential.getCa(), equalTo(CA));
            assertThat(certificateCredential.getCertificate(), equalTo(CERTIFICATE));
            assertThat(certificateCredential.getPrivateKey(), equalTo(PRIVATE_KEY));
        }

        CredentialVersion createCredential(Encryptor encryptor) {
            return new CertificateCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setCa(CA).setCertificate(CERTIFICATE).setPrivateKey(PRIVATE_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
        }
    };
    TestParameterizer sshParameterizer = new TestParameterizer("ssh", "null") {

        ResultMatcher jsonAssertions() {
            return multiJsonPath("$.value.public_key", "public_key", "$.value.private_key", "private_key", "$.value.public_key_fingerprint", null);
        }

        void credentialAssertions(CredentialVersion credential) {
            SshCredentialVersion sshCredential = (SshCredentialVersion) credential;
            assertThat(sshCredential.getPublicKey(), equalTo(PUBLIC_KEY));
            assertThat(sshCredential.getPrivateKey(), equalTo(PRIVATE_KEY));
        }

        CredentialVersion createCredential(Encryptor encryptor) {
            return new SshCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(PRIVATE_KEY).setPublicKey(PUBLIC_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
        }
    };
    TestParameterizer rsaParameterizer = new TestParameterizer("rsa", "null") {

        ResultMatcher jsonAssertions() {
            return multiJsonPath("$.value.public_key", "public_key", "$.value.private_key", "private_key");
        }

        void credentialAssertions(CredentialVersion credential) {
            RsaCredentialVersion rsaCredential = (RsaCredentialVersion) credential;
            assertThat(rsaCredential.getPublicKey(), equalTo(PUBLIC_KEY));
            assertThat(rsaCredential.getPrivateKey(), equalTo(PRIVATE_KEY));
        }

        CredentialVersion createCredential(Encryptor encryptor) {
            return new RsaCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(PRIVATE_KEY).setPublicKey(PUBLIC_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
        }
    };
    params.add(passwordParameters);
    params.add(userParameterizer);
    params.add(certificateParameterizer);
    params.add(sshParameterizer);
    params.add(rsaParameterizer);
    return params;
}
Also used : RsaCredentialVersion(org.cloudfoundry.credhub.domain.RsaCredentialVersion) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Encryptor(org.cloudfoundry.credhub.domain.Encryptor) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) UserCredentialVersion(org.cloudfoundry.credhub.domain.UserCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) RsaCredentialVersion(org.cloudfoundry.credhub.domain.RsaCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) UserCredentialVersion(org.cloudfoundry.credhub.domain.UserCredentialVersion) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 40 with CredentialVersion

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

the class CredentialsControllerTypeSpecificSetTest method updatingACredential_withOverwriteSetToFalse_persistsAnAuditEntry.

@Test
public void updatingACredential_withOverwriteSetToFalse_persistsAnAuditEntry() throws Exception {
    CredentialVersion expectedCredentialVersion = parametizer.createCredential(encryptor);
    doReturn(expectedCredentialVersion).when(credentialVersionDataService).findMostRecent(CREDENTIAL_NAME);
    final MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"type\":\"" + parametizer.credentialType + "\"," + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"value\":" + parametizer.credentialValue + "}");
    mockMvc.perform(request);
    auditingHelper.verifyAuditing(CREDENTIAL_ACCESS, CREDENTIAL_NAME, UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data", 200);
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) RsaCredentialVersion(org.cloudfoundry.credhub.domain.RsaCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) JsonCredentialVersion(org.cloudfoundry.credhub.domain.JsonCredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) UserCredentialVersion(org.cloudfoundry.credhub.domain.UserCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

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