Quantcast

bug report

classic Classic list List threaded Threaded
5 messages Options
jia
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug report

jia
  Hello, I'm a java web developer, and I encountered some problem about shiro. In myproject I integrated shiro 1.3.2 with spring 4.3.0.Release. On the first it worked well, but recently it broked down. The urls I configured in the ShiroFilterFactoryBean didn't behaved as they were expected to. I set some urls to work without authentication, that is to say "anon", but when I visited the url, the application would redirect to the unauthenticated url. On the beginning I had no idea about it, but when I printed the shiroFilter.getFilterChainDefinitionMap(), I found the problem.  The urls' order was not by what I set  them, because I used a HashMap. So the "/**" url was on the front of some url which I set as "anon", and then the problem come. After I changed the HashMap to LinkedHaskMap, which keeps its items' order, the problem is solved. So is this a bug?
  Here is my shiro configuration. I've modified the variable definetionsMap's type to LinkedHashMap.
@Bean
public ShiroFilterFactoryBean shiroFilter(){
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();

Map<String, Filter> map = new HashMap<>();
map.put("addPrincipal", addPrincipalToSessionFilter());
shiroFilter.setFilters(map);

Map<String, String> definitionsMap = new LinkedHashMap<>();
definitionsMap.put("/", "anon");
definitionsMap.put("/index.jsp", "anon");
definitionsMap.put("/backstage/**", "anon");
definitionsMap.put("/pay/notify", "anon");
definitionsMap.put("/pay/testRabbit", "anon");
definitionsMap.put("/site/anon", "anon");
definitionsMap.put("/unauthenticated", "anon");
definitionsMap.put("/login", "anon");
definitionsMap.put("/verification", "anon");
definitionsMap.put("/forgetPassword", "anon");
definitionsMap.put("/signup", "anon");
definitionsMap.put("/admin/**", "authc, roles[admin]");
definitionsMap.put("/pay/alipay", "authc");
definitionsMap.put("/**", "addPrincipal, user");
shiroFilter.setFilterChainDefinitionMap(definitionsMap);

System.out.println(shiroFilter.getFilterChainDefinitionMap());

shiroFilter.setLoginUrl("/unauthenticated");
shiroFilter.setUnauthorizedUrl("/unauthorized");
shiroFilter.setSecurityManager(securityManager());

logger.info("Shiro Filters: " + shiroFilter.getFilters());
return shiroFilter;
}
  If you are interested, you can visit my project on github:)
  https://github.com/Q-SJ/baobiaoshiro
  Sincerely. Hope for your reply.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bug report

Brian Demers
Not a bug, you should be using a LinkedHashMap (or other map that will preserve order).

That said, we could print a log message if we detect something other then a LinkedHashMap.  The downside though, I'm sure there are other map implementations that would work here too.

Thoughts?

On Wed, Jan 18, 2017 at 3:08 AM, 千年&yi叹 <[hidden email]> wrote:
  Hello, I'm a java web developer, and I encountered some problem about shiro. In myproject I integrated shiro 1.3.2 with spring 4.3.0.Release. On the first it worked well, but recently it broked down. The urls I configured in the ShiroFilterFactoryBean didn't behaved as they were expected to. I set some urls to work without authentication, that is to say "anon", but when I visited the url, the application would redirect to the unauthenticated url. On the beginning I had no idea about it, but when I printed the shiroFilter.getFilterChainDefinitionMap(), I found the problem.  The urls' order was not by what I set  them, because I used a HashMap. So the "/**" url was on the front of some url which I set as "anon", and then the problem come. After I changed the HashMap to LinkedHaskMap, which keeps its items' order, the problem is solved. So is this a bug?
  Here is my shiro configuration. I've modified the variable definetionsMap's type to LinkedHashMap.
@Bean
public ShiroFilterFactoryBean shiroFilter(){
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();

Map<String, Filter> map = new HashMap<>();
map.put("addPrincipal", addPrincipalToSessionFilter());
shiroFilter.setFilters(map);

Map<String, String> definitionsMap = new LinkedHashMap<>();
definitionsMap.put("/", "anon");
definitionsMap.put("/index.jsp", "anon");
definitionsMap.put("/backstage/**", "anon");
definitionsMap.put("/pay/notify", "anon");
definitionsMap.put("/pay/testRabbit", "anon");
definitionsMap.put("/site/anon", "anon");
definitionsMap.put("/unauthenticated", "anon");
definitionsMap.put("/login", "anon");
definitionsMap.put("/verification", "anon");
definitionsMap.put("/forgetPassword", "anon");
definitionsMap.put("/signup", "anon");
definitionsMap.put("/admin/**", "authc, roles[admin]");
definitionsMap.put("/pay/alipay", "authc");
definitionsMap.put("/**", "addPrincipal, user");
shiroFilter.setFilterChainDefinitionMap(definitionsMap);

System.out.println(shiroFilter.getFilterChainDefinitionMap());

shiroFilter.setLoginUrl("/unauthenticated");
shiroFilter.setUnauthorizedUrl("/unauthorized");
shiroFilter.setSecurityManager(securityManager());

logger.info("Shiro Filters: " + shiroFilter.getFilters());
return shiroFilter;
}
  If you are interested, you can visit my project on github:)
  Sincerely. Hope for your reply.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bug report

scSynergy
One other possibility, though far from perfect, is to have shiroFilter.setFilterChainDefinitionMap(definitionsMap) only accept LinkedHashMap or TreeMap as parameters instead of accepting just any Map. I think those are the only Map implementations in standard Java SE which retain order.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: bug report

Richard Wheeldon
TreeMap sorts according to the natural order of the elements (or using a comparator). It doesn't preserve order. i.e. If you put Alice, Charlie and Bob into a LinkedHashMap in that order you get Alice, Charlie and Bob out. If you put them into a TreeMap you get Alice, Bob, Charlie

-----Original Message-----
From: scSynergy [mailto:[hidden email]]
Sent: Thursday, January 19, 2017 9:40 AM
To: [hidden email]
Subject: Re: bug report

One other possibility, though far from perfect, is to have
shiroFilter.setFilterChainDefinitionMap(definitionsMap) only accept LinkedHashMap or TreeMap as parameters instead of accepting just any Map. I think those are the only Map implementations in standard Java SE which retain order.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/bug-report-tp7581461p7581464.html
Sent from the Shiro User mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bug report

Brian Demers
We cannot change the existing method signature. We could add a new one and deprecate the old, log a warning if a non-LinkedHashMap is used, or create a different mechanism (non-map) approach to setting the definitions.

For Shiro 1.4 (still RC, so can be changed), I added a ShiroFilterChainDefinition interface, and the default impl.

NOTE: the intent behind this is to make it easier to define the required beans, see the example here 

Thoughts ?




On Thu, Jan 19, 2017 at 6:52 AM, Richard Wheeldon <[hidden email]> wrote:
TreeMap sorts according to the natural order of the elements (or using a comparator). It doesn't preserve order. i.e. If you put Alice, Charlie and Bob into a LinkedHashMap in that order you get Alice, Charlie and Bob out. If you put them into a TreeMap you get Alice, Bob, Charlie

-----Original Message-----
From: scSynergy [mailto:[hidden email]]
Sent: Thursday, January 19, 2017 9:40 AM
To: [hidden email]
Subject: Re: bug report

One other possibility, though far from perfect, is to have
shiroFilter.setFilterChainDefinitionMap(definitionsMap) only accept LinkedHashMap or TreeMap as parameters instead of accepting just any Map. I think those are the only Map implementations in standard Java SE which retain order.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/bug-report-tp7581461p7581464.html
Sent from the Shiro User mailing list archive at Nabble.com.

Loading...