登陆拦截器

<!-- 配置拦截器站 -->
		<interceptors>
			<interceptor name="loginInterceptor" class="org.cric.interceptor.LoginInterceptor"></interceptor>
			<interceptor-stack name="myStack">
				<interceptor-ref name="loginInterceptor">
					<param name="excludeMethods">enterSystem</param><!--配置黑名单-->
				</interceptor-ref>
				<interceptor-ref name="defaultStack"/>
			</interceptor-stack>
		</interceptors>
		
		<default-interceptor-ref name="myStack"/>

 

package org.cric.interceptor;

import org.cric.dao.AdminDao;
import org.cric.dao.impl.AdminDaoImpl;
import org.cric.model.Admin;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
/*
 * 登陆拦截器
 */
public class LoginInterceptor extends MethodFilterInterceptor {
	private static final long serialVersionUID = -8116433908456886908L;
	private AdminDao adminDaoImpl=new AdminDaoImpl();
	private static final String SESSIONEKEY="adminbar";//session的key.
	
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		Object obj=invocation.getInvocationContext().getSession().get(SESSIONEKEY);//获取Session
		if(obj!=null){
			Admin admin=(Admin)obj;
			Admin admin2=adminDaoImpl.check(admin);//防止黑客模拟admin对象
			if(admin2!=null){
				if(admin2.getStatus()==0){//判断管理员是否锁定
					return invocation.invoke();//执行    Action 层
				}
			}
			
		}
		return "gologinPage";
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值