From 13ab11a844d840025d153f7eac9109fbbe1c6b08 Mon Sep 17 00:00:00 2001 From: sebdet Date: Thu, 10 Oct 2019 11:40:27 +0200 Subject: Rework the clamp cadi filter Add test and rework the code for X509 certificate Issue-ID: CLAMP-519 Change-Id: I3c0aa05cd4bec24770243b86a4672ff3906afba5 Signed-off-by: sebdet --- .../onap/clamp/clds/filter/ClampCadiFilter.java | 18 ++++++--- src/test/javascript/package.json | 46 ---------------------- 2 files changed, 12 insertions(+), 52 deletions(-) delete mode 100644 src/test/javascript/package.json (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java b/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java index 7e104c74b..cd141ae77 100644 --- a/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java +++ b/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java @@ -144,16 +144,22 @@ public class ClampCadiFilter extends CadiFilter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { - String certHeader = URLDecoder.decode(((HttpServletRequest) request).getHeader("X-SSL-Cert"), - StandardCharsets.UTF_8.toString()); + String certHeader = ((HttpServletRequest) request).getHeader("X-SSL-Cert"); if (certHeader != null) { - CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certificateFactory - .generateCertificate(new ByteArrayInputStream(certHeader.getBytes())); - request.setAttribute("javax.servlet.request.X509Certificate", cert); - + .generateCertificate(new ByteArrayInputStream( + URLDecoder.decode(certHeader, StandardCharsets.UTF_8.toString()).getBytes())); + X509Certificate[] certifArray = ((X509Certificate[]) request + .getAttribute("javax.servlet.request.X509Certificate")); + if (certifArray == null) { + certifArray = new X509Certificate[] { cert }; + request.setAttribute("javax.servlet.request.X509Certificate", certifArray); + } else { + certifArray[0] = cert; + } } + } catch (CertificateException e) { logger.error("Unable to inject the X.509 certificate", e); } diff --git a/src/test/javascript/package.json b/src/test/javascript/package.json deleted file mode 100644 index a2f0cd2eb..000000000 --- a/src/test/javascript/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "scripts": { - "test": "jest", - "test:watch": "jest --watch", - "test:coverage": "jest --coverage" - }, - "jest": { - "verbose": true, - "coverageDirectory": "${project.build.directory}/clamp-ui/coverage", - "collectCoverageFrom": [ - "**/designer/**/*.{js,jsx}", - "!**/designer/lib/**" - ], - "rootDir": "${project.build.directory}/clamp-ui", - "roots": [ - "${project.basedir}/src/test/javascript/", - "/designer/" - ], - "moduleDirectories": [ - "${project.build.directory}/clamp-ui/node/node_modules", - "${project.build.directory}/clamp-ui/node_modules", - "/designer" - ], - "coverageReporters": [ - "lcov" - ] - }, - "devDependencies": { - "angular": "1.3.2", - "angular-resource": "1.3.2", - "angular-cookies": "1.3.2", - "angular-route": "1.3.2", - "angular-mocks": "1.3.2", - "angular-animate": "1.3.2", - "angular-sanitize": "1.3.2", - "angular-touch": "1.3.2", - "angular-dialog-service": "5.3.0", - "angular-loading-bar": "0.9.0", - "jquery": "3.3.1", - "popper.js": "1.14.4", - "bootstrap": "4.1.1", - "angular-ui-bootstrap": "2.5.6", - "jest": "^23.6.0", - "jest-cli": "^21.2.1" - } -} -- cgit 1.2.3-korg