use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class SetHandler method handle.
public CredentialView handle(BaseCredentialSetRequest setRequest, List<EventAuditRecordParameters> auditRecordParameters) {
if (setRequest instanceof CertificateSetRequest) {
// fill in the ca value if it's one of ours
CertificateCredentialValue certificateValue = ((CertificateSetRequest) setRequest).getCertificateValue();
String caName = certificateValue.getCaName();
if (caName != null) {
final String caValue = certificateAuthorityService.findActiveVersion(caName).getCertificate();
certificateValue.setCa(caValue);
CertificateReader certificateReader = new CertificateReader(certificateValue.getCertificate());
if (!certificateReader.isSignedByCa(caValue)) {
throw new ParameterizedValidationException("error.certificate_was_not_signed_by_ca_name");
}
}
}
CredentialVersion existingCredentialVersion = credentialService.findMostRecent(setRequest.getName());
final CredentialVersion credentialVersion = credentialService.save(existingCredentialVersion, setRequest.getCredentialValue(), setRequest, auditRecordParameters);
final boolean isNewCredential = existingCredentialVersion == null;
if (isNewCredential || setRequest.isOverwrite()) {
permissionService.savePermissions(credentialVersion, setRequest.getAdditionalPermissions(), auditRecordParameters, isNewCredential, setRequest.getName());
}
return CredentialView.fromEntity(credentialVersion);
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleRegenerate.
public CredentialView handleRegenerate(String credentialUuid, List<EventAuditRecordParameters> auditRecordParameters, CertificateRegenerateRequest request) {
CertificateCredentialVersion existingCredentialVersion = certificateService.findByCredentialUuid(credentialUuid, auditRecordParameters);
BaseCredentialGenerateRequest generateRequest = generationRequestGenerator.createGenerateRequest(existingCredentialVersion, existingCredentialVersion.getName(), auditRecordParameters);
CertificateCredentialValue credentialValue = (CertificateCredentialValue) credentialGenerator.generate(generateRequest);
credentialValue.setTransitional(request.isTransitional());
final CertificateCredentialVersion credentialVersion = (CertificateCredentialVersion) permissionedCertificateService.save(existingCredentialVersion, credentialValue, generateRequest, auditRecordParameters);
return new CertificateView(credentialVersion);
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleCreateVersionsRequest.
public CertificateView handleCreateVersionsRequest(String certificateId, CreateVersionRequest requestBody, List<EventAuditRecordParameters> auditRecordParameters) {
CertificateCredentialValue certificateCredentialValue = requestBody.getValue();
certificateCredentialValue.setTransitional(requestBody.isTransitional());
final CertificateCredentialVersion credentialVersion = permissionedCertificateService.set(UUID.fromString(certificateId), certificateCredentialValue, auditRecordParameters);
return new CertificateView(credentialVersion);
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CredentialsControllerGenerateTest method beforeEach.
@Before
public void beforeEach() {
Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
userContext = mock(UserContext.class);
fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
when(credentialGenerator.generateCredential(any(StringGenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD_NAME));
when(sshGenerator.generateCredential(any(SshGenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
when(rsaGenerator.generateCredential(any(RsaGenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
when(certificateGenerator.generateCredential(any(CertificateGenerationParameters.class))).thenReturn(new CertificateCredentialValue("ca_cert", CERT, PRIVATE_KEY, null));
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificGenerateTest method setup.
@Before
public void setup() throws Exception {
String fakeSalt = cryptSaltFactory.generateSalt(FAKE_PASSWORD);
Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
when(passwordGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD));
when(certificateGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new CertificateCredentialValue(CA, CERTIFICATE, PRIVATE_KEY, null));
when(sshGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
when(rsaGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
when(userGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new UserCredentialValue(USERNAME, FAKE_PASSWORD, fakeSalt));
auditingHelper = new AuditingHelper(requestAuditRecordRepository, eventAuditRecordRepository);
}
Aggregations