Quantcast

Database loaded urls section

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

Database loaded urls section

bobhoskinsbrother
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Database loaded urls section

Les Hazlewood-2
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Database loaded urls section

bobhoskinsbrother
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)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Database loaded urls section

Victoria
This post has NOT been accepted by the mailing list yet.
Can please anyone share code that implements this?

thank you in advance!

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

Re: Database loaded urls section

matbarni
This post has NOT been accepted by the mailing list yet.
In reply to this post by Les Hazlewood-2
Can someone provide a working example of a JPA loaded configuration example?

I can't find anything that is configured and filtered with JPA source without the .INI file.
Loading...