diff --git a/pom.xml b/pom.xml
index e029ac617..ffd2470e1 100755
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
opensrp-server-web
war
- 2.8.48-SNAPSHOT
+ 2.9.0-SNAPSHOT
opensrp-server-web
OpenSRP Server Web Application
https://github.com/OpenSRP/opensrp-server-web
@@ -14,24 +14,23 @@
9979
${project.basedir}
- 5.4.12.Final
+ 5.4.24.Final
UTF-8
- 5.2.4.RELEASE
- 5.3.12.RELEASE
- 2.4.0.RELEASE
- 2.9.2
- 2.2.4.RELEASE
- 3.2.0
- 5.2.2.RELEASE
+ 5.2.19.RELEASE
+ 5.2.15.RELEASE
+ 2.4.2.RELEASE
+ 3.0.0
+ 2.2.13.RELEASE
+ 3.8.0
always
1.5.1
- 2.12.24-SNAPSHOT
- 2.3.6-SNAPSHOT
+ 2.13.0-SNAPSHOT
+ 2.4.0-SNAPSHOT
2.0.1-SNAPSHOT
- 2.0.3-SNAPSHOT
2.0.5
- 1.0.3-SNAPSHOT
+ 1.1.1-SNAPSHOT
1.18.12
+ 2.17.1
@@ -160,16 +159,6 @@
opensrp-server-connector
${opensrp.connector.version}
-
- org.smartregister
- opensrp-server-common
- ${opensrp.common.version}
-
-
- org.slf4j
- slf4j-log4j12
- 1.6.6
-
org.springframework.security
spring-security-core
@@ -250,7 +239,7 @@
commons-codec
commons-codec
- 1.9
+ 1.15
org.springframework.security
@@ -275,7 +264,7 @@
org.keycloak
keycloak-spring-security-adapter
- 9.0.3
+ 16.1.0
com.fasterxml.jackson.core
@@ -285,7 +274,7 @@
org.owasp.encoder
encoder
- 1.2.2
+ 1.2.3
org.projectlombok
@@ -313,7 +302,7 @@
junit
junit
- 4.13.1
+ 4.13.2
test
@@ -355,7 +344,7 @@
org.apache.maven
maven-artifact
- 3.0.3
+ 3.8.1
org.jeasy
@@ -370,7 +359,7 @@
com.jayway.jsonpath
json-path
- 2.4.0
+ 2.6.0
@@ -386,14 +375,14 @@
io.sentry
sentry-log4j2
- 5.5.2
+ 5.6.0
io.lettuce
lettuce-core
- 5.2.2.RELEASE
+ 6.1.6.RELEASE
org.springframework
@@ -413,17 +402,22 @@
org.apache.logging.log4j
log4j-slf4j-impl
- 2.17.1
+ ${log4j.version}
org.apache.logging.log4j
log4j-jcl
- 2.17.1
+ ${log4j.version}
io.micrometer
micrometer-registry-prometheus
- 1.8.1
+ 1.8.2
+
+
+ com.google.guava
+ guava
+ 31.0.1-jre
diff --git a/src/main/java/org/opensrp/web/config/MetricsConfiguration.java b/src/main/java/org/opensrp/web/config/MetricsConfiguration.java
index 9752f306e..a88fec747 100644
--- a/src/main/java/org/opensrp/web/config/MetricsConfiguration.java
+++ b/src/main/java/org/opensrp/web/config/MetricsConfiguration.java
@@ -5,11 +5,11 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.db.PostgreSQLDatabaseMetrics;
-import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
import io.micrometer.core.instrument.binder.logging.Log4j2Metrics;
+import io.micrometer.core.instrument.binder.system.DiskSpaceMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.prometheus.PrometheusConfig;
diff --git a/src/main/java/org/opensrp/web/config/SwaggerConfig.java b/src/main/java/org/opensrp/web/config/SwaggerConfig.java
index 966da6e83..8fbb3d774 100644
--- a/src/main/java/org/opensrp/web/config/SwaggerConfig.java
+++ b/src/main/java/org/opensrp/web/config/SwaggerConfig.java
@@ -1,10 +1,13 @@
package org.opensrp.web.config;
import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
@@ -18,6 +21,7 @@
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
+import javax.servlet.ServletContext;
import java.util.List;
@Configuration
@@ -30,12 +34,19 @@ public class SwaggerConfig extends WebMvcConfigurerAdapter {
private static final String BEARER = "Bearer";
private static final String HEADER = "header";
+ @Autowired
+ private ServletContext servletContext;
+
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
- .paths(PathSelectors.regex("(/rest/.*)|(/multimedia/.*)|(/security/.*)|(/user-details)"))
+ .paths(PathSelectors.regex(
+ StringUtils.replace("(basePath/rest/.*)|(basePath/multimedia/.*)|(basePath/security/.*)|(basePath/user-details)",
+ "basePath",
+ servletContext.getContextPath()
+ ))) // To be revisited on v3.0.1
.build()
.apiInfo(getApiInfo())
.securityContexts(Lists.newArrayList(securityContext()))
@@ -54,8 +65,14 @@ public ApiInfo getApiInfo() {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
- registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
+ registry.addResourceHandler("/swagger-ui/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
+ }
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/swagger-ui/")
+ .setViewName("forward:/swagger-ui/index.html");
}
public SecurityContext securityContext() {
diff --git a/src/main/java/org/opensrp/web/config/security/filter/XssPreventionRequestWrapper.java b/src/main/java/org/opensrp/web/config/security/filter/XssPreventionRequestWrapper.java
index 9d3e27e0b..7431138d5 100644
--- a/src/main/java/org/opensrp/web/config/security/filter/XssPreventionRequestWrapper.java
+++ b/src/main/java/org/opensrp/web/config/security/filter/XssPreventionRequestWrapper.java
@@ -51,7 +51,7 @@ public ServletInputStream getInputStream() throws IOException {
@Override
public BufferedReader getReader() throws IOException {
if (rawData == null) {
- rawData = IOUtils.toByteArray(this.request.getReader(),StandardCharsets.UTF_8);
+ rawData = IOUtils.toByteArray(this.request.getReader(), StandardCharsets.UTF_8.name());
servletStream.stream = new ByteArrayInputStream(rawData);
}
updateParameters();
diff --git a/src/main/java/org/opensrp/web/rest/TemplateResource.java b/src/main/java/org/opensrp/web/rest/TemplateResource.java
index 0c3e8f530..f323c3a0e 100644
--- a/src/main/java/org/opensrp/web/rest/TemplateResource.java
+++ b/src/main/java/org/opensrp/web/rest/TemplateResource.java
@@ -2,8 +2,9 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.opensrp.domain.Template;
import org.opensrp.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/src/test/java/org/opensrp/web/config/SwaggerConfigTest.java b/src/test/java/org/opensrp/web/config/SwaggerConfigTest.java
index cbcfb93a6..50f2b5b2c 100644
--- a/src/test/java/org/opensrp/web/config/SwaggerConfigTest.java
+++ b/src/test/java/org/opensrp/web/config/SwaggerConfigTest.java
@@ -5,6 +5,13 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.reflect.internal.WhiteboxImpl;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistration;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -16,12 +23,16 @@
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
+import javax.servlet.ServletContext;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(JUnit4.class)
@@ -33,14 +44,19 @@ public class SwaggerConfigTest {
private static final String BEARER = "Bearer";
private static final String HEADER = "header";
+ @Mock
+ private ServletContext servletContext;
+
@Before
public void setUp() {
- swaggerConfig = mock(SwaggerConfig.class);
+ MockitoAnnotations.initMocks(this);
+ doReturn("/opensrp").when(servletContext).getContextPath();
+ swaggerConfig = spy(new SwaggerConfig());
+ WhiteboxImpl.setInternalState(swaggerConfig, "servletContext", servletContext);
}
@Test
public void testApi() {
- assertNull(swaggerConfig.api());
when(swaggerConfig.api()).thenReturn(createTestDocket());
when(swaggerConfig.getApiInfo()).thenReturn(createTestApiInfo());
when(swaggerConfig.securityContext()).thenReturn(createTestSecurityContext());
@@ -52,27 +68,40 @@ public void testApi() {
@Test
public void testGetApiInfo() {
- assertNull(swaggerConfig.getApiInfo());
- when(swaggerConfig.getApiInfo()).thenReturn(createTestApiInfo());
- ApiInfo apiInfo = swaggerConfig.getApiInfo();
- assertNotNull(apiInfo);
- assertEquals(apiInfo.getTitle(), "Test title");
- assertEquals(apiInfo.getDescription(), "Test description");
- assertEquals(apiInfo.getVersion(), "VERSION 1.0");
- assertEquals(apiInfo.getLicense(), "Test LICENSE");
- assertEquals(apiInfo.getLicenseUrl(), "Test license url");
+ assertNotNull(swaggerConfig.getApiInfo());
}
@Test
public void testSecurityContext() {
- assertNull(swaggerConfig.securityContext());
- when(swaggerConfig.securityContext()).thenReturn(createTestSecurityContext());
- SecurityContext securityContext= swaggerConfig.securityContext();
- assertNotNull(securityContext);
- assertEquals(securityContext.getSecurityReferences().get(0).getReference(), BASIC);
- assertEquals(securityContext.getSecurityReferences().get(0).getScopes().size(), 1);
- assertEquals(securityContext.getSecurityReferences().get(1).getReference(), BEARER);
- assertEquals(securityContext.getSecurityReferences().get(1).getScopes().size(), 1);
+ assertNotNull(swaggerConfig.securityContext());
+ }
+
+ @Test
+ public void testAddResourceHandlersShouldInvokeRegistryResourceHandler() {
+ String pathPattern = "/swagger-ui/**";
+ String resourceLocation = "classpath:/META-INF/resources/webjars/springfox-swagger-ui/";
+ ResourceHandlerRegistry mockRegistry = mock(ResourceHandlerRegistry.class);
+ ResourceHandlerRegistration mockHandlerRegistration = mock(ResourceHandlerRegistration.class);
+ doReturn(mockHandlerRegistration).when(mockRegistry).addResourceHandler(eq(pathPattern));
+
+ swaggerConfig.addResourceHandlers(mockRegistry);
+
+ verify(mockRegistry).addResourceHandler(eq(pathPattern));
+ verify(mockHandlerRegistration).addResourceLocations(eq(resourceLocation));
+ }
+
+ @Test
+ public void testAddViewControllersShouldInvokeViewControllerAddMethod() {
+ String path = "/swagger-ui/";
+ String viewName = "forward:/swagger-ui/index.html";
+ ViewControllerRegistry mockViewControllerRegistry = mock(ViewControllerRegistry.class);
+ ViewControllerRegistration mockViewControllerRegistration = mock(ViewControllerRegistration.class);
+ doReturn(mockViewControllerRegistration).when(mockViewControllerRegistry).addViewController(eq(path));
+
+ swaggerConfig.addViewControllers(mockViewControllerRegistry);
+
+ verify(mockViewControllerRegistry).addViewController(eq(path));
+ verify(mockViewControllerRegistration).setViewName(eq(viewName));
}
private Docket createTestDocket() {