You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Fernando Wermus <fe...@gmail.com> on 2010/03/16 21:42:26 UTC

webapp and shiro without spring

Hi all,
    I was trying my first step with shiro, without any luck. Despite I set
up web.xml shiro says that no SecurityManager has been set.

I decided to add these lines to my code to make SecurityManager
sessionable....

    @Override protected void onBeginRequest() {

     super.onBeginRequest();

     ThreadContext.bind(new org.apache.shiro.web.DefaultWebSecurityManager(
new MyRealm()));

    }

    @Override protected void onEndRequest() {

     super.onEndRequest();

     ThreadContext.unbindSecurityManager();

    }


Now I get a


java.lang.IllegalStateException: ServletRequest is not available! A
ServletRequest must be present in either the Subject context map, on an
existing WebSubject or via the thread context. This exception is probably
indicative of an erroneous application configuration.
at
org.apache.shiro.web.mgt.DefaultWebSubjectFactory.getServletRequest(DefaultWebSubjectFactory.java:67)
at
org.apache.shiro.web.mgt.DefaultWebSubjectFactory.getHost(DefaultWebSubjectFactory.java:103)


I suppose that the session is bind in shiroFilter, but It doesnt seem the
case

My Shiro Filter....



<!-- SHIRO FILTER -->

    <filter>

        <filter-name>ShiroFilter</filter-name>

        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class
>

        <init-param>

           <param-name>config</param-name>

           <param-value>

 [main]

 realmA = com.misPartidos.web.MyRealm

           </param-value>

        </init-param>

    </filter>


  <filter-mapping>

   <filter-name>ShiroFilter</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>



As I dont know spring I couldnt understand the example given enogh .


Thank in advance

-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus

Re: webapp and shiro without spring

Posted by Fernando Wermus <fe...@gmail.com>.
Les!
   It is solved. Despite I was aware of the order of the filters, I have
