Search in sources :

Example 16 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method delete_onACredentialName_deletesAllCredentialsWithTheName.

@Test
public void delete_onACredentialName_deletesAllCredentialsWithTheName() {
    Credential credential = credentialDataService.save(new Credential("/my-credential"));
    PasswordCredentialVersionData credentialData = new PasswordCredentialVersionData();
    credentialData.setCredential(credential);
    credentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce("nonce".getBytes()));
    subject.save(credentialData);
    credentialData = new PasswordCredentialVersionData("/my-credential");
    credentialData.setCredential(credential);
    credentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("another password".getBytes()).setNonce("nonce".getBytes()));
    subject.save(credentialData);
    assertThat(subject.findAllByName("/my-credential"), hasSize(2));
    subject.delete("/my-credential");
    assertThat(subject.findAllByName("/my-credential"), hasSize(0));
    assertNull(credentialDataService.find("/my-credential"));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 17 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class PermissionDataServiceTest method seedDatabase.

private void seedDatabase() {
    ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(CREDENTIAL_NAME);
    credential = valueCredentialData.getCredential();
    ValueCredentialVersionData noAccessValueCredentialData = new ValueCredentialVersionData(NO_ACCESS_CREDENTIAL_NAME);
    Credential noAccessValueCredential = noAccessValueCredentialData.getCredential();
    Credential noAccessCredential = credentialDataService.save(noAccessValueCredential);
    this.credential = credentialDataService.save(this.credential);
    subject.savePermissions(this.credential, singletonList(new PermissionEntry(LUKE, newArrayList(WRITE, DELETE))));
    subject.savePermissions(this.credential, singletonList(new PermissionEntry(LEIA, singletonList(READ))));
    subject.savePermissions(this.credential, singletonList(new PermissionEntry(HAN_SOLO, newArrayList(READ_ACL, WRITE_ACL))));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData)

Example 18 with Credential

use of org.cloudfoundry.credhub.entity.Credential 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 19 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class CredentialDataServiceTest method find_isCaseInsensitive.

@Test
public void find_isCaseInsensitive() {
    final Credential credential = new Credential(CREDENTIAL_NAME.toLowerCase());
    credentialRepository.save(credential);
    assertThat(subject.find(CREDENTIAL_NAME.toUpperCase()), equalTo(credential));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateService method deleteVersion.

public CertificateCredentialVersion deleteVersion(UUID certificateUuid, UUID versionUuid, List<EventAuditRecordParameters> auditRecordParameters) {
    EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_DELETE, null);
    auditRecordParameters.add(eventAuditRecordParameters);
    Credential certificate = certificateDataService.findByUuid(certificateUuid);
    if (certificate == null || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.DELETE)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    eventAuditRecordParameters.setCredentialName(certificate.getName());
    CertificateCredentialVersion versionToDelete = certificateVersionDataService.findVersion(versionUuid);
    if (versionDoesNotBelongToCertificate(certificate, versionToDelete)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    if (certificateHasOnlyOneVersion(certificateUuid)) {
        throw new ParameterizedValidationException("error.credential.cannot_delete_last_version");
    }
    certificateVersionDataService.deleteVersion(versionUuid);
    return versionToDelete;
}
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)

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