用户,角色,权限常用实现方法

POJO 

import java.util.Set;

public class UserVo {
	private Integer id;
	private String uname;
	private String password;
	private Level level;
	
	
	
	public Level getLevel() {
		return level;
	}
	public void setLevel(Level level) {
		this.level = level;
	}
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

}



public class Level {
	private Integer id;
	private String levelName;
	private Set<Quanxian> qx = new HashSet<Quanxian>(0);
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getLevelName() {
		return levelName;
	}
	public void setLevelName(String levelName) {
		this.levelName = levelName;
	}
	public Set<Quanxian> getQx() {
		return qx;
	}
	public void setQx(Set<Quanxian> qx) {
		this.qx = qx;
	}
}

public class Quanxian {
	private Integer id;
	private String quanxian;
	private Integer fatherid;
	private String url;
	public Integer getFatherid() {
		return fatherid;
	}
	public void setFatherid(Integer fatherid) {
		this.fatherid = fatherid;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getQuanxian() {
		return quanxian;
	}
	public void setQuanxian(String quanxian) {
		this.quanxian = quanxian;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}

}


public class AdminLoginCheck extends HttpServlet implements Filter {

//通过 一个过滤器 Filter 进行权限控制
	   private FilterConfig filterConfig;
	    //Handle the passed-in FilterConfig
	    
	    public void init(FilterConfig filterConfig) throws ServletException {
	        this.filterConfig = filterConfig;

	    }

	    //Process the request/response pair
	    public void doFilter(ServletRequest request, ServletResponse response,
	                         FilterChain filterChain) {//System.out.println(this.getClass()+": doFilter()");
	    	HttpServletRequest req = (HttpServletRequest)request;
	    	//System.out.println(req.getServletPath());
            
	        HttpServletResponse res = (HttpServletResponse)response;
	        HttpSession ses = req.getSession();
Uservo uervo =ses.getAttribute("user")
	        try {//System.out.println("in Adminloginf........");
	            if(uervo ==null)
	            {
	            res.sendRedirect(req.getContextPath());
	            }else{
                 Boolean allow= false ;
                 Set<Quanxian> qxs = uservo.getLevel().getQx();
                 For(Quanxian o:qxs){
                    If(o.getUrl().equals(req.getServletPath())){
allow=true;
}
}
If(allow){
 filterChain.doFilter(request, response);}
	            }
	        } catch (ServletException sx) {
	            filterConfig.getServletContext().log(sx.getMessage());
	        } catch (IOException iox) {
	            filterConfig.getServletContext().log(iox.getMessage());
	        }
	    }

	    //Clean up resources
	    public void destroy() {
	    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值