shiro

shiro filters with duplicate patterns which one used


what happens when you DUPLICATE shiro filters with the same exact pattern? I know the "first match wins" policy applies to two similar patterns,

addFilterChain("/secure/**", ROLE_1); // this one is used

addFilterChain("/secure/foo", ROLE_2);

but what if the patterns are ACTUALLY identical? which one will be used here, #1 or #2?


addFilterChain("/secure/bar", ROLE_1);

addFilterChain("/secure/bar", ROLE_2);

i expect the "first match wins" policy will still apply but i wanted to make sure.


Solution

  • #2

    The addFilterChain method adds a value to a Map, the second entry will overwrite the first

    https://github.com/apache/shiro/blob/010da2c281044e1630c662288e440c95ec87b8d7/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java#L292-L294

    This is different from the first example where you have different patterns, and the first pattern to match the request will be used.