EnvironmentLoadListener initialzation from EJB

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

EnvironmentLoadListener initialzation from EJB

haroldpudwell
This post has NOT been accepted by the mailing list yet.
I would like to load Shiro in a JEE server using a @Startup EJB. Is this possible? I do not want to use the @WebListener
public class MyClass extends EnvironmentLoaderListener {
}

instantiation as my web tier runs in a different JVM.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: EnvironmentLoadListener initialzation from EJB

scSynergy
This is what we use in a bean annotated with @Startup @Singleton:

@PostConstruct
    public void initializeShiro() {
            String iniFile = retrieveFromDatabase(); // real implementation omitted for clarity
            Ini ini = new Ini();
            ini.load(iniFile);
            String realms = ini.getSectionProperty("main", "securityManager.realms");
            if (realms != null && !realms.contains(CamelRealm.CAMELREALM)) {
                ini.setSectionProperty("main", "securityManager.realms", realms + ", $" + CamelRealm.CAMELREALM);
            }
            BeanManager beanManager = CDI.current().getBeanManager();
            IniSecurityManagerFactory factory = new CdiIniSecurityManagerFactory(ini, beanManager);
            org.apache.shiro.mgt.SecurityManager securityManager = (org.apache.shiro.mgt.SecurityManager) factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
    }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: EnvironmentLoadListener initialzation from EJB

haroldpudwell
This post has NOT been accepted by the mailing list yet.
Thanks! I completely eliminated using ini files and web.xml entries. I was able to achieve it with:

@Startup
@Singleton
public class InitializeSecurityManager {

        @Inject
        WebSecurityManager securityManager;

        public InitializeSecurityManager() {

        }

        @PostConstruct
        public void initializeShiro() {
                SecurityUtils.setSecurityManager(securityManager);
        }


Loading...