summaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-09-19 16:22:35 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-19 16:22:35 +0000
commit20293b786597e0867916d3daf3c2f824850c0199 (patch)
treebc3477bb212c717aa92f363e83f3916f27377131 /filters
parentbaf9900e9439e59de44c7a3b4548ea6f7cd935c4 (diff)
parentd815d848cd83cfb9180286af5bc8a7516f4eafe9 (diff)
Merge "update filters"
Diffstat (limited to 'filters')
-rw-r--r--filters/features/ccsdk-filters/pom.xml51
-rwxr-xr-xfilters/installer/pom.xml22
-rwxr-xr-xfilters/provider/pom.xml70
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java40
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java7
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersService.java4
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersServiceImpl.java33
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java223
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java363
-rw-r--r--filters/provider/src/main/resources/OSGI-INF/blueprint/filters-blueprint.xml9
-rw-r--r--filters/provider/src/main/resources/org/opendaylight/blueprint/filters-blueprint.xml9
-rw-r--r--filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java23
-rw-r--r--filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java71
-rw-r--r--filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java165
14 files changed, 94 insertions, 996 deletions
diff --git a/filters/features/ccsdk-filters/pom.xml b/filters/features/ccsdk-filters/pom.xml
index 320dfab31..08462a70b 100644
--- a/filters/features/ccsdk-filters/pom.xml
+++ b/filters/features/ccsdk-filters/pom.xml
@@ -15,43 +15,32 @@
<packaging>feature</packaging>
<name>ccsdk-sli-core :: filters :: ${project.artifactId}</name>
- <dependencyManagement>
- <dependencies>
-
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-common</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<dependencies>
-
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ccsdk-sli</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
-
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>filters-provider</artifactId>
<version>${project.version}</version>
</dependency>
-
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <excludedArtifactIds>
+ <!-- let opendaylight start these features/jars to avoid conflicts at runtime -->
+ <excludedArtifactId>slf4j-api</excludedArtifactId>
+ <excludedArtifactId>javax.annotation-api</excludedArtifactId>
+ <excludedArtifactId>javax.servlet-api</excludedArtifactId>
+ <excludedArtifactId>javax.ws.rs-api</excludedArtifactId>
+ </excludedArtifactIds>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
diff --git a/filters/installer/pom.xml b/filters/installer/pom.xml
index 8921eca8d..3428c1b11 100755
--- a/filters/installer/pom.xml
+++ b/filters/installer/pom.xml
@@ -23,28 +23,6 @@
<include.transitive.dependencies>false</include.transitive.dependencies>
</properties>
- <dependencyManagement>
- <dependencies>
-
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-common</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
-
<dependencies>
<dependency>
diff --git a/filters/provider/pom.xml b/filters/provider/pom.xml
index 602b8384b..ef5b49c1f 100755
--- a/filters/provider/pom.xml
+++ b/filters/provider/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+ <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -15,78 +15,16 @@
<packaging>bundle</packaging>
<name>ccsdk-sli-core :: filters :: ${project.artifactId}</name>
- <url>http://maven.apache.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <!-- Ignore deprecated classes in coverage counts -->
- <sonar.coverage.exclusions>**/RequestResponseDbLoggingFilter.java</sonar.coverage.exclusions>
- </properties>
-
- <dependencyManagement>
- <dependencies>
-
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-common</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<dependencies>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-filter-base</artifactId>
+ <version>1.5.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
-
-
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>sli-common</artifactId>
- <version>${project.version}</version>
- </dependency>
-
</dependencies>
</project>
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java
new file mode 100644
index 000000000..7805e365d
--- /dev/null
+++ b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java
@@ -0,0 +1,40 @@
+package org.onap.ccsdk.sli.core.filters;
+
+import javax.servlet.http.HttpServletRequest;
+import org.onap.logging.filter.base.AuditLogServletFilter;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.MDC;
+
+public class ControllerAuditLogFilter extends AuditLogServletFilter {
+ private static final String MDC_HTTP_METHOD_KEY = "HttpMethod";
+
+ @Override
+ protected void additionalPreHandling(HttpServletRequest httpServletRequest) {
+ // Don't overwrite service instance id if it was set outside of this automated method
+ if (MDC.get(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID) == null) {
+ String serviceInstanceId = getServiceInstanceId(httpServletRequest.getPathInfo());
+ if (serviceInstanceId != null) {
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID, serviceInstanceId);
+ }
+ }
+ MDC.put(MDC_HTTP_METHOD_KEY, httpServletRequest.getMethod());
+ }
+
+ // restconf URLs follow a pattern, this method attempts to extract the service instance id according to that pattern
+ protected String getServiceInstanceId(String path) {
+ int idx = path.indexOf("service-list");
+ if (idx != -1) {
+ // chomp off service-list/
+ String str = path.substring(idx + 13);
+ idx = str.indexOf("/");
+ //if there is another forward slash with more information chomp it off
+ if (idx != -1) {
+ return str.substring(0, idx);
+ } else {
+ return str;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java
new file mode 100644
index 000000000..3f9f93fc5
--- /dev/null
+++ b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java
@@ -0,0 +1,7 @@
+package org.onap.ccsdk.sli.core.filters;
+
+import org.onap.logging.filter.base.PayloadLoggingServletFilter;
+
+public class ControllerPayloadLoggingFilter extends PayloadLoggingServletFilter {
+
+}
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersService.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersService.java
deleted file mode 100644
index 9587e8d96..000000000
--- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersService.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package org.onap.ccsdk.sli.core.filters;
-
-public interface FiltersService {
-}
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersServiceImpl.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersServiceImpl.java
deleted file mode 100644
index 12370ca9a..000000000
--- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/FiltersServiceImpl.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.filters;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FiltersServiceImpl implements FiltersService {
- private static final Logger LOG = LoggerFactory.getLogger(FiltersServiceImpl.class);
-
- public FiltersServiceImpl() {
- LOG.debug("Registering {}", FiltersServiceImpl.class.getName());
- }
-}
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java
deleted file mode 100644
index 4481ab904..000000000
--- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Modifications Copyright (C) 2018 IBM.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.filters;
-
-import java.io.IOException;
-import java.util.UUID;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.codec.binary.Base64;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-
-
-/**
- * Logs IN request according ECOMP Logging Guidelines at https://tspace.web.att.com/viewer/app/lcfiles/ae5f7751-39da-4c6b-8a83-5836c8c815e1/content
- */
-public class LogFilter implements Filter {
-
- //X-ECOMP is shared between audit and metric
- public static final String BEGIN_TIMESTAMP = "AUDIT-BeginTimestamp";
- public static final String END_TIMESTAMP = "AUDIT-EndTimestamp";
- public static final String REQUEST_ID = "X-ECOMP-RequestID";
- public static final String SERVICE_INSTANCE = "X-ECOMP-ServiceInstanceID";
- public static final String THREAD_ID ="X-ECOMP-ThreadId"; //optional
- public static final String PHYSICAL_SERVER_NAME="X-ECOMP-PhysicalServerName"; //optional
- public static final String SERVICE_NAME="X-ECOMP-ServiceName";
- public static final String PARTNER_NAME="X-ECOMP-PartnerName";
- public static final String STATUS_CODE="AUDIT-StatusCode";
- public static final String RESP_CODE="AUDIT-ResponseCode";
- public static final String RESP_DESC="AUDIT-ResponseDescription";
- public static final String INSTANCE_UUID="AUDIT-InstanceUUID";
- public static final String CATEGORY="AUDIT-INFO";
- public static final String SEVERITY ="AUDIT-Severity"; //optional
- public static final String SERVER_IP="AUDIT-ServerIP"; //by chef node['ip']
- public static final String ELAPSED_TIME="AUDIT-ElapsedTime";
- public static final String SERVER_HOST="AUDIT-Server";//by chef node['fqdn']
- public static final String CLIENT_IP="AUDIT-ClientIPaddress";
- public static final String CLASS="AUDIT-Classname"; //optional
- public static final String UNUSED="AUDIT-Unused"; //empty
- public static final String PROCESS_KEY="AUDIT-ProcessKey"; //optional
- public static final String CUST_1="AUDIT-CustomField1";//optional
- public static final String CUST_2="AUDIT-CustomField2"; //optional
- public static final String CUST_3="AUDIT-CustomField3"; //optional
- public static final String CUST_4="AUDIT-CustomField4"; //optional
- public static final String DETAIL_MESSAGE="AUDIT-DetailMessage";//optional
-
-
- private static final Logger log = LoggerFactory.getLogger(LogFilter.class);
- private static final Logger AUDIT = LoggerFactory.getLogger("org.onap.ccsdk.sli.core.filters.audit");
- @Override
- public void destroy() {
- // this method does nothing
- }
-
- @Override
- public void doFilter(final ServletRequest request, final ServletResponse response,
- final FilterChain filterChain) throws IOException, ServletException {
-
- long startTime = System.currentTimeMillis();
- try {
-
- if ( request != null && request instanceof HttpServletRequest ) {
- pre((HttpServletRequest)request);
- }
- filterChain.doFilter(request, response);
-
-
- } finally {
-
- if (request != null && request instanceof HttpServletRequest ) {
- post((HttpServletRequest)request,(HttpServletResponse)response,startTime);
- }
- MDC.clear();
- }
-
- }
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- // this method does nothing
- }
-
-
-
- private void pre(HttpServletRequest request) {
-
- UUID uuid = UUID.randomUUID();
- // check if uuid is in header X-ECOMP-RequestID
-
- String ecompUUID = request.getHeader(REQUEST_ID);
-
- if (ecompUUID != null && ecompUUID.length() > 0) {
- try {
- uuid = UUID.fromString(ecompUUID);
- log.info("UUID is ECOMP UUID " + uuid.toString());
- } catch (Exception ex){
- log.warn("Failed to convert ECOMP UUID to java.util.UUID format:" + ecompUUID,ex);
- }
- }
- MDC.put(REQUEST_ID, uuid.toString());
-
- String userName="unknown";
-
-
- // going directly after Authorization header
- if (request.getHeader("Authorization") != null) {
- String authzHeader = request.getHeader("Authorization");
- String usernameAndPassword = new String(Base64.decodeBase64(authzHeader.substring(6).getBytes()));
-
- int userNameIndex = usernameAndPassword.indexOf(':');
- String username = usernameAndPassword.substring(0, userNameIndex);
- userName = username;
-
- }
-
-
- MDC.put(PARTNER_NAME, userName);
- //just to initilaze for metric logger (outbound calls)
- MDC.put("X-ECOMP-TargetEntity","");
- MDC.put("X-ECOMP-TargetServiceName","");
-
- MDC.put(SERVICE_NAME,request.getRequestURL().toString());
- MDC.put(SERVICE_INSTANCE,"");
-
- }
-
-
- private void post(HttpServletRequest request,HttpServletResponse response,long startTime) {
-
- MDC.put(BEGIN_TIMESTAMP,asIso8601(startTime));
- MDC.put(END_TIMESTAMP,asIso8601(System.currentTimeMillis()));
- MDC.put(SERVICE_NAME,request.getRequestURL().toString());
- int idx = request.getPathInfo().lastIndexOf(':');
- String instance = "";
- if ( idx != -1 ) {
- instance = request.getPathInfo().substring(idx+1);
- }
- MDC.put(SERVICE_INSTANCE,instance);
- MDC.put(THREAD_ID,"");
- MDC.put(PHYSICAL_SERVER_NAME,"");
- if ( response.getStatus() >= 400 ) {
- MDC.put(STATUS_CODE,"ERROR");
- } else {
- MDC.put(STATUS_CODE,"COMPLETE");
- }
-
- MDC.put(RESP_CODE, Integer.toString(response.getStatus()));
- MDC.put(RESP_DESC,"");
- MDC.put(INSTANCE_UUID,"");
- MDC.put(CATEGORY,"");
- MDC.put(SEVERITY,"");
- //MDC.put(SERVER_IP,""); //by chef
- MDC.put(ELAPSED_TIME,Long.toString(System.currentTimeMillis() - startTime));
- //MDC.put(SERVER_HOST,""); //by chef
- String forwardedHost = request.getHeader("X-Forwarded-For");
- if (forwardedHost != null) {
- MDC.put(CLIENT_IP, forwardedHost);
- }
- else{
- MDC.put(CLIENT_IP,request.getRemoteHost());
- }
- MDC.put(CLASS,"");
- MDC.put(UNUSED,"");
- MDC.put(PROCESS_KEY,"");
- MDC.put(CUST_1,"");
- MDC.put(CUST_2,"");
- MDC.put(CUST_3,"");
- MDC.put(CUST_4,"");
- MDC.put(DETAIL_MESSAGE,request.getMethod());
-
- AUDIT.info("");
- }
-
- private String asIso8601(Date date) {
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss.SS'+00:00'");
- df.setTimeZone(tz);
- return df.format(date);
- }
-
- private String asIso8601(long tsInMillis) {
- return asIso8601(new Date(tsInMillis));
- }
-
-
-}
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java
deleted file mode 100644
index e24a75274..000000000
--- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Modifications Copyright (C) 2018 IBM.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.filters;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.util.Enumeration;
-import java.util.zip.GZIPInputStream;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ReadListener;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.WriteListener;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-
-public class RequestResponseLoggingFilter implements Filter {
-
- private static org.slf4j.Logger log =
- org.slf4j.LoggerFactory.getLogger("org.onap.ccsdk.sli.core.filters.request.response");
-
- private static class ByteArrayServletStream extends ServletOutputStream {
-
- ByteArrayOutputStream baos;
-
- ByteArrayServletStream(ByteArrayOutputStream baos) {
- this.baos = baos;
- }
-
- @Override
- public void write(int param) throws IOException {
- baos.write(param);
- }
-
- @Override
- public boolean isReady() {
- return true;
- }
-
- @Override
- public void setWriteListener(WriteListener arg0) {
- // this method does nothing
-
- }
- }
-
- private static class ByteArrayPrintWriter extends PrintWriter {
- private ByteArrayOutputStream baos;
- private int errorCode = -1;
- private String errorMsg = "";
- private boolean errored = false;
-
- public ByteArrayPrintWriter(ByteArrayOutputStream out) {
- super(out);
- this.baos = out;
- }
-
- public ServletOutputStream getStream() {
- return new ByteArrayServletStream(baos);
- }
-
- public Boolean hasErrored() {
- return errored;
- }
- public int getErrorCode() {
- return errorCode;
- }
- public String getErrorMsg() {
- return errorMsg;
- }
-
- public void setError(int code) {
- errorCode = code;
- errored = true;
- }
-
- public void setError(int code, String msg) {
- errorMsg = msg;
- errorCode = code;
- errored = true;
- }
-
- }
-
- private class BufferedServletInputStream extends ServletInputStream {
-
- ByteArrayInputStream bais;
-
- public BufferedServletInputStream(ByteArrayInputStream bais) {
- this.bais = bais;
- }
-
- @Override
- public int available() {
- return bais.available();
- }
-
- @Override
- public int read() {
- return bais.read();
- }
-
- @Override
- public int read(byte[] buf, int off, int len) {
- return bais.read(buf, off, len);
- }
-
- @Override
- public boolean isFinished() {
- return available() < 1;
- }
-
- @Override
- public boolean isReady() {
- return true;
- }
-
- @Override
- public void setReadListener(ReadListener arg0) {
- // this method does nothing
- }
-
- }
-
- private class BufferedRequestWrapper extends HttpServletRequestWrapper {
-
- ByteArrayInputStream bais;
-
- ByteArrayOutputStream baos;
-
- BufferedServletInputStream bsis;
-
- byte[] buffer;
-
- public BufferedRequestWrapper(HttpServletRequest req) throws IOException {
- super(req);
-
- InputStream is = req.getInputStream();
- baos = new ByteArrayOutputStream();
- byte[] buf = new byte[1024];
- int letti;
- while ((letti = is.read(buf)) > 0) {
- baos.write(buf, 0, letti);
- }
- buffer = baos.toByteArray();
-
- }
-
- @Override
- public ServletInputStream getInputStream() {
- try {
- bais = new ByteArrayInputStream(buffer);
- bsis = new BufferedServletInputStream(bais);
- } catch (Exception ex) {
- log.error("Exception in getInputStream", ex);
- }
-
- return bsis;
- }
-
- public byte[] getBuffer() {
- return buffer;
- }
-
- }
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- // this method does nothing
- }
-
- @Override
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
- throws IOException, ServletException {
-
- final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
- BufferedRequestWrapper bufferedRequest = new BufferedRequestWrapper(httpRequest);
-
- StringBuilder requestHeaders = new StringBuilder("REQUEST|");
- requestHeaders.append(httpRequest.getMethod());
- requestHeaders.append(":");
- requestHeaders.append(httpRequest.getRequestURL().toString());
- requestHeaders.append("|");
- String header;
- for (Enumeration<String> e = httpRequest.getHeaderNames(); e.hasMoreElements();) {
- header = e.nextElement();
- requestHeaders.append(header);
- requestHeaders.append(":");
- requestHeaders.append(httpRequest.getHeader(header));
- requestHeaders.append(";");
-
- }
- log.info(requestHeaders.toString());
-
- log.info("REQUEST BODY|" + new String(bufferedRequest.getBuffer()));
-
- final HttpServletResponse response = (HttpServletResponse) servletResponse;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final ByteArrayPrintWriter pw = new ByteArrayPrintWriter(baos);
-
- HttpServletResponse wrappedResp = new HttpServletResponseWrapper(response) {
- @Override
- public PrintWriter getWriter() {
- return pw;
- }
-
- @Override
- public ServletOutputStream getOutputStream() {
- return pw.getStream();
- }
-
- @Override
- public void sendError(int sc) throws IOException {
- super.sendError(sc);
- pw.setError(sc);
-
- }
- @Override
- public void sendError(int sc, String msg) throws IOException {
- super.sendError(sc, msg);
- pw.setError(sc, msg);
- }
- };
-
- try {
- filterChain.doFilter(bufferedRequest, wrappedResp);
- } catch (Exception e) {
- log.error("Chain Exception", e);
- throw e;
- } finally {
- try {
- byte[] bytes = baos.toByteArray();
- StringBuilder responseHeaders = new StringBuilder("RESPONSE HEADERS|");
-
- for (String headerName : response.getHeaderNames()) {
- responseHeaders.append(headerName);
- responseHeaders.append(":");
- responseHeaders.append(response.getHeader(headerName));
- responseHeaders.append(";");
- }
- responseHeaders.append("Status:");
- responseHeaders.append(response.getStatus());
- responseHeaders.append(";IsCommited:" + wrappedResp.isCommitted());
-
- log.info(responseHeaders.toString());
-
- if ("gzip".equals(response.getHeader("Content-Encoding"))) {
-
- log.info("UNGZIPED RESPONSE BODY|" + decompressGZIPByteArray(bytes));
-
- } else {
-
- log.info("RESPONSE BODY|" + new String(bytes));
- }
-
- if (pw.hasErrored()) {
- log.info("ERROR RESPONSE|" + pw.getErrorCode() + ":" + pw.getErrorMsg());
- } else {
- if (!wrappedResp.isCommitted()){
- response.getOutputStream().write(bytes);
- response.getOutputStream().flush();
- }
- }
-
- } catch (Exception e) {
- log.error("Exception in response filter", e);
- }
-
- }
- }
-
- @Override
- public void destroy() {
- // this method does nothing
- }
-
- private String decompressGZIPByteArray(byte[] bytes) {
-
- BufferedReader in = null;
- InputStreamReader inR = null;
- ByteArrayInputStream byteS = null;
- GZIPInputStream gzS = null;
- StringBuilder str = new StringBuilder();
- try {
- byteS = new ByteArrayInputStream(bytes);
- gzS = new GZIPInputStream(byteS);
- inR = new InputStreamReader(gzS);
- in = new BufferedReader(inR);
-
- if (in != null) {
-
- String content;
-
- while ((content = in.readLine()) != null) {
- str.append(content);
- }
- }
-
- } catch (Exception e) {
- log.error("Failed get read GZIPInputStream", e);
- } finally {
-
- if (byteS != null)
- try {
- byteS.close();
- } catch (IOException e1) {
- log.error("Failed to close ByteStream", e1);
- }
- if (gzS != null)
- try {
- gzS.close();
- } catch (IOException e2) {
- log.error("Failed to close GZStream", e2);
- }
- if (inR != null)
- try {
- inR.close();
- } catch (IOException e3) {
- log.error("Failed to close InputReader", e3);
- }
- if (in != null)
- try {
- in.close();
- } catch (IOException e) {
- log.error("Failed to close BufferedReader", e);
- }
- }
- return str.toString();
- }
-}
diff --git a/filters/provider/src/main/resources/OSGI-INF/blueprint/filters-blueprint.xml b/filters/provider/src/main/resources/OSGI-INF/blueprint/filters-blueprint.xml
deleted file mode 100644
index 3bf8423e9..000000000
--- a/filters/provider/src/main/resources/OSGI-INF/blueprint/filters-blueprint.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
- odl:use-default-for-reference-types="true">
-
- <bean id="filters" class="org.onap.ccsdk.sli.core.filters.FiltersServiceImpl" />
- <service ref="filters" interface="org.onap.ccsdk.sli.core.filters.FiltersService" />
-
-</blueprint>
diff --git a/filters/provider/src/main/resources/org/opendaylight/blueprint/filters-blueprint.xml b/filters/provider/src/main/resources/org/opendaylight/blueprint/filters-blueprint.xml
deleted file mode 100644
index 3bf8423e9..000000000
--- a/filters/provider/src/main/resources/org/opendaylight/blueprint/filters-blueprint.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
- odl:use-default-for-reference-types="true">
-
- <bean id="filters" class="org.onap.ccsdk.sli.core.filters.FiltersServiceImpl" />
- <service ref="filters" interface="org.onap.ccsdk.sli.core.filters.FiltersService" />
-
-</blueprint>
diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java
new file mode 100644
index 000000000..9d0357a96
--- /dev/null
+++ b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java
@@ -0,0 +1,23 @@
+package org.onap.ccsdk.sli.core.filters;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+public class ControllerAuditLogFilterTest {
+
+ @Test
+ public void getSimpleSiid() throws Exception {
+ ControllerAuditLogFilter filter = new ControllerAuditLogFilter();
+ String siid = filter.getServiceInstanceId("/restconf/config/Layer3API:services/service-list/100");
+ assertEquals("100", siid);
+ }
+
+ @Test
+ public void getSimpleComplexSiid() throws Exception {
+ ControllerAuditLogFilter filter = new ControllerAuditLogFilter();
+ String siid = filter.getServiceInstanceId(
+ "/restconf/config/Layer3API:services/service-list/1337/service-data/oper-status");
+ assertEquals("1337", siid);
+ }
+
+}
diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java
deleted file mode 100644
index a900b246c..000000000
--- a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- *
- */
-package org.onap.ccsdk.sli.core.filters;
-
-import static org.junit.Assert.*;
-import org.apache.commons.codec.binary.Base64;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import static org.mockito.Mockito.*;
-import java.io.IOException;
-import java.util.UUID;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author dt5972
- *
- */
-public class TestLogFilter {
-
- LogFilter logFilter;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- logFilter = new LogFilter();
- logFilter.init(null);
- }
-
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- logFilter.destroy();
- }
-
- /**
- * Test method for {@link org.onap.ccsdk.sli.core.filters.LogFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}.
- * @throws ServletException
- * @throws IOException
- */
- @Test
- public void testDoFilter() throws IOException, ServletException {
-
- // Test failed request with minimal headers
- HttpServletRequest servletReq = mock(HttpServletRequest.class);
- when(servletReq.getRequestURL()).thenReturn(new StringBuffer("SLI-API:healthcheck"));
- when(servletReq.getPathInfo()).thenReturn("/hello:world");
- HttpServletResponse servletResp = mock(HttpServletResponse.class);
- when(servletResp.getStatus()).thenReturn(400);
- FilterChain filterChain = mock(FilterChain.class);
- logFilter.doFilter(servletReq, servletResp, filterChain);
-
- // Test successful request with valid header
- when(servletReq.getHeader(LogFilter.REQUEST_ID)).thenReturn(UUID.randomUUID().toString());
- when(servletReq.getHeader("Authorization")).thenReturn("Basic "+Base64.encodeBase64String("username:password".getBytes()));
- when(servletResp.getStatus()).thenReturn(200);
- logFilter.doFilter(servletReq, servletResp, filterChain);
-
-
- }
-
-}
diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java
deleted file mode 100644
index 7ce856e68..000000000
--- a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/**
- *
- */
-package org.onap.ccsdk.sli.core.filters;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringBufferInputStream;
-import java.io.StringReader;
-import java.util.LinkedList;
-import java.util.UUID;
-import java.util.Vector;
-import javax.servlet.FilterChain;
-import javax.servlet.ReadListener;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.WriteListener;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.codec.binary.Base64;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author dt5972
- *
- */
-public class TestRequestResponseLoggingFilter {
-
- RequestResponseLoggingFilter filter;
-
- private class DummyServletInputStream extends ServletInputStream {
-
- InputStream stream;
-
- public DummyServletInputStream(InputStream stream) {
- this.stream = stream;
- }
-
-
- @Override
- public void close() throws IOException {
- super.close();
- stream.close();
- }
-
-
- @Override
- public int read() throws IOException {
- return stream.read();
- }
-
-
- @Override
- public boolean isFinished() {
- try {
- return stream.available() < 1;
- } catch (IOException e) {
- return true;
- }
- }
-
-
- @Override
- public boolean isReady() {
- // TODO Auto-generated method stub
- return true;
- }
-
-
- @Override
- public void setReadListener(ReadListener arg0) {
- // TODO Auto-generated method stub
-
- }
-
-
-
- }
-
- private class DummyServletOutputStream extends ServletOutputStream {
-
- OutputStream ostr;
-
- public DummyServletOutputStream(OutputStream ostr) {
- this.ostr = ostr;
- }
-
- @Override
- public void write(int b) throws IOException {
- ostr.write(b);
- }
-
- @Override
- public boolean isReady() {
- return true;
- }
-
- @Override
- public void setWriteListener(WriteListener arg0) {
-
- }
-
- }
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- filter = new RequestResponseLoggingFilter();
- filter.init(null);
- }
-
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {}
-
- /**
- * Test method for {@link org.onap.ccsdk.sli.core.filters.RequestResponseLoggingFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}.
- * @throws IOException
- * @throws ServletException
- */
- @Test
- public void testDoFilter() throws IOException, ServletException {
-
- HttpServletRequest request = mock(HttpServletRequest.class);
- String msgBody = "hello world";
- InputStream reqInputStream = new ByteArrayInputStream(msgBody.getBytes());
- when(request.getInputStream()).thenReturn(new DummyServletInputStream(reqInputStream));
- when(request.getMethod()).thenReturn("POST");
- when(request.getRequestURL()).thenReturn(new StringBuffer("/HELLO:world"));
- when(request.getPathInfo()).thenReturn("/hello:world");
- Vector<String> headerList = new Vector<>();
- headerList.add(LogFilter.REQUEST_ID);
- headerList.add("Authorization");
- when(request.getHeaderNames()).thenReturn(headerList.elements());
-
- when(request.getHeader(LogFilter.REQUEST_ID)).thenReturn(UUID.randomUUID().toString());
- when(request.getHeader("Authorization")).thenReturn("Basic "+Base64.encodeBase64String("username:password".getBytes()));
-
- HttpServletResponse response = mock(HttpServletResponse.class);
- OutputStream outStr = new ByteArrayOutputStream();
- when(response.getOutputStream()).thenReturn(new DummyServletOutputStream(outStr));
-
- FilterChain filterChain = mock(FilterChain.class);
-
- filter.doFilter(request, response, filterChain);
-
-
-
- }
-
-}