You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Jillian <ca...@gmail.com> on 2013/07/20 08:17:44 UTC

Shiro logoutFilter not performing logout...

Hello,

I'm new to struts2 & shiro, and I'm trying to create a really simple sample
app (and I haven't found an example of this integration anywhere - so I
hope this is possible).  I'm using Tomcat7, Struts2 2.3.15, and Shiro 1.2.2


I've currently just got one action that grabs some database values and
displays them.  I have shiro protecting the namespace that action is in,
I'm using a very simple standard login.jsp and the users are currently
configured in the shiro.ini.  Log in works, redirects to the action, all is
well.

But I'm having trouble with a simple "logout" link on the results page. I'm
trying to use the logout filter.  Here's my shiro.ini (comments removed):

[main]
authc.loginUrl = /login.jsp
authc.successUrl  = /displayStudent
logout.redirectUrl = /logout.jsp

[urls]
login.jsp = ssl[8443], authc
/logout = logout
/student/** = authc
/** = authc

[users]
admin=hello
jill=bob


(logout.jsp is just a placeholder so I could see if the logout worked - in
the end it willl redirect to login)

My link is:

<a href="<s:url action="logoutAction"/>">LOGOUT</a>


And the struts.xml action for that link is:
       <action name="logoutAction">
          <result>/logout</result>
       </action>

The error I'm getting is your standard 404:

HTTP Status 404 - /b2mu-1.0/logout
type Status report
message /b2mu-1.0/logout
description The requested resource is not available.


And if I refresh the app I'm redirected to the protected content (ie, I'm
still logged in).  So I'm pretty sure the action is redirecting to the
appropriate url, which should be caught by shiro.   Am I missing some
logout filter configuration that I need?

Thanks!
Jillian

Re: Shiro logoutFilter not performing logout...

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

That is certainly a good solution.  The LogoutFilter does the exact same
thing - your approach just happens to be Struts-specific (nothing wrong
with that!).

Cheers,

--
Les Hazlewood | @lhazlewood
CTO, Stormpath | http://stormpath.com | @goStormpath | 888.391.5282


On Sat, Jul 20, 2013 at 10:50 AM, Jillian <ca...@gmail.com> wrote:

> Update:   (for others who might be trying to integrate with struts)
>
> Ok, I couldn't get the filter to work (tried adding the filter to web.xml
> and some other rather funky things...)
>
> But I did realize I was making my original try at LogoutAction too hard,
> and
> was able to create a rather simple version that seems to work:
>
>
> LogotAction.java:
> package whatever;
> import org.apache.shiro.SecurityUtils;
> public class LogoutAction{
>   public String execute(){
>              SecurityUtils.getSubject().logout();
>              return "success";
>   }
> }
>
> struts.xml:
>  <action name="logoutAction" class="info.b2mu.action.LogoutAction">
>    <result>/login.jsp</result>
>  </action>
>
> link in jsp:
> <a href=&quot;&lt;s:url action=&quot;logoutAction&quot;/>">Logout
>
> This may not be the ideal solution, but it seems to work for now....
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Shiro-logoutFilter-not-performing-logout-tp7578925p7578927.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: Shiro logoutFilter not performing logout...

Posted by Jillian <ca...@gmail.com>.
Update:   (for others who might be trying to integrate with struts)

Ok, I couldn't get the filter to work (tried adding the filter to web.xml
and some other rather funky things...)

But I did realize I was making my original try at LogoutAction too hard, and
was able to create a rather simple version that seems to work:


LogotAction.java:
package whatever;
import org.apache.shiro.SecurityUtils;
public class LogoutAction{
  public String execute(){
	     SecurityUtils.getSubject().logout();
	     return "success";
  }
}

struts.xml:
 <action name="logoutAction" class="info.b2mu.action.LogoutAction">
   <result>/login.jsp</result>
 </action>

link in jsp:
<a href=&quot;&lt;s:url action=&quot;logoutAction&quot;/>">Logout 

This may not be the ideal solution, but it seems to work for now....



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Shiro-logoutFilter-not-performing-logout-tp7578925p7578927.html
Sent from the Shiro User mailing list archive at Nabble.com.