You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by bobhoskinsbrother <ho...@hotmail.com> on 2010/11/05 00:53:45 UTC
Database loaded urls section
Hi,
I'm currently loading the urls section from the "config" parameters for
org.apache.shiro.web.servlet.IniShiroFilter in my web.xml.
I'd like to be able to load these from the database, as I have the ability
to make dynamic content and routes in my system. (i.e. I can dynamically
make and intercept /My/Url/1345/index.xhtml in the app)
Is there an easy way of doing this, or do I need to write a custom Filter?
Ben
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Database-loaded-urls-section-tp5707379p5707379.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Database loaded urls section
Posted by bobhoskinsbrother <ho...@hotmail.com>.
Hi Les,
Thanks a lot for your *very* prompt response :-)
I'm currently holding off applying the IoC pattern, as I've previously seen
it applied with varying results; its the 'javascript' of the java world -
powerful, flexible, and mostly badly used :-)
In fact I've went to shiro in order to simplify and remove spring (and its
security module). Guice is more appealing (as I also liked pico in the early
days of IoC) I'm holding off until I really, really need to.
So, I want to ensure a fairly easy upgrade path for shiro, so will try to
keep my intervention to a minimum
In short I'm going to write either:
An adaptation of the classes as suggested below (basically wrap, lookup and
delegate to the DefaultFilterChainManager and IniShiroFilter),
or
Decorate the Ini class at instantiation in the IniShiroFilter to allow
loading from other sources (which is pretty much done with the configure()
method. Hmm, this maybe less clean semantically, but it'll get me there
quicker...
Give me a shout if you want any of the code (it might be kinda throw away,
as I'm not using a JDBC database)
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Database-loaded-urls-section-tp5707379p5708497.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Database loaded urls section
Posted by Les Hazlewood <lh...@apache.org>.
Hi Ben,
The ShiroFilter uses a FilterChainResolver to resolve the FilterChain
to execute based on a given request. This allows FilterChains to be
resolved dynamically at runtime. By default, they are resolved based
on static definitions in INI, but they could very easily be resolved
dynamically.
The default implementation of the FilterChainResolver is a
PathMatchingFilterChainResolver. It looks at the URL path on the
incoming request and then calls into a FilterChainManager to get a
corresponding FilterChain for the matched path.
The DefaultFilterChainManager implementation uses an internal
in-memory Map to manage the path-to-chain configuration. When using
INI config, the map is populated based on the [urls] INI section.
I think it'd be a relatively easy exercise to implement the
FilterChainManager interface to talk to a datasource instead of an
in-memory map. You can set your implementation as a property on the
PathMatchingFilterChainResolver instance, and you should be good to
go.
If you're using a DI/IoC framework like Spring or Guice this should be
really simple. If you're not, you might have to subclass the
IniShiroFilter (or AbstractShiroFilter) to set up the
FilterChainResolver and its nested FilterChainManager instance
directly. If you have to do that, the IniShiroFilter source code will
give you some good ideas:
http://svn.apache.org/repos/asf/shiro/trunk/web/src/main/java/org/apache/shiro/web/servlet/IniShiroFilter.java
HTH!
--
Les Hazlewood
Founder, Katasoft, Inc.
Application Security Products & Professional Apache Shiro Support and Training:
http://www.katasoft.com