The easiest way to do this is to subclass
org.apache.shiro.web.env.IniWebEnvironment.

Then, whenever you want (but before the EnvironmentLoaderListener
calls environment.init()), just call:

this.setIni(myConstructedIni);

You can do this in your subclass constructor for example.  Or you can
override the init() method:

@Override
public void init() {
    Ini custom = createMyCustomIni();
    this.setIni(custom);
    super.init();
}

The IniWebEnvironment implementation's init() method (called when the
webapp's ServletContext is available) will use the custom Ini instance
to build the Shiro object graph.  You can see more here:
http://shiro.apache.org/static/current/xref/org/apache/shiro/web/env/IniWebEnvironment.html#62

HTH!

Cheers,

Les

On Tue, Oct 16, 2012 at 3:40 PM, Diptanu Choudhury <[email protected]> wrote:
>
> Hi Guys,
>
> I am trying to shiro in a web application. And i followed the instructions on 
> the docs and got it working. However i dont want to use the shiro.ini 
> anymore, I want to create a Ini class in my code and use it instead. I am 
> doing the following
>
>
> <listener>
>     
> <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
> </listener
>
> <context-param>
>     <param-name>shiroEnvironmentClass</param-name>
>     <param-value>com.foo.bar.shiro.MyWebEnvironment</param-value>
> </context-param>
>
>
>
> And the class com.foo.bar.shiro.MyWebEnvironment looks like this
>
> class MyWebEnvironment extends DefaultWebEnvironment implements 
> Initializable, Destroyable{
>
> public init(){
>
> Ini ini = new Ini()
>
> WebSecurityManager securityManager = WebIniSecurityManagerFactory(ini);
>
> setObject("securityManager", securityManager);
>
> }
>
> }
>
> From the logs I can see that Shiro gets loaded, but Shiro doesn't pick up 
> anything from the configuration. Please feel free to point me to the right 
> section of the docs and sorry for sending the same email twice, pressed the 
> Send button accidentally earlier :(
>
> --
> Thanks,
> Diptanu Choudhury
>
>

Reply via email to