From 084c257d6e2e80d51ff152e0e8e75d13d4e7af40 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Mon, 24 Oct 2022 08:27:12 +0200 Subject: [PATCH] WW-4173 Passes current ActionInvocation to allow based disabling interceptor on it --- .../java/com/opensymphony/xwork2/DefaultActionInvocation.java | 4 ++-- .../opensymphony/xwork2/interceptor/AbstractInterceptor.java | 2 +- .../java/com/opensymphony/xwork2/interceptor/Interceptor.java | 3 ++- .../java/org/apache/struts2/interceptor/CoepInterceptor.java | 4 ++-- .../java/org/apache/struts2/interceptor/CoopInterceptor.java | 4 ++-- .../apache/struts2/interceptor/FetchMetadataInterceptor.java | 2 +- .../org/apache/struts2/interceptor/csp/CspInterceptor.java | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java index 8c388d469..c1e049dfa 100644 --- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java +++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java @@ -248,11 +248,11 @@ public class DefaultActionInvocation implements ActionInvocation { if (interceptor instanceof WithLazyParams) { interceptor = lazyParamInjector.injectParams(interceptor, interceptorMapping.getParams(), invocationContext); } - if (interceptor.isDisabled()) { + if (interceptor.isDisabled(this)) { LOG.debug("Interceptor: {} is disabled, skipping to next", interceptor.getClass().getSimpleName()); resultCode = this.invoke(); } else { - resultCode = interceptor.intercept(DefaultActionInvocation.this); + resultCode = interceptor.intercept(this); } } else { resultCode = invokeActionOnly(); diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java index 2895bc0f0..efa009052 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java @@ -49,7 +49,7 @@ public abstract class AbstractInterceptor implements Interceptor { } @Override - public boolean isDisabled() { + public boolean isDisabled(ActionInvocation invocation) { return this.disabled; } } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java index c60c2f416..3488314d2 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java @@ -222,8 +222,9 @@ public interface Interceptor extends Serializable { /** * Allows to disable processing a given interceptor * + * @param invocation current {@link ActionInvocation} to determine if the interceptor should be executed * @return true if the given interceptor should be skipped * @since 6.1.0 */ - boolean isDisabled(); + boolean isDisabled(ActionInvocation invocation); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/CoepInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/CoepInterceptor.java index c887877dc..6d550c19f 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/CoepInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/CoepInterceptor.java @@ -51,7 +51,7 @@ public class CoepInterceptor extends AbstractInterceptor implements PreResultLis @Override public String intercept(ActionInvocation invocation) throws Exception { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { LOG.trace("COEP interceptor has been disabled"); } else { invocation.addPreResultListener(this); @@ -61,7 +61,7 @@ public class CoepInterceptor extends AbstractInterceptor implements PreResultLis @Override public void beforeResult(ActionInvocation invocation, String resultCode) { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { return; } diff --git a/core/src/main/java/org/apache/struts2/interceptor/CoopInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/CoopInterceptor.java index 5590ca98f..9827ceb13 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/CoopInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/CoopInterceptor.java @@ -53,7 +53,7 @@ public class CoopInterceptor extends AbstractInterceptor implements PreResultLis @Override public String intercept(ActionInvocation invocation) throws Exception { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { LOG.trace("COOP interceptor has been disabled"); } else { invocation.addPreResultListener(this); @@ -63,7 +63,7 @@ public class CoopInterceptor extends AbstractInterceptor implements PreResultLis @Override public void beforeResult(ActionInvocation invocation, String resultCode) { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { return; } HttpServletRequest request = invocation.getInvocationContext().getServletRequest(); diff --git a/core/src/main/java/org/apache/struts2/interceptor/FetchMetadataInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/FetchMetadataInterceptor.java index 0122d718b..9a3583607 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/FetchMetadataInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/FetchMetadataInterceptor.java @@ -62,7 +62,7 @@ public class FetchMetadataInterceptor extends AbstractInterceptor { @Override public String intercept(ActionInvocation invocation) throws Exception { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { LOG.trace("Fetch Metadata interceptor has been disabled"); return invocation.invoke(); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java index eb3ddb4a0..38b196514 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java @@ -47,7 +47,7 @@ public final class CspInterceptor extends AbstractInterceptor implements PreResu @Override public String intercept(ActionInvocation invocation) throws Exception { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { LOG.trace("CSP interceptor has been disabled"); } else { invocation.addPreResultListener(this); @@ -56,7 +56,7 @@ public final class CspInterceptor extends AbstractInterceptor implements PreResu } public void beforeResult(ActionInvocation invocation, String resultCode) { - if (this.isDisabled()) { + if (this.isDisabled(invocation)) { return; } HttpServletRequest request = invocation.getInvocationContext().getServletRequest();