WW-5352 Add debug logging for parameter rejections

This commit is contained in:
Kusal Kithul-Godage
2024-01-17 19:26:03 +11:00
parent 49b9c0c78c
commit 728d695ce1
@@ -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.