summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest/archiva-rest-services
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-12-17 00:10:02 +0100
committerMartin Stockhammer <martin_s@apache.org>2021-12-17 00:10:02 +0100
commit8ed54feb5885857c714ecc80d466b56eaeb25818 (patch)
treed640d66022d158a5115c668c259401e855ab60d9 /archiva-modules/archiva-web/archiva-rest/archiva-rest-services
parent3acb9ba358f05dd0b30cb7fa9700d099fe53b250 (diff)
downloadarchiva-8ed54feb5885857c714ecc80d466b56eaeb25818.tar.gz
archiva-8ed54feb5885857c714ecc80d466b56eaeb25818.zip
[MRM-2026] Improving audit log
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest/archiva-rest-services')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/AuditInfoFilter.java161
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml1
2 files changed, 162 insertions, 0 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/AuditInfoFilter.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/AuditInfoFilter.java
new file mode 100644
index 000000000..a0cdb4b7c
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/AuditInfoFilter.java
@@ -0,0 +1,161 @@
+package org.apache.archiva.rest.services.interceptors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+
+/**
+ * @since
+ */
+@Service("auditInfoFilter#rest")
+@Provider
+public class AuditInfoFilter implements ContainerRequestFilter
+{
+
+ private static final Logger log = LoggerFactory.getLogger( AuditInfoFilter.class );
+
+ @Context
+ private HttpServletRequest servletRequest;
+
+ private static final AuditInfoThreadLocal auditInfoThreadLocal = new AuditInfoThreadLocal();
+
+ public AuditInfoFilter() {
+
+ }
+
+ public static class AuditInfoThreadLocal extends ThreadLocal<AuditInfo> {
+
+ public AuditInfoThreadLocal() {
+
+ }
+
+ @Override
+ protected AuditInfo initialValue( )
+ {
+ return new AuditInfo();
+ }
+ }
+
+ public static class AuditInfo {
+
+ private String remoteAddress = "0.0.0.0";
+ private String localAddress = "0.0.0.0";
+ private String remoteHost = "0.0.0.0";
+ private String protocol = "";
+ private int remotePort = 0;
+ private String method = "";
+
+ public AuditInfo() {
+
+ }
+
+ public String getRemoteAddress( )
+ {
+ return remoteAddress;
+ }
+
+ public void setRemoteAddress( String remoteAddress )
+ {
+ this.remoteAddress = remoteAddress;
+ }
+
+ public String getLocalAddress( )
+ {
+ return localAddress;
+ }
+
+ public void setLocalAddress( String localAddress )
+ {
+ this.localAddress = localAddress;
+ }
+
+ public String getRemoteHost( )
+ {
+ return remoteHost;
+ }
+
+ public void setRemoteHost( String remoteHost )
+ {
+ this.remoteHost = remoteHost;
+ }
+
+ public int getRemotePort( )
+ {
+ return remotePort;
+ }
+
+ public void setRemotePort( int remotePort )
+ {
+ this.remotePort = remotePort;
+ }
+
+ public String getMethod( )
+ {
+ return method;
+ }
+
+ public void setMethod( String method )
+ {
+ this.method = method;
+ }
+
+ public String getProtocol( )
+ {
+ return protocol;
+ }
+
+ public void setProtocol( String protocol )
+ {
+ this.protocol = protocol;
+ }
+ }
+
+
+
+ @Override
+ public void filter( ContainerRequestContext containerRequestContext ) throws IOException
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug( "Filter {}, {}", servletRequest.getRemoteAddr( ), servletRequest.getRemoteHost( ) );
+ }
+ AuditInfo auditInfo = auditInfoThreadLocal.get( );
+ auditInfo.setRemoteAddress( servletRequest.getRemoteAddr( ) );
+ auditInfo.setLocalAddress( servletRequest.getLocalAddr( ) );
+ auditInfo.setProtocol( servletRequest.getProtocol( ) );
+ auditInfo.setRemoteHost( servletRequest.getRemoteHost( ) );
+ auditInfo.setRemotePort( servletRequest.getRemotePort( ) );
+ auditInfo.setMethod( containerRequestContext.getMethod( ) );
+ }
+
+ public static AuditInfo getAuditInfo() {
+ return auditInfoThreadLocal.get( );
+ }
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
index c9e677db6..f51795d86 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
@@ -50,6 +50,7 @@
<jaxrs:providers>
<ref bean="jsonProvider"/>
+ <ref bean="auditInfoFilter#rest"/>
<ref bean="authenticationInterceptor#rest"/>
<ref bean="permissionInterceptor#rest"/>
<ref bean="requestValidationInterceptor#rest" />