views:

37

answers:

0

Hi all,

I have an authen interceptor that check if user is logged in. If not than it will redirect to the login page, with a query string param "url" indicating the referrer URL. I tried using "actionInvocation.getInvocationContext().getParameters()" for passing values to the redirect URL, but have no luck.

Can anyone suggest what I done wrong? Thanks a lot.

Interceptor code:

public String intercept(ActionInvocation actionInvocation) throws Exception {
    Map session = actionInvocation.getInvocationContext().getSession();
    Map params = actionInvocation.getInvocationContext().getParameters();

    String user = (String) session.get(Constants.KEY_USER);

    boolean isAuthenticated = (null!=user);

    if (!isAuthenticated) {
        params.put("backUrl", "http://www.some_url.com/");
        return Action.LOGIN;            
    }
    else {
        return actionInvocation.invoke();
    }
}

struts.xml parts

<global-results>
   <result name="login" type="redirect">/login?url=${backUrl}</result>