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