Skip to content

Commit 2b2246a

Browse files
springbootdemo: Gemini review cleanup — extract OpenAPI path constants, parameterize axis2 version, remove dead code
- Extract PATH_OPENAPI_JSON/YAML/SWAGGER_UI constants in HTTPPostOnlyRejectionFilter and JWTAuthenticationFilter (both springbootdemo and tomcat11) to eliminate magic strings - Replace hardcoded 2.0.1-SNAPSHOT in antrun copy tasks with ${axis2.version} property - Delete dead OpenApiController.java — DispatcherServlet is not wired in this WAR deployment so @GetMapping handlers were never invoked; OpenApiServlet registered directly in Axis2WebAppInitializer handles these paths instead Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 69e7eb5 commit 2b2246a

6 files changed

Lines changed: 35 additions & 117 deletions

File tree

modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/security/webservices/HTTPPostOnlyRejectionFilter.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@
3838
import java.util.UUID;
3939

4040
public class HTTPPostOnlyRejectionFilter extends OncePerRequestFilter {
41-
41+
42+
private static final String PATH_OPENAPI_JSON = "/openapi.json";
43+
private static final String PATH_OPENAPI_YAML = "/openapi.yaml";
44+
private static final String PATH_SWAGGER_UI = "/swagger-ui";
45+
4246
private static Log logger = LogFactory.getLog(HTTPPostOnlyRejectionFilter.class);
43-
47+
4448
private final RedirectStrategy redirectStrategy = new NoRedirectStrategy();
4549

4650
public HTTPPostOnlyRejectionFilter() {
@@ -52,11 +56,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
5256

5357
String uuid = UUID.randomUUID().toString();
5458
String logPrefix = "HTTPPostOnlyRejectionFilter.doFilterInternal , uuid: " + uuid + " , ";
55-
59+
5660
logger.trace(logPrefix + "starting ... ");
57-
61+
5862
String uri = request.getRequestURI();
59-
boolean isOpenApiPath = uri.endsWith("/openapi.json") || uri.endsWith("/openapi.yaml") || uri.endsWith("/swagger-ui");
63+
boolean isOpenApiPath = uri.endsWith(PATH_OPENAPI_JSON) || uri.endsWith(PATH_OPENAPI_YAML) || uri.endsWith(PATH_SWAGGER_UI);
6064
if (isOpenApiPath) {
6165
filterChain.doFilter(request, response);
6266
return;

modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/security/webservices/JWTAuthenticationFilter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
import org.owasp.esapi.Validator;
4040

4141
public class JWTAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
42-
42+
43+
private static final String PATH_OPENAPI_JSON = "/openapi.json";
44+
private static final String PATH_OPENAPI_YAML = "/openapi.yaml";
45+
private static final String PATH_SWAGGER_UI = "/swagger-ui";
46+
4347
@Autowired
4448
private WSSecUtils wssecutils;
4549

@@ -56,7 +60,7 @@ public void setAuthenticationManager(AuthenticationManager authenticationManager
5660
@Override
5761
protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) {
5862
String uri = request.getRequestURI();
59-
if (uri.endsWith("/openapi.json") || uri.endsWith("/openapi.yaml") || uri.endsWith("/swagger-ui")) {
63+
if (uri.endsWith(PATH_OPENAPI_JSON) || uri.endsWith(PATH_OPENAPI_YAML) || uri.endsWith(PATH_SWAGGER_UI)) {
6064
return false; // OpenAPI documentation endpoints are public
6165
}
6266
return true;

modules/samples/userguide/src/userguide/springbootdemo/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4343
<java.version>17</java.version>
4444
<spring-boot.version>3.4.3</spring-boot.version>
45+
<axis2.version>2.0.1-SNAPSHOT</axis2.version>
4546
</properties>
4647

4748
<dependencies>
@@ -372,8 +373,8 @@
372373
</copy>
373374
<!-- Create openapi module archive for WEB-INF/modules -->
374375
<mkdir dir="${project.build.directory}/deploy/axis2-json-api.war/WEB-INF/modules"/>
375-
<copy file="${settings.localRepository}/org/apache/axis2/axis2-openapi/2.0.1-SNAPSHOT/axis2-openapi-2.0.1-SNAPSHOT.jar"
376-
tofile="${project.build.directory}/deploy/axis2-json-api.war/WEB-INF/modules/openapi-2.0.1-SNAPSHOT.mar"/>
376+
<copy file="${settings.localRepository}/org/apache/axis2/axis2-openapi/${axis2.version}/axis2-openapi-${axis2.version}.jar"
377+
tofile="${project.build.directory}/deploy/axis2-json-api.war/WEB-INF/modules/openapi-${axis2.version}.mar"/>
377378
<unzip src="${project.build.directory}/axis2-json-api-0.0.1-SNAPSHOT.war" dest="${project.build.directory}/exploded"/>
378379
<jar jarfile="${project.build.directory}/exploded/WEB-INF/services/Login.aar">
379380
<metainf file="resources-axis2/login_resources/services.xml"/>
@@ -391,8 +392,8 @@
391392
</copy>
392393
<!-- Create openapi module archive for exploded WEB-INF/modules -->
393394
<mkdir dir="${project.build.directory}/exploded/WEB-INF/modules"/>
394-
<copy file="${settings.localRepository}/org/apache/axis2/axis2-openapi/2.0.1-SNAPSHOT/axis2-openapi-2.0.1-SNAPSHOT.jar"
395-
tofile="${project.build.directory}/exploded/WEB-INF/modules/openapi-2.0.1-SNAPSHOT.mar"/>
395+
<copy file="${settings.localRepository}/org/apache/axis2/axis2-openapi/${axis2.version}/axis2-openapi-${axis2.version}.jar"
396+
tofile="${project.build.directory}/exploded/WEB-INF/modules/openapi-${axis2.version}.mar"/>
396397
</target>
397398
</configuration>
398399
<goals>

modules/samples/userguide/src/userguide/springbootdemo/src/main/java/userguide/springboot/configuration/OpenApiController.java

Lines changed: 0 additions & 99 deletions
This file was deleted.

modules/samples/userguide/src/userguide/springbootdemo/src/main/java/userguide/springboot/security/webservices/HTTPPostOnlyRejectionFilter.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@
3838
import java.util.UUID;
3939

4040
public class HTTPPostOnlyRejectionFilter extends OncePerRequestFilter {
41-
41+
42+
private static final String PATH_OPENAPI_JSON = "/openapi.json";
43+
private static final String PATH_OPENAPI_YAML = "/openapi.yaml";
44+
private static final String PATH_SWAGGER_UI = "/swagger-ui";
45+
4246
private static Log logger = LogFactory.getLog(HTTPPostOnlyRejectionFilter.class);
43-
47+
4448
private final RedirectStrategy redirectStrategy = new NoRedirectStrategy();
4549

4650
public HTTPPostOnlyRejectionFilter() {
@@ -52,11 +56,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
5256

5357
String uuid = UUID.randomUUID().toString();
5458
String logPrefix = "HTTPPostOnlyRejectionFilter.doFilterInternal , uuid: " + uuid + " , ";
55-
59+
5660
logger.trace(logPrefix + "starting ... ");
57-
61+
5862
String uri = request.getRequestURI();
59-
boolean isOpenApiPath = uri.endsWith("/openapi.json") || uri.endsWith("/openapi.yaml") || uri.endsWith("/swagger-ui");
63+
boolean isOpenApiPath = uri.endsWith(PATH_OPENAPI_JSON) || uri.endsWith(PATH_OPENAPI_YAML) || uri.endsWith(PATH_SWAGGER_UI);
6064
if (isOpenApiPath) {
6165
filterChain.doFilter(request, response);
6266
return;

modules/samples/userguide/src/userguide/springbootdemo/src/main/java/userguide/springboot/security/webservices/JWTAuthenticationFilter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
import org.owasp.esapi.Validator;
4040

4141
public class JWTAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
42-
42+
43+
private static final String PATH_OPENAPI_JSON = "/openapi.json";
44+
private static final String PATH_OPENAPI_YAML = "/openapi.yaml";
45+
private static final String PATH_SWAGGER_UI = "/swagger-ui";
46+
4347
@Autowired
4448
private WSSecUtils wssecutils;
4549

@@ -56,7 +60,7 @@ public void setAuthenticationManager(AuthenticationManager authenticationManager
5660
@Override
5761
protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) {
5862
String uri = request.getRequestURI();
59-
if (uri.endsWith("/openapi.json") || uri.endsWith("/openapi.yaml") || uri.endsWith("/swagger-ui")) {
63+
if (uri.endsWith(PATH_OPENAPI_JSON) || uri.endsWith(PATH_OPENAPI_YAML) || uri.endsWith(PATH_SWAGGER_UI)) {
6064
return false; // OpenAPI documentation endpoints are public
6165
}
6266
return true;

0 commit comments

Comments
 (0)