aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2022-05-04 11:53:01 +0100
committersourabh_sourabh <sourabh.sourabh@est.tech>2022-05-06 13:43:46 +0100
commita7863efca29d19ea07b3cdbad23e2b4335694c97 (patch)
treeef80f4eaf7b66fd75ad3942884ed7a8043c97f53
parentab3c7378c0cf96021856171d80b14b5a839f192e (diff)
Security Logging Fields
- logback encoder and sleuth dependencies are added. - New appender is added to log JSON format content on console. Issue-ID: CPS-986 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Change-Id: I9e45a9d842831a87af3fb9ac309485110357f0c8
-rwxr-xr-xpom.xml33
-rwxr-xr-xsrc/main/resources/application.yml8
-rw-r--r--src/main/resources/logback-spring.xml74
-rw-r--r--src/main/resources/logback.xml43
-rw-r--r--src/test/resources/application.yml5
5 files changed, 118 insertions, 45 deletions
diff --git a/pom.xml b/pom.xml
index 9b6612f..a2931f7 100755
--- a/pom.xml
+++ b/pom.xml
@@ -60,6 +60,11 @@
<scope>import</scope>
</dependency>
<dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+ <version>3.1.1</version>
+ </dependency>
+ <dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-bom</artifactId>
<version>2.0-M4-groovy-3.0</version>
@@ -73,6 +78,21 @@
<type>pom</type>
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>net.logstash.logback</groupId>
+ <artifactId>logstash-logback-encoder</artifactId>
+ <version>7.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.janino</groupId>
+ <artifactId>janino</artifactId>
+ <version>3.1.7</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vladmihalcea</groupId>
+ <artifactId>hibernate-types-52</artifactId>
+ <version>2.10.0</version>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -104,7 +124,6 @@
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
- <version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
@@ -206,6 +225,18 @@
<version>0.18.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.logstash.logback</groupId>
+ <artifactId>logstash-logback-encoder</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.janino</groupId>
+ <artifactId>janino</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 7db9510..9b3be03 100755
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -25,6 +25,8 @@ rest:
base-path: /cps-temporal/api
spring:
+ application:
+ name: cps-temporal
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/cpstemporaldb
username: ${DB_USERNAME}
@@ -90,4 +92,8 @@ management:
show-details: always
# kubernetes probes: liveness and readiness
probes:
- enabled: true \ No newline at end of file
+ enabled: true
+
+logging:
+ format: json
+ \ No newline at end of file
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..c71c9a6
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,74 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (c) 2021 Bell Canada.
+ Modifications Copyright (C) 2022 Nordix Foundation
+ ================================================================================
+ 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=========================================================
+-->
+
+<configuration scan="true" scanPeriod="30 seconds" debug="false">
+
+ <include resource="org/springframework/boot/logging/logback/defaults.xml" />
+ <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
+
+ <springProperty scope="context" name="springAppName" source="spring.application.name"/>
+ <springProperty scope="context" name="username" source="security.auth.username"/>
+ <springProperty scope="context" name="loggingFormat" source="logging.format"/>
+
+ <property name="currentTimeStamp" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}"/>
+
+ <appender name="jsonConsole"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
+ <providers>
+ <pattern>
+ <omitEmptyFields>true</omitEmptyFields>
+ <pattern>
+ {
+ "logTimeStamp": "${currentTimeStamp:-}",
+ "logTypeName": "",
+ "logLevel": "%level",
+ "traceId": "%X{traceId:-}",
+ "statusCode": "",
+ "principalId": "${username:-}",
+ "serviceName": "${springAppName:-}",
+ "message": "%message",
+ "spanId": "%X{spanId:-}",
+ "processId": "${PID:-}",
+ "threadName": "%thread",
+ "class": "%logger{40}",
+ "exception": "%wEx"
+ }
+ </pattern>
+ </pattern>
+ </providers>
+ </encoder>
+ </appender>
+
+ <appender name="asyncConsole" class="ch.qos.logback.classic.AsyncAppender">
+ <if condition='property("loggingFormat").equalsIgnoreCase("json")'>
+ <then>
+ <appender-ref ref="jsonConsole"/>
+ </then>
+ <else>
+ <appender-ref ref="CONSOLE"/>
+ </else>
+ </if>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="asyncConsole"/>
+ </root>
+
+</configuration>
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
deleted file mode 100644
index a75b7aa..0000000
--- a/src/main/resources/logback.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (c) 2021 Bell Canada.
- ================================================================================
- 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=========================================================
--->
-
-<configuration>
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>%d - %highlight(%-5level) [%-20.20thread] %cyan(%logger{36}) - %msg%n</pattern>
- </encoder>
- </appender>
-
- <!-- Logger for cps classes -->
- <logger name="org.onap.cps" level="info"/>
-
- <!-- Logger for sql statements. Set to info to disable, debug to enable -->
- <logger name="org.hibernate.SQL" level="info"/>
-
- <!-- Logger for sql bindings. Set to info to disable, to trace to enable -->
- <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="info"/>
-
- <!-- Logger for hibernate statistics. Set to warn to disable, to info to enable -->
- <logger name="org.hibernate.engine.internal.StatisticalLoggingSessionEventListener" level="warn"/>
-
- <root level="info">
- <appender-ref ref="STDOUT" />
- </root>
-
-</configuration>
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index 9bdacbe..ce0e95b 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -24,6 +24,8 @@ rest:
base-path: /cps-temporal/api
spring:
+ application:
+ name: cps-temporal
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
@@ -71,3 +73,6 @@ security:
auth:
username: testUser
password: testPassword
+
+logging:
+ format: json