diff --git a/.github/workflows/spring.yml b/.github/workflows/spring.yml index b5f77606..0a78aef8 100644 --- a/.github/workflows/spring.yml +++ b/.github/workflows/spring.yml @@ -15,7 +15,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - distribution: 'corretto' + distribution: 'adopt' java-version: '16' cache: 'maven' diff --git a/pom.xml b/pom.xml index ad19d91d..678ac4c4 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.cga sctp pom - 1.4.8 + 1.4.9 org.springframework.boot diff --git a/sctp-api/pom.xml b/sctp-api/pom.xml index 8d21b48f..3d979cd6 100644 --- a/sctp-api/pom.xml +++ b/sctp-api/pom.xml @@ -5,7 +5,7 @@ sctp org.cga - 1.4.8 + 1.4.9 4.0.0 diff --git a/sctp-api/src/main/java/org/cga/sctp/api/config/ApiConfiguration.java b/sctp-api/src/main/java/org/cga/sctp/api/config/ApiConfiguration.java index 2a53c9e4..439619fa 100644 --- a/sctp-api/src/main/java/org/cga/sctp/api/config/ApiConfiguration.java +++ b/sctp-api/src/main/java/org/cga/sctp/api/config/ApiConfiguration.java @@ -40,6 +40,7 @@ import org.cga.sctp.mobile.MobileApplicationService; import org.cga.sctp.user.UserService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; @@ -82,36 +83,8 @@ public class ApiConfiguration extends WebSecurityConfigurerAdapter { @Autowired private MobileApplicationService mobileApplicationService; -/* @Bean - OperationCustomizer customize() { - return (operation, handlerMethod) -> { - operation.responses(new ApiResponses() - .addApiResponse("Mobile Application Version", new ApiResponse() - .addHeaderObject( - AppConstants.APP_VERSION_CODE_HEADER, new Header() - .schema(new IntegerSchema()) - .description("Current application version code") - ) - .addHeaderObject( - AppConstants.APP_VERSION_UPDATE_AVAILABLE_HEADER, new Header() - .schema(new BooleanSchema()) - .description("Whether an update is available") - ) - .addHeaderObject( - AppConstants.APP_VERSION_UPDATE_TIME_HEADER, new Header() - .schema(new DateTimeSchema()) - .description("When the new application became available") - ) - .addHeaderObject( - AppConstants.APP_VERSION_UPDATE_MANDATORY, new Header() - .schema(new BooleanSchema()) - .description("Whether the update is mandatory or not") - ) - ) - ); - return operation; - }; - }*/ + @Value("${api.checkAppVersion:false}") + private boolean checkAppVersion; @Override public void configure(WebSecurity web) throws Exception { @@ -148,7 +121,7 @@ public void configure(WebSecurity web) throws Exception { @Bean public AppVersionFilter apiVersionFilter() { - return new AppVersionFilter(mobileApplicationService, gson, ALLOW_LIST); + return new AppVersionFilter(mobileApplicationService, checkAppVersion, gson, ALLOW_LIST); } @Bean diff --git a/sctp-api/src/main/java/org/cga/sctp/api/config/AppConfiguration.java b/sctp-api/src/main/java/org/cga/sctp/api/config/AppConfiguration.java index 3b273c2f..3c9e14c6 100644 --- a/sctp-api/src/main/java/org/cga/sctp/api/config/AppConfiguration.java +++ b/sctp-api/src/main/java/org/cga/sctp/api/config/AppConfiguration.java @@ -92,9 +92,7 @@ public void setContextPath(String contextPath) { @Bean("customGson") public Gson gson() { - return new GsonBuilder() - .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()) - .registerTypeAdapter(LocalDate.class, new LocalDateAdapter()) - .create(); + return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()) + .registerTypeAdapter(LocalDate.class, new LocalDateAdapter()).create(); } } diff --git a/sctp-api/src/main/java/org/cga/sctp/api/filters/AppVersionFilter.java b/sctp-api/src/main/java/org/cga/sctp/api/filters/AppVersionFilter.java index c16cf7ef..fa5fa12d 100644 --- a/sctp-api/src/main/java/org/cga/sctp/api/filters/AppVersionFilter.java +++ b/sctp-api/src/main/java/org/cga/sctp/api/filters/AppVersionFilter.java @@ -59,11 +59,12 @@ public class AppVersionFilter extends GenericFilterBean { private final Gson gson; + private final boolean filterEnabled; private final AtomicReference appVersion; private final List ignoredPathMatchers; private final MobileApplicationService mobileApplicationService; - public AppVersionFilter(MobileApplicationService mobileApplicationService, Gson gson, String... ignoredPaths) { + public AppVersionFilter(MobileApplicationService mobileApplicationService, boolean filterEnabled, Gson gson, String... ignoredPaths) { this.gson = gson; this.appVersion = new AtomicReference<>(); this.ignoredPathMatchers = new LinkedList<>(); @@ -73,9 +74,14 @@ public AppVersionFilter(MobileApplicationService mobileApplicationService, Gson this.ignoredPathMatchers.add(new AntPathRequestMatcher(pathPattern)); } } + this.filterEnabled = filterEnabled; this.refreshVersion(); } + public AppVersionFilter(MobileApplicationService mobileApplicationService, Gson gson, String... ignoredPaths) { + this(mobileApplicationService, true, gson, ignoredPaths); + } + private boolean ignorePath(HttpServletRequest request) { for (AntPathRequestMatcher requestMatcher : ignoredPathMatchers) { if (requestMatcher.matches(request)) { @@ -86,16 +92,22 @@ private boolean ignorePath(HttpServletRequest request) { } @Override - public void doFilter( - ServletRequest servletRequest, - ServletResponse servletResponse, - FilterChain filterChain) throws IOException, ServletException { + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { int applicationVersionCode = -1; AppVersion version = appVersion.get(); HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; + if (!filterEnabled) { + response.addHeader(AppConstants.APP_VERSION_CODE_HEADER, version.getVersionCode().toString()); + response.addHeader(AppConstants.APP_VERSION_UPDATE_TIME_HEADER, version.getUpdatedAt().toString()); + response.addHeader(AppConstants.APP_VERSION_UPDATE_AVAILABLE_HEADER, "false"); + response.addHeader(AppConstants.APP_VERSION_UPDATE_MANDATORY, version.getMandatoryUpdate().toString()); + filterChain.doFilter(request, response); + return; + } + if (ignorePath(request)) { filterChain.doFilter(request, response); return; diff --git a/sctp-core/pom.xml b/sctp-core/pom.xml index 1455bb81..1c664e4b 100644 --- a/sctp-core/pom.xml +++ b/sctp-core/pom.xml @@ -5,7 +5,7 @@ sctp org.cga - 1.4.8 + 1.4.9 4.0.0 diff --git a/sctp-mis/pom.xml b/sctp-mis/pom.xml index ff249065..4cb80dd7 100644 --- a/sctp-mis/pom.xml +++ b/sctp-mis/pom.xml @@ -5,7 +5,7 @@ sctp org.cga - 1.4.8 + 1.4.9 4.0.0