shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r1481406 - in /shiro/branches/1.2.x/web/src: main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
Date Sat, 11 May 2013 20:36:21 GMT
Author: lhazlewood
Date: Sat May 11 20:36:20 2013
New Revision: 1481406

URL: http://svn.apache.org/r1481406
Log:
SHIRO-429: fixed bug and added test cases for regression

Modified:
    shiro/branches/1.2.x/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
    shiro/branches/1.2.x/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy

Modified: shiro/branches/1.2.x/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java?rev=1481406&r1=1481405&r2=1481406&view=diff
==============================================================================
--- shiro/branches/1.2.x/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
(original)
+++ shiro/branches/1.2.x/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
Sat May 11 20:36:20 2013
@@ -209,16 +209,26 @@ public class DefaultFilterChainManager i
                 config = StringUtils.clean(pair[1]);
                 //if there was an open bracket, it assumed there is a closing bracket, so
strip it too:
                 config = config.substring(0, config.length() - 1);
+                config = StringUtils.clean(config);
 
-                //backwards compatibility prior to implmenting SHIRO-205:
+                //backwards compatibility prior to implementing SHIRO-205:
                 //prior to SHIRO-205 being implemented, it was common for end-users to quote
the config inside brackets
                 //if that config required commas.  We need to strip those quotes to get to
the interior quoted definition
                 //to ensure any existing quoted definitions still function for end users:
-                if (config.startsWith("\"") && config.endsWith("\"")) {
-                    config = config.substring(1, config.length() - 1);
+                if (config != null && config.startsWith("\"") && config.endsWith("\""))
{
+                    String stripped = config.substring(1, config.length() - 1);
+                    stripped = StringUtils.clean(stripped);
+
+                    //if the stripped value does not have any internal quotes, we can assume
that the entire config was
+                    //quoted and we can use the stripped value.
+                    if (stripped != null && stripped.indexOf('"') == -1) {
+                        config = stripped;
+                    }
+                    //else:
+                    //the remaining config does have internal quotes, so we need to assume
that each comma delimited
+                    //pair might be quoted, in which case we need the leading and trailing
quotes that we stripped
+                    //So we ignore the stripped value.
                 }
-                
-                config = StringUtils.clean(config);
             }
             
             return new String[]{name, config};

Modified: shiro/branches/1.2.x/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy?rev=1481406&r1=1481405&r2=1481406&view=diff
==============================================================================
--- shiro/branches/1.2.x/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
(original)
+++ shiro/branches/1.2.x/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
Sat May 11 20:36:20 2013
@@ -85,6 +85,19 @@ class DefaultFilterChainManagerTest exte
         assertEquals "roles", pair[0]
         assertEquals "guest, admin", pair[1]
     }
+
+    //SHIRO-205 - asserts backwards compatibility before SHIRO-205 was implemented:
+    //@since 1.2.2
+    void testToNameConfigPairWithIndividualNestedQuotesInBrackets() {
+        def token = 'roles["guest", "admin"]'
+
+        String[] pair = manager.toNameConfigPair(token);
+
+        assertNotNull pair
+        assertEquals 2, pair.length
+        assertEquals "roles", pair[0]
+        assertEquals '"guest", "admin"', pair[1]
+    }
     
     //SHIRO-205
     void testFilterChainConfigWithNestedCommas() {
@@ -181,6 +194,38 @@ class DefaultFilterChainManagerTest exte
         assertEquals(DefaultFilter.perms.getFilterClass(), filter.getClass());
     }
 
+    /**
+     * Helps assert <a href="https://issues.apache.org/jira/browse/SHIRO-429">SHIRO-429</a>
+     * @since 1.2.2
+     */
+    void testCreateChainWithQuotedInstanceConfig() {
+
+        manager.createChain("test", 'authc, perms["perm1", "perm2"]');
+
+        assertTrue(manager.hasChains());
+
+        Set<String> chainNames = manager.getChainNames();
+        assertNotNull(chainNames);
+        assertEquals(1, chainNames.size());
+        assertTrue(chainNames.contains("test"));
+
+        Map<String, NamedFilterList> chains = manager.getFilterChains();
+        assertEquals(1, chains.size());
+        assertTrue(chains.containsKey("test"));
+        manager.setFilterChains(chains);
+
+        NamedFilterList chain = manager.getChain("test");
+        assertNotNull(chain);
+
+        Filter filter = chain.get(0);
+        assertNotNull(filter);
+        assertEquals(DefaultFilter.authc.getFilterClass(), filter.getClass());
+
+        filter = chain.get(1);
+        assertNotNull(filter);
+        assertEquals(DefaultFilter.perms.getFilterClass(), filter.getClass());
+    }
+
     void testBeanMethods() {
         Map<String, Filter> filters = manager.getFilters();
         assertEquals(filters.size(), DefaultFilter.values().length);



Mime
View raw message