wicket attends first :(. I would like you know that Wicket-shiro integration
is not using IniShiroFilter, but ShiroFilter.

Thanks

On Tue, Mar 16, 2010 at 9:41 PM, Les Hazlewood <lh...@apache.org>wrote:

> Hi Fernando,
>
> With Ini-based web.xml configuration is now handled by the
> IniShiroFilter.  Are you using the latest trunk snapshot of Shiro?
>
> For example, this works in the Shiro sample webapp:
>
> <filter>
>        <filter-name>ShiroFilter</filter-name>
>
>  <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
>         <init-param>
>            <param-name>config</param-name>
>            <param-value>
>             # INI config here as described in
>            #
> http://incubator.apache.org/shiro/configuration.html#Configuration-INISections
>             </param-value>
>        </init-param>
>    </filter>
>
>    <filter-mapping>
>        <filter-name>ShiroFilter</filter-name>
>        <url-pattern>/*</url-pattern>
>    </filter-mapping>
>

> You definitely don't want to be creating and unbinding a new
> SecurityManager instance for every request - that would be too
> expensive.  Also, have you checked out the wicket-stuff Shiro
> integration project?  This handles the pre/post request setup for
> wicket-specific applications and should still work.  If not, let us
> know and maybe we'll have to edit the wicket-stuff project a little.
> If I remember correctly, the wicket-stuff guys were just waiting for
> Shiro 1.0 to come out to make their Maven integration a little easier.
>  Let us know if you come across issues and I'll try to jump in and
> help out if I can!
>
> Best,
>
> Les
>
> On Tue, Mar 16, 2010 at 1:42 PM, Fernando Wermus
> <fe...@gmail.com> wrote:
> > Hi all,
> >     I was trying my first step with shiro, without any luck. Despite I
> set
> > up web.xml shiro says that no SecurityManager has been set.
> > I decided to add these lines to my code to make SecurityManager
> > sessionable....
> >
> >     @Override protected void onBeginRequest() {
> >
> >      super.onBeginRequest();
> >
> >
> >
> ThreadContext.bind(new org.apache.shiro.web.DefaultWebSecurityManager(new MyRealm()));
> >
> >     }
> >
> >     @Override protected void onEndRequest() {
> >
> >      super.onEndRequest();
> >
> >      ThreadContext.unbindSecurityManager();
> >
> >     }
> >
> > Now I get a
> >
> > java.lang.IllegalStateException: ServletRequest is not available! A
> > ServletRequest must be present in either the Subject context map, on an
> > existing WebSubject or via the thread context. This exception is probably
> > indicative of an erroneous application configuration.
> > at
> >
> org.apache.shiro.web.mgt.DefaultWebSubjectFactory.getServletRequest(DefaultWebSubjectFactory.java:67)
> > at
> >
> org.apache.shiro.web.mgt.DefaultWebSubjectFactory.getHost(DefaultWebSubjectFactory.java:103)
> >
> > I suppose that the session is bind in shiroFilter, but It doesnt seem the
> > case
> > My Shiro Filter....
> >
> >
> > <!-- SHIRO FILTER -->
> >
> >     <filter>
> >
> >         <filter-name>ShiroFilter</filter-name>
> >
> >
> >   <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
> >
> >         <init-param>
> >
> >            <param-name>config</param-name>
> >
> >            <param-value>
> >
> >  [main]
> >
> >  realmA = com.misPartidos.web.MyRealm
> >
> >            </param-value>
> >
> >         </init-param>
> >
> >     </filter>
> >
> >   <filter-mapping>
> >
> >    <filter-name>ShiroFilter</filter-name>
> >
> >     <url-pattern>/*</url-pattern>
> >
> >   </filter-mapping>
> >
> > As I dont know spring I couldnt understand the example given enogh .
> >
> > Thank in advance
> >
> > --
> > Fernando Wermus.
> >
> > www.linkedin.com/in/fernandowermus
> >
>



-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus

Re: webapp and shiro without spring

Posted by Les Hazlewood <lh...@apache.org>.
Hi Fernando,

With Ini-based web.xml configuration is now handled by the
IniShiroFilter.  Are you using the latest trunk snapshot of Shiro?

For example, this works in the Shiro sample webapp:

<filter>
        <filter-name>ShiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>
            # INI config here as described in
            # http://incubator.apache.org/shiro/configuration.html#Configuration-INISections
            </param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>ShiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

You definitely don't want to be creating and unbinding a new
SecurityManager instance for every request - that would be too
expensive.  Also, have you checked out the wicket-stuff Shiro
integration project?  This handles the pre/post request setup for
wicket-specific applications and should still work.  If not, let us
know and maybe we'll have to edit the wicket-stuff project a little.
If I remember correctly, the wicket-stuff guys were just waiting for
Shiro 1.0 to come out to make their Maven integration a little easier.
 Let us know if you come across issues and I'll try to jump in and
help out if I can!

Best,

Les

On Tue, Mar 16, 2010 at 1:42 PM, Fernando Wermus
<fe...@gmail.com> wrote:
> Hi all,
>     I was trying my first step with shiro, without any luck. Despite I set
> up web.xml shiro says that no SecurityManager has been set.
> I decided to add these lines to my code to make SecurityManager
> sessionable....
>
>     @Override protected void onBeginRequest() {
>
>      super.onBeginRequest();
>
>
> ThreadContext.bind(new org.apache.shiro.web.DefaultWebSecurityManager(new MyRealm()));
>
>     }
>
>     @Override protected void onEndRequest() {
>
>      super.onEndRequest();
>
>      ThreadContext.unbindSecurityManager();
>
>     }
>
> Now I get a
>
> java.lang.IllegalStateException: ServletRequest is not available! A
> ServletRequest must be present in either the Subject context map, on an
> existing WebSubject or via the thread context. This exception is probably
> indicative of an erroneous application configuration.
> at
> org.apache.shiro.web.mgt.DefaultWebSubjectFactory.getServletRequest(DefaultWebSubjectFactory.java:67)
> at
> org.apache.shiro.web.mgt.DefaultWebSubjectFactory.getHost(DefaultWebSubjectFactory.java:103)
>
> I suppose that the session is bind in shiroFilter, but It doesnt seem the
> case
> My Shiro Filter....
>
>
> <!-- SHIRO FILTER -->
>
>     <filter>
>
>         <filter-name>ShiroFilter</filter-name>
>
>
>   <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
>
>         <init-param>
>
>            <param-name>config</param-name>
>
>            <param-value>
>
>  [main]
>
>  realmA = com.misPartidos.web.MyRealm
>
>            </param-value>
>
>         </init-param>
>
>     </filter>
>
>   <filter-mapping>
>
>    <filter-name>ShiroFilter</filter-name>
>
>     <url-pattern>/*</url-pattern>
>
>   </filter-mapping>
>
> As I dont know spring I couldnt understand the example given enogh .
>
> Thank in advance
>
> --
> Fernando Wermus.
>
> www.linkedin.com/in/fernandowermus
>