use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method updateTransitionalVersion.
public List<CredentialVersion> updateTransitionalVersion(UUID certificateUuid, UUID newTransitionalVersionUuid, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_UPDATE, null);
auditRecordParameters.add(eventAuditRecordParameters);
Credential credential = findCertificateCredential(certificateUuid);
String name = credential.getName();
eventAuditRecordParameters.setCredentialName(name);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), name, PermissionOperation.WRITE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
certificateVersionDataService.unsetTransitionalVerison(certificateUuid);
if (newTransitionalVersionUuid != null) {
CertificateCredentialVersion version = certificateVersionDataService.findVersion(newTransitionalVersionUuid);
if (versionDoesNotBelongToCertificate(credential, version)) {
throw new ParameterizedValidationException("error.credential.mismatched_credential_and_version");
}
certificateVersionDataService.setTransitionalVersion(newTransitionalVersionUuid);
}
return certificateVersionDataService.findActiveWithTransitional(name);
}
use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class CertificateCredentialRegeneratable method createGenerateRequest.
@Override
public BaseCredentialGenerateRequest createGenerateRequest(CredentialVersion credentialVersion, List<EventAuditRecordParameters> auditRecordParameters) {
CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) credentialVersion;
CertificateReader reader = certificateCredential.getParsedCertificate();
if (!reader.isValid() || (isEmpty(certificateCredential.getCaName()) && !reader.isSelfSigned())) {
auditRecordParameters.add(new EventAuditRecordParameters(CREDENTIAL_UPDATE, credentialVersion.getName()));
throw new ParameterizedValidationException("error.cannot_regenerate_non_generated_certificate");
}
CertificateGenerationParameters certificateGenerationParameters = new CertificateGenerationParameters(reader, certificateCredential.getCaName());
CertificateGenerateRequest generateRequest = new CertificateGenerateRequest();
generateRequest.setName(certificateCredential.getName());
generateRequest.setType(certificateCredential.getCredentialType());
generateRequest.setCertificateGenerationParameters(certificateGenerationParameters);
generateRequest.setOverwrite(true);
return generateRequest;
}
use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class PasswordCredentialRegeneratable method createGenerateRequest.
@Override
public BaseCredentialGenerateRequest createGenerateRequest(CredentialVersion credentialVersion, List<EventAuditRecordParameters> auditRecordParameters) {
PasswordCredentialVersion passwordCredential = (PasswordCredentialVersion) credentialVersion;
PasswordGenerateRequest generateRequest = new PasswordGenerateRequest();
generateRequest.setName(passwordCredential.getName());
generateRequest.setType(passwordCredential.getCredentialType());
generateRequest.setOverwrite(true);
StringGenerationParameters generationParameters;
generationParameters = passwordCredential.getGenerationParameters();
if (generationParameters == null) {
auditRecordParameters.add(new EventAuditRecordParameters(CREDENTIAL_UPDATE, credentialVersion.getName()));
throw new ParameterizedValidationException("error.cannot_regenerate_non_generated_password");
}
generateRequest.setGenerationParameters(generationParameters);
return generateRequest;
}
use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificGenerateTest method generatingACredential_validatesTheRequestBody.
@Test
public void generatingACredential_validatesTheRequestBody() throws Exception {
MockHttpServletRequestBuilder request = createGenerateNewCredentialRequest();
DefaultCredentialGenerateRequest requestBody = mock(DefaultCredentialGenerateRequest.class);
Mockito.doThrow(new ParameterizedValidationException("error.bad_request")).when(requestBody).validate();
doReturn(requestBody).when(objectMapper).readValue(anyString(), any(Class.class));
mockMvc.perform(request).andExpect(status().isBadRequest()).andExpect(content().json("{\"error\":\"The request could not be fulfilled because the request path or body did not meet expectation. Please check the documentation for required formatting and retry your request.\"}"));
}
use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class CertificateGeneratorTest method whenTheCADoesNotHaveAPrivateKey_itThrowsAnException.
@Test
public void whenTheCADoesNotHaveAPrivateKey_itThrowsAnException() throws Exception {
CertificateGenerationRequestParameters parameters = new CertificateGenerationRequestParameters();
parameters.setCaName("/ca-without-private-key");
parameters.setKeyLength(2048);
parameters.setSelfSigned(false);
CertificateCredentialValue caWithoutPrivateKey = mock(CertificateCredentialValue.class);
when(certificateAuthorityService.findActiveVersion("/ca-without-private-key")).thenReturn(caWithoutPrivateKey);
when(caWithoutPrivateKey.getPrivateKey()).thenReturn(null);
when(keyGenerator.generateKeyPair(anyInt())).thenReturn(rootCaKeyPair);
try {
subject.generateCredential(new CertificateGenerationParameters(parameters));
fail("Should throw exception");
} catch (ParameterizedValidationException e) {
assertThat(e.getMessage(), equalTo("error.ca_missing_private_key"));
}
}
Aggregations