From 728d695ce14174b0e4cdb116ba3d3f9260fae2cb Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Wed, 17 Jan 2024 19:26:03 +1100 Subject: [PATCH] WW-5352 Add debug logging for parameter rejections --- .../parameter/ParametersInterceptor.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java index c91aea87a..9c7013b7c 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java @@ -399,8 +399,11 @@ public class ParametersInterceptor extends MethodFilterInterceptor { if (relevantMethod == null) { return false; } - StrutsParameter annotation = getParameterAnnotation(relevantMethod); - if (annotation == null || annotation.depth() < paramDepth) { + if (getPermittedInjectionDepth(relevantMethod) < paramDepth) { + LOG.debug( + "Parameter injection for method [{}] on action [{}] rejected. Ensure it is annotated with @StrutsParameter with an appropriate 'depth'.", + relevantMethod.getName(), + relevantMethod.getDeclaringClass().getName()); return false; } if (paramDepth >= 1) { @@ -450,8 +453,11 @@ public class ParametersInterceptor extends MethodFilterInterceptor { if (!Modifier.isPublic(field.getModifiers())) { return false; } - StrutsParameter annotation = getParameterAnnotation(field); - if (annotation == null || annotation.depth() < paramDepth) { + if (getPermittedInjectionDepth(field) < paramDepth) { + LOG.debug( + "Parameter injection for field [{}] on action [{}] rejected. Ensure it is annotated with @StrutsParameter with an appropriate 'depth'.", + fieldName, + action.getClass().getName()); return false; } if (paramDepth >= 1) { @@ -467,6 +473,17 @@ public class ParametersInterceptor extends MethodFilterInterceptor { allowlistParameterizedTypeArg(field.getGenericType()); } + /** + * @return permitted injection depth where -1 indicates not permitted + */ + protected int getPermittedInjectionDepth(AnnotatedElement element) { + StrutsParameter annotation = getParameterAnnotation(element); + if (annotation == null) { + return -1; + } + return annotation.depth(); + } + /** * Annotation retrieval logic. Can be overridden to support extending annotations or some other form of annotation * inheritance.