Search in sources :

Example 1 with CredentialValue

use of org.cloudfoundry.credhub.credential.CredentialValue in project credhub by cloudfoundry-incubator.

the class SetHandlerTest method handleSetRequest_withACertificateSetRequest_andACaName_providesCaCertificate.

@Test
public void handleSetRequest_withACertificateSetRequest_andACaName_providesCaCertificate() {
    CertificateCredentialValue cerificateAuthority = new CertificateCredentialValue(null, TestConstants.TEST_CA, null, null);
    when(certificateAuthorityService.findActiveVersion("/test-ca-name")).thenReturn(cerificateAuthority);
    CertificateSetRequest setRequest = new CertificateSetRequest();
    final CertificateCredentialValue credentialValue = new CertificateCredentialValue(null, TestConstants.TEST_CERTIFICATE, "Enterprise", "test-ca-name");
    final ArrayList<EventAuditRecordParameters> eventAuditRecordParameters = new ArrayList<>();
    setRequest.setType("certificate");
    setRequest.setName("/captain");
    setRequest.setAdditionalPermissions(accessControlEntries);
    setRequest.setOverwrite(false);
    setRequest.setCertificateValue(credentialValue);
    CertificateCredentialValue expectedCredentialValue = new CertificateCredentialValue(TestConstants.TEST_CA, TestConstants.TEST_CERTIFICATE, "Enterprise", "/test-ca-name");
    ArgumentCaptor<CredentialValue> credentialValueArgumentCaptor = ArgumentCaptor.forClass(CredentialValue.class);
    subject.handle(setRequest, eventAuditRecordParameters);
    verify(credentialService).save(eq(null), credentialValueArgumentCaptor.capture(), eq(setRequest), eq(eventAuditRecordParameters));
    assertThat(credentialValueArgumentCaptor.getValue(), samePropertyValuesAs(expectedCredentialValue));
    verify(permissionService).savePermissions(credentialVersion, accessControlEntries, eventAuditRecordParameters, true, "/captain");
}
Also used : UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) CredentialValue(org.cloudfoundry.credhub.credential.CredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) ArrayList(java.util.ArrayList) CertificateSetRequest(org.cloudfoundry.credhub.request.CertificateSetRequest) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) Test(org.junit.Test)

Example 2 with CredentialValue

use of org.cloudfoundry.credhub.credential.CredentialValue 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 3 with CredentialValue

use of org.cloudfoundry.credhub.credential.CredentialValue in project credhub by cloudfoundry-incubator.

the class PermissionedCredentialServiceTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    userContext = mock(UserContext.class);
    UserContextHolder userContextHolder = new UserContextHolder();
    userContextHolder.setUserContext(userContext);
    subject = new PermissionedCredentialService(credentialVersionDataService, credentialFactory, permissionCheckingService, certificateAuthorityService, userContextHolder, credentialDataService);
    auditRecordParameters = new ArrayList<>();
    generationParameters = mock(StringGenerationParameters.class);
    credentialValue = mock(CredentialValue.class);
    credential = new Credential(CREDENTIAL_NAME);
    accessControlEntries = new ArrayList<>();
    when(userContext.getActor()).thenReturn(USER);
    existingCredentialVersion = new PasswordCredentialVersion(CREDENTIAL_NAME);
    existingCredentialVersion.setEncryptor(encryptor);
    when(permissionCheckingService.hasPermission(USER, CREDENTIAL_NAME, READ)).thenReturn(true);
    when(permissionCheckingService.hasPermission(USER, CREDENTIAL_NAME, WRITE)).thenReturn(true);
    when(credentialDataService.findByUUID(CREDENTIAL_UUID)).thenReturn(credential);
    when(credentialVersionDataService.findByUuid(VERSION_UUID_STRING)).thenReturn(existingCredentialVersion);
    when(request.getName()).thenReturn(CREDENTIAL_NAME);
    when(request.getGenerationParameters()).thenReturn(generationParameters);
    when(request.getAdditionalPermissions()).thenReturn(accessControlEntries);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CredentialValue(org.cloudfoundry.credhub.credential.CredentialValue) UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 4 with CredentialValue

use of org.cloudfoundry.credhub.credential.CredentialValue in project credhub by cloudfoundry-incubator.

the class GenerateHandler method handle.

public CredentialView handle(BaseCredentialGenerateRequest generateRequest, List<EventAuditRecordParameters> auditRecordParameters) {
    CredentialVersion existingCredentialVersion = credentialService.findMostRecent(generateRequest.getName());
    CredentialValue value = credentialGenerator.generate(generateRequest);
    final CredentialVersion credentialVersion = credentialService.save(existingCredentialVersion, value, generateRequest, auditRecordParameters);
    final boolean isNewCredential = existingCredentialVersion == null;
    if (isNewCredential || generateRequest.isOverwrite()) {
        permissionService.savePermissions(credentialVersion, generateRequest.getAdditionalPermissions(), auditRecordParameters, isNewCredential, generateRequest.getName());
    }
    return CredentialView.fromEntity(credentialVersion);
}
Also used : CredentialValue(org.cloudfoundry.credhub.credential.CredentialValue) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 5 with CredentialValue

use of org.cloudfoundry.credhub.credential.CredentialValue 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)

Aggregations

CredentialValue (org.cloudfoundry.credhub.credential.CredentialValue)5 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)3 ArrayList (java.util.ArrayList)1 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)1 UserContext (org.cloudfoundry.credhub.auth.UserContext)1 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)1 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)1 StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)1 UserCredentialValue (org.cloudfoundry.credhub.credential.UserCredentialValue)1 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)1 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)1 Credential (org.cloudfoundry.credhub.entity.Credential)1 BaseCredentialGenerateRequest (org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest)1 CertificateGenerateRequest (org.cloudfoundry.credhub.request.CertificateGenerateRequest)1 CertificateSetRequest (org.cloudfoundry.credhub.request.CertificateSetRequest)1 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)1 Before (org.junit.Before)1 Test (org.junit.Test)1