Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

java - Redirecting to a correct action after authentication interceptor in 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.

My problem is the following:

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.

How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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}")
})

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...