diff --git a/avni-server-api/src/main/java/org/avni/server/framework/tomcat/TomcatContainerCustomizer.java b/avni-server-api/src/main/java/org/avni/server/framework/tomcat/TomcatContainerCustomizer.java index b68ee7635..80ca9a765 100644 --- a/avni-server-api/src/main/java/org/avni/server/framework/tomcat/TomcatContainerCustomizer.java +++ b/avni-server-api/src/main/java/org/avni/server/framework/tomcat/TomcatContainerCustomizer.java @@ -1,19 +1,27 @@ package org.avni.server.framework.tomcat; +import org.apache.catalina.Valve; +import org.apache.catalina.valves.AccessLogValve; import org.apache.tomcat.util.http.Rfc6265CookieProcessor; import org.apache.tomcat.util.http.SameSiteCookies; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.stereotype.Component; +import java.util.Collection; + @Component public class TomcatContainerCustomizer implements WebServerFactoryCustomizer { private static final Logger LOGGER = LoggerFactory.getLogger(TomcatContainerCustomizer.class); + @Value("${server.tomcat.accesslog.max-days}") + int accessLogMaxDays; + @Override public void customize(TomcatServletWebServerFactory factory) { if (factory != null) { @@ -23,6 +31,14 @@ public void customize(TomcatServletWebServerFactory factory) { }); factory.addContextCustomizers(sameSiteCookiesConfig()); LOGGER.info("Enabled secure scheme (https)."); + + Collection engineValves = factory.getEngineValves(); + for (Valve tempObject : engineValves) { + if (tempObject instanceof AccessLogValve) { + AccessLogValve accessLogValve = (AccessLogValve) tempObject; + accessLogValve.setMaxDays(accessLogMaxDays); + } + } } else { LOGGER.warn("Could not change protocol scheme because Tomcat is not used as servlet container."); }