logininterceptor.java

来自「Webwork+Spring+Freemake框架」· Java 代码 · 共 46 行

JAVA
46
字号
package neo.core.common;

import neo.core.Constants;
import neo.core.util.QueryUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;

/**
 * 登录拦截器,用于阻止未登录用户访问系统
 */
public class LoginInterceptor implements Interceptor {
	protected final Log log = LogFactory.getLog(getClass());

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		Action action = (Action) invocation.getAction();
		String actionName = invocation.getInvocationContext().getName();
		if (action instanceof Anonymous || "login".equals(actionName)
				|| "logout".equals(actionName)) {
			return invocation.invoke();
		} else {
			if (ActionContext.getContext().getSession().get(
					Constants.LOGIN_USER) != null) {
				return invocation.invoke();
			}
		}

		ActionContext.getContext().getSession().put(Constants.ORIGINAL_URL,
				QueryUtil.getRequestURL(ServletActionContext.getRequest()));
		return Action.LOGIN;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?