You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Ali Shahbour <sh...@gmail.com> on 2013/03/25 11:58:42 UTC

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.SESSIO
N);

            

            bind(IndexViewModel.class);

            

            MyShiroWebModule.guiceFilterModule();

     }

}






Re: Dynamic Web Application with Shiro and Guice

Posted by Milan Baran <mi...@gmail.com>.
Hello,

could you share your problem via GitHub, BitBucket or something similar?
I will try to help you then.

=mb=



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Dynamic-Web-Application-with-Shiro-and-Guice-tp7578524p7578554.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Dynamic Web Application with Shiro and Guice

Posted by Ali Shahbour <sh...@gmail.com>.
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 <sh...@gmail.com>
Date:  Monday, March 25, 2013 12:58 PM
To:  "user@shiro.apache.org" <us...@shiro.apache.org>
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();
> 
>      }
> 
> }
> 
> 
> 
> 
> 



Re: Dynamic Web Application with Shiro and Guice

Posted by Ali Shahbour <sh...@gmail.com>.
Hello Again

It is fixed by implementing either

MyShiroWebModule.guiceFilterModule().configure(binder());



Or



MyShiroWebModule.bindGuiceFilter(binder());



I am doing so on my ServletModule but I am not sure this is the correct
place .



Best Regards

Shahbour


From:  Ali Shahbour <sh...@gmail.com>
Date:  Monday, March 25, 2013 12:58 PM
To:  "user@shiro.apache.org" <us...@shiro.apache.org>
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();
> 
>      }
> 
> }
> 
> 
> 
> 
>