shiro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Les Hazlewood <>
Subject Re: Configuring Shiro programmatically
Date Tue, 03 Jan 2012 23:07:19 GMT
Hi Bengt,

I can't speak to how to use Blueprint as my OSGi skills are rather rusty.

With regards to configuring Shiro programmatically, this is pretty
easy - mostly everything in Shiro is configurable via getters/setters
- you can instantiate and set whatever implementations you wish.

Now, if my memory serves me correctly, Blueprint is more or less
Spring-style configuration for beans in an OSGi module, no?  If so,
wouldn't you configure Shiro beans as Spring beans similar to what is
described here: ?

Now, when it comes to custom filters, and filter chain definitions,
The ShiroFilter uses something called a FilterChainResolver at runtime
(input: request, response, servletContainerFilterChain; output: the
FilterChain to execute).  A FilterChainResolver relies internally on a
FilterChainManager to determine which chain should be executed based
on the inbound request.  At startup, the FilterChainManager reads the
filterChainDefinitions (i.e. each line in the [urls] section) and
creates a corresponding FilterChain.

In the Spring support, there is a
org.apache.shiro.spring.web.ShiroFilterFactoryBean that, based on the
filter chain definitions, will create the FilterChainManager, inject
it into a FilterChainResolver instance, and make the resolver
accessible to a new ShiroFilter instance.

You can see the ShiroFilterFactoryBean source code for how it does
this if you need to gleam ideas:

So I'm assuming in Blueprint, you need to do a few things:

1.  Configure a SecurityManager instance
2.  Configure any number of Filter instances
3.  Configure a FilterChainManager, referencing the filters in #2
4.  Configure a PathMatchingFilterChainResolver that uses the
FilterChainManager in #3
5.  Configure a ShiroFilter instance that uses the FilterChainResolver in #4.
6.  Make sure that ShiroFilter instance filters all web requests
served by your OSGi-based web application.  Usually this filter is at
the very front of (or very near the front of) all other filters in the
web application.

Feel free to ask any other questions - I'm happy to help.



On Fri, Dec 30, 2011 at 9:02 AM, Bengt Rodehav <> wrote:
> I'm using Shiro 1.1.0 in an OSGi environment (Apache Karaf on Apache Felix).
> I posted a question recently about configuring Shiro using Blueprint in an
> OSGi environment. I got no response to that question. I then thought that if
> I could first figure out how to configure Shiro programmatically then maybe
> I can figure out the rest myself.
> At first it seemed pretty easy but then I came to my custom filters. When I
> used a shiro.ini file, I gave my custom filter a name that I could then
> refer to in the [urls] section. I can't figure out how to do this when I
> create my filter programmatically.
> Can anyone give me a hint regarding this? I appreciate any help,
> /Bengt

View raw message