Hello
I was able to fix the No SecurityManager error by doing
bind(org.apache.shiro.web.servlet.ShiroFilter.class).asEagerSingleton();
filter("/*").through(org.apache.shiro.web.servlet.ShiroFilter.class);
but I think this is wrong as MyShiroWebModule.guiceFilterModule() should
take care of binding the filters , or I am wrong ?
Best Regards
Shahbour
From: Ali Shahbour <[email protected]>
Date: Monday, March 25, 2013 12:58 PM
To: "[email protected]" <[email protected]>
Subject: Dynamic Web Application with Shiro and Guice
> Hello
>
> I am trying to have ZK framework work with shiro and guice , but I am still
> stuck , I am getting No SecurityManager accessible to the calling code, when
> trying to put annotation @RequiresAuthentication On any function
>
> One point is still missing for me also , where is the correct point to call
> guiceFilterModule()
>
> Below are major classes I am using
>
> @WebListener
>
> public class MyGuiceConfig extends GuiceServletContextListener {
>
> private ServletContext servletContext;
>
>
>
> @Override
>
> public void contextInitialized(ServletContextEvent servletContextEvent) {
>
> servletContext = servletContextEvent.getServletContext();
>
> super.contextInitialized(servletContextEvent);
>
> }
>
>
>
> @Override
>
> protected Injector getInjector() {
>
> return Guice.createInjector(new MyShiroWebModule(servletContext),new
> ShiroAopModule(),new MyServletModule());
>
> }
>
> }
>
>
>
> And MyShiroWebModule
>
>
>
> public class MyShiroWebModule extends ShiroWebModule {
>
>
>
> public MyShiroWebModule(ServletContext servletContext) {
>
> super(servletContext);
>
> // TODO Auto-generated constructor stub
>
> }
>
>
>
> @Override
>
> protected void configureShiroWeb() {
>
> try {
>
>
> bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
>
> } catch (NoSuchMethodException e) {
>
> addError(e);
>
> }
>
>
>
> addFilterChain("/public/**", ANON);
>
> addFilterChain("/stuff/allowed/**", AUTHC_BASIC, config(PERMS,
> "yes"));
>
> addFilterChain("/stuff/forbidden/**", AUTHC_BASIC, config(PERMS,
> "no"));
>
> addFilterChain("/**", AUTHC_BASIC);
>
>
>
> //MyShiroWebModule.guiceFilterModule();
>
> //SecurityUtils.setSecurityManager(securityManager)
>
> }
>
> @Provides
>
> Ini loadShiroIni() {
>
> return Ini.fromResourcePath("classpath:shiro.ini");
>
> }
>
>
>
> }
>
>
>
> MyServletModule
>
>
>
>
>
> public class MyServletModule extends ServletModule {
>
>
>
> @Override
>
> protected void configureServlets() {
>
> super.configureServlets();
>
> bind(DHtmlLayoutServlet.class).asEagerSingleton();
>
> bind(DHtmlUpdateServlet.class).in(Scopes.SINGLETON);
>
> Map<String,String> layoutServletParameters = new HashMap<String, String>();
>
> layoutServletParameters.put("update-uri", "/zkau");
>
> serve("*.zul",
> "*.zhtml").with(DHtmlLayoutServlet.class,layoutServletParameters);
>
> serve("/zkau/*").with(DHtmlUpdateServlet.class);
>
> serve("*.html").with(MyServlet.class);
>
>
>
>
>
bind(PojoClass.class).toProvider(PojoProvider.class).in(ServletScopes.SESSION)>
;
>
>
>
> bind(IndexViewModel.class);
>
>
>
> MyShiroWebModule.guiceFilterModule();
>
> }
>
> }
>
>
>
>
>