package com.chinaitop.depot.intelligent.utils;

import org.apache.commons.lang.ObjectUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class CustomFilter implements Filter {

	@Override
    public void init(FilterConfig filterConfig) throws ServletException {
 
    }
	
	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) arg0;
		HttpSession session = request.getSession();
		String orgId = "";
		if (session != null){
			orgId = ObjectUtils.toString(session.getAttribute("orgId"),"");
		}
		if (!orgId.isEmpty()) {
			DataPolicyEngine.set(orgId);
		}
		arg2.doFilter(arg0, arg1);
		DataPolicyEngine.remove();
	}
	
	@Override
    public void destroy() {
 
    }

}
