Return-Path: X-Original-To: apmail-shiro-user-archive@www.apache.org Delivered-To: apmail-shiro-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 12641975D for ; Tue, 3 Jan 2012 23:07:46 +0000 (UTC) Received: (qmail 28277 invoked by uid 500); 3 Jan 2012 23:07:45 -0000 Delivered-To: apmail-shiro-user-archive@shiro.apache.org Received: (qmail 28254 invoked by uid 500); 3 Jan 2012 23:07:45 -0000 Mailing-List: contact user-help@shiro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@shiro.apache.org Delivered-To: mailing list user@shiro.apache.org Received: (qmail 28246 invoked by uid 99); 3 Jan 2012 23:07:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jan 2012 23:07:45 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.216.52] (HELO mail-qw0-f52.google.com) (209.85.216.52) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jan 2012 23:07:40 +0000 Received: by qadc11 with SMTP id c11so11378403qad.11 for ; Tue, 03 Jan 2012 15:07:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.224.31.202 with SMTP id z10mr63417892qac.96.1325632039576; Tue, 03 Jan 2012 15:07:19 -0800 (PST) Sender: les.hazlewood@anjinllc.com Received: by 10.229.32.205 with HTTP; Tue, 3 Jan 2012 15:07:19 -0800 (PST) In-Reply-To: References: Date: Tue, 3 Jan 2012 18:07:19 -0500 X-Google-Sender-Auth: -qZ6lmvJQQA5iqTbv21EroHG42A Message-ID: Subject: Re: Configuring Shiro programmatically From: Les Hazlewood To: user@shiro.apache.org Content-Type: text/plain; charset=UTF-8 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: http://shiro.apache.org/spring.html ? 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: http://svn.apache.org/repos/asf/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/web/ShiroFilterFactoryBean.java 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. Cheers, Les 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