Uses the same logic as in ParametersInterceptor to use st of patterns
to exclude cookies which tries to access Struts internal state
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/1a668af7
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/1a668af7
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/1a668af7
Branch: refs/heads/master
Commit: 1a668af7f1ffccea4a3b46d8d8c1fe1c7331ff02
Parents: dbcdbd0
Author: Lukasz Lenart
Authored: Thu May 1 11:31:12 2014 +0200
Committer: Lukasz Lenart
Committed: Thu May 1 11:31:12 2014 +0200
--
.../struts2/interceptor/CookieInterceptor.java | 45 +++--
.../interceptor/CookieInterceptorTest.java | 53
2 files changed, 82 insertions(+), 16 deletions(-)
--
http://git-wip-us.apache.org/repos/asf/struts/blob/1a668af7/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
--
diff --git
a/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
b/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
index 3e2e81d..340b57f 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
@@ -33,6 +33,7 @@ import org.apache.struts2.ServletActionContext;
import javax.servlet.http.Cookie;
import java.util.Collections;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -175,7 +176,13 @@ public class CookieInterceptor extends AbstractInterceptor
{
// Allowed names of cookies
private Pattern acceptedPattern = Pattern.compile(ACCEPTED_PATTERN,
Pattern.CASE_INSENSITIVE);
-private Pattern excludedPattern =
Pattern.compile(ExcludedPatterns.CLASS_ACCESS_PATTERN,
Pattern.CASE_INSENSITIVE);
+private Set excludedPatterns = new HashSet();
+
+public CookieInterceptor() {
+for (String pattern : ExcludedPatterns.EXCLUDED_PATTERNS) {
+excludedPatterns.add(Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE));
+}
+}
/**
* Set the cookiesName which if matched will allow the cookie
@@ -253,13 +260,16 @@ public class CookieInterceptor extends
AbstractInterceptor {
* @return true|false
*/
protected boolean isAcceptableValue(String value) {
-boolean matches = !excludedPattern.matcher(value).matches();
-if (!matches) {
-if (LOG.isTraceEnabled()) {
-LOG.trace("Cookie value [#0] matches excludedPattern [#1]",
value, ExcludedPatterns.CLASS_ACCESS_PATTERN);
+for (Pattern excludedPattern : excludedPatterns) {
+boolean matches = !excludedPattern.matcher(value).matches();
+if (!matches) {
+if (LOG.isTraceEnabled()) {
+LOG.trace("Cookie value [#0] matches excludedPattern
[#1]", value, excludedPattern.toString());
+}
+return false;
}
}
-return matches;
+return true;
}
/**
@@ -293,23 +303,26 @@ public class CookieInterceptor extends
AbstractInterceptor {
}
/**
- * Checks if name of Cookie match {@link #excludedPattern}
+ * Checks if name of Cookie match {@link #excludedPatterns}
*
* @param name of Cookie
* @return true|false
*/
protected boolean isExcluded(String name) {
-boolean matches = excludedPattern.matcher(name).matches();
-if (matches) {
-if (LOG.isTraceEnabled()) {
-LOG.trace("Cookie [#0] matches excludedPattern [#1]", name,
ExcludedPatterns.CLASS_ACCESS_PATTERN);
-}
-} else {
-if (LOG.isTraceEnabled()) {
-LOG.trace("Cookie [#0] doesn't match excludedPattern [#1]",
name, ExcludedPatterns.CLASS_ACCESS_PATTERN);
+for (Pattern excludedPattern : excludedPatterns) {
+boolean matches = excludedPattern.matcher(name).matches();
+if (matches) {
+if (LOG.isTraceEnabled()) {
+LOG.trace("Cookie [#0] matches excludedPattern [#1]",
name, excludedPattern.toString());
+}
+return true;
+} else {
+if (LOG.isTraceEnabled()) {
+LOG.trace("Cookie [#0] doesn't match excludedPattern
[#1]", name, excludedPattern.toString());
+}
}
}
-return matches;
+return false;
}
/**
http://git-wip-us.apache.org/repos/asf/struts/blob/1a668af7/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java