在 Struts 2 中的身份验证拦截器之后重定向到正确的操作 [英] Redirecting to a correct action after authentication interceptor in Struts 2

查看:29
本文介绍了在 Struts 2 中的身份验证拦截器之后重定向到正确的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Struts 2 并且我有一个私有的操作包,因为某些操作需要登录才能访问.所以我在我的安全包里有这个:

I'm using Struts 2 and I have a private package of actions, because certain actions require login to be accessed. So I have this in my secure package:

<interceptors>
    <interceptor name="authenticationInterceptor" class="com.koorde.interceptor.AuthenticationInterceptor"/>
        
    <interceptor-stack name="secureStack">
      <interceptor-ref name="authenticationInterceptor"/>
      <interceptor-ref name="defaultStack"/>    
    </interceptor-stack>
</interceptors>
    
<default-interceptor-ref name="secureStack"/>

<global-results>
    <result name="login" type="redirect">dologin</result>
    <result name="session_error" type="redirect"> html/error/hibernate_session.jsp</result>
    <result name="error" type="redirect"> html/error/hibernate_session.jsp</result>
</global-results>

当然还有其他动作定义.

And of course other actions definition.

我的问题如下:

假设用户想要访问他的个人区域.他点击 personalArea 链接,他将被自动重定向到登录页面(因为 personalArea 是一个安全操作).我想要的是:登录后用户自动重定向(以继续操作)到 personalArea 而不是主页.

Let's say a user want to access his personal area. He clicks on personalArea link and he will be automatically redirected on login page (cause personalArea is a secure action). What I want is: after login user is automatically redirect (to continue the action) to personalArea and not home page.

所以,我想要的是:当用户因为安全操作登录系统时,登录后操作(安全)继续执行.

So, what I want is: when user log in into the system because of a secure actions, after login the execution of the action (secured) continues.

我该怎么做?

推荐答案

可能的解决方案之一是跟踪截取其 URL 的用户.您可以在身份验证拦截器中执行此操作.

One of the possible solutions is to keep track of the user intercepting their URLs. You might do it in the authentication interceptor.

String queryString = request.getQueryString();
session.put("savedUrl", request.getRequestURI()+(queryString==null?"":("?"+queryString))); 

使用带有动态参数的全局结果

use the global result with dynamic parameter

@Results({
  @Result(name = "return", type = "redirect", location = "${savedUrl}")
})

登录后检查savedUrl的会话并返回结果"return".假设为动态参数提供了 getter.

after login check the session for savedUrl and return result "return". Assumed providing getter for the dynamic parameter.

这篇关于在 Struts 2 中的身份验证拦截器之后重定向到正确的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