I’ve got a LoginInterceptor that runs before most actions and checks if the member is logged in or not. If it is, the page is shown, otherwise it is redirected to login page.
However I just noticed the interceptor “blocks” all URL parameters. Basically if there is an interceptor before an action, URL parameters for this action won’t be passed to setters.
This is my interceptor:
public class LoginInterceptor extends AbstractInterceptor {
public String intercept(final ActionInvocation invocation) throws Exception {
final String REDIR = "loginRedirect";
AuthenticationService auth = new AuthenticationService();
if (auth.isMemberLoggedIn()) {
return invocation.invoke();
} else {
return REDIR;
}
}
}
I suspect the invocation.invoke() invokes the action, but without the parameters.
What can I do about it?
UPDATE:
AuthenticationService.isMemberLoggedIn()
public boolean isMemberLoggedIn() {
Map<String, Object> session = ActionContext.getContext().getSession();
String username = (String) session.get("username");
if (username != null) {
return true;
} else {
return false;
}
}
struts.xml
<package name="global" extends="struts-default">
<interceptors>
<interceptor name="loginInterceptor" class="community.interceptor.LoginInterceptor" />
</interceptors>
<global-results>
<result name="loginRedirect" type="redirect">/members/login</result>
</global-results>
</package>
Then each package extends global and I invoke them in each action:
<interceptor-ref name="loginInterceptor" />
If your interceptor stack does not include the
paramsinterceptor, then this problem will occur. You should configure your stack something along the lines of this:Or, you can extend an out-of-the-box stack: