diff options
author | 2020-02-13 14:55:21 +0100 | |
---|---|---|
committer | 2020-02-13 14:55:21 +0100 | |
commit | 06f7465cebf967f6c1ffd9970b05158c00aa5ff1 (patch) | |
tree | ad950726b6da96f9af5ba898e7038d5984a87fee /certService/src/main/java/org/onap/aaf/certservice/api | |
parent | 459a31e973f55fd97831a9a7cae0dce664259a4e (diff) |
Improve exception flow
Issue-ID: AAF-995
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I4d690fbe27364bc50b97ab42e64e610566d93ca0
Diffstat (limited to 'certService/src/main/java/org/onap/aaf/certservice/api')
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/api/CertificationService.java | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/certService/src/main/java/org/onap/aaf/certservice/api/CertificationService.java b/certService/src/main/java/org/onap/aaf/certservice/api/CertificationService.java index 75fc0f52..d1a4a17a 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/api/CertificationService.java +++ b/certService/src/main/java/org/onap/aaf/certservice/api/CertificationService.java @@ -24,11 +24,9 @@ import com.google.gson.Gson; import org.onap.aaf.certservice.certification.CertificationModelFactory; import org.onap.aaf.certservice.certification.CsrModelFactory; import org.onap.aaf.certservice.certification.CsrModelFactory.StringBase64; -import org.onap.aaf.certservice.certification.exceptions.CsrDecryptionException; -import org.onap.aaf.certservice.certification.exceptions.PemDecryptionException; +import org.onap.aaf.certservice.certification.exceptions.DecryptionException; import org.onap.aaf.certservice.certification.model.CertificationModel; import org.onap.aaf.certservice.certification.model.CsrModel; -import org.onap.aaf.certservice.certification.model.ErrorResponseModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -68,35 +66,19 @@ public class CertificationService { @PathVariable String caName, @RequestHeader("CSR") String encodedCsr, @RequestHeader("PK") String encodedPrivateKey - ) { + ) throws DecryptionException { + caName = caName.replaceAll("[\n|\r|\t]", "_"); LOGGER.info("Received certificate signing request for CA named: {}", caName); + CsrModel csrModel = csrModelFactory.createCsrModel( + new StringBase64(encodedCsr), + new StringBase64(encodedPrivateKey) + ); + LOGGER.debug("Received CSR meta data: \n{}", csrModel); + CertificationModel certificationModel = certificationModelFactory + .createCertificationModel(csrModel,caName); + return new ResponseEntity<>(new Gson().toJson(certificationModel), HttpStatus.OK); - try { - CsrModel csrModel = csrModelFactory.createCsrModel( - new StringBase64(encodedCsr), - new StringBase64(encodedPrivateKey) - ); - LOGGER.debug("Received CSR meta data: \n{}", csrModel); - CertificationModel certificationModel = certificationModelFactory - .createCertificationModel(csrModel,caName); - return new ResponseEntity<>( - new Gson().toJson(certificationModel), - HttpStatus.OK); - } catch (CsrDecryptionException e) { - LOGGER.error("Exception occurred during decoding certificate sign request:", e); - return getErrorResponseEntity("Wrong certificate signing request (CSR) format"); - } catch (PemDecryptionException e) { - LOGGER.error("Exception occurred during decoding key:", e); - return getErrorResponseEntity("Wrong key (PK) format"); - } - } - - private ResponseEntity<String> getErrorResponseEntity(String errorMessage) { - ErrorResponseModel errorResponse = new ErrorResponseModel(errorMessage); - return new ResponseEntity<>( - new Gson().toJson(errorResponse), - HttpStatus.BAD_REQUEST); } |