拦截器---java

来源:互联网 发布:java swing的网格布局 编辑:程序博客网 时间:2024/06/04 19:07

拦截器—java

代码

public class SpringAuthInterceptor extends HandlerInterceptorAdapter {    private static final Log log = LogFactory.getLog(SpringAuthInterceptor.class);    private static final int BUSSINESS_TYPE = 2;    private static final List<String> BUSSINESS_EXCLUDE_URL = new ArrayList<String>();    @Autowired    private SystemManagementService systemManagementService;    static {        BUSSINESS_EXCLUDE_URL.addAll(ListUtil.toList(new String[] { "/bigdata/issueCommand/index.do",                "/bigdata/issueCommand/mfIndex.do", "/bigdata/issueCommand/list.do", "/bigdata/denyOrLift/index.do",                "/bigdata/basicData/index.do", "bigdata/cdnsubnet/create.do", "bigdata/cdnsubnet/index.do" }));    }    @Override    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)            throws IOException, ServletException {        HttpSession session = request.getSession();        String applicationPath = request.getContextPath();        String requestPath = request.getRequestURI().substring(applicationPath.length());        User user = (User) session.getAttribute("user");        if (null == user) {            response.sendRedirect(applicationPath + "/login.do");            return false;        } else {            // 如果是业务员,判断访问URL的权限            if (user.getType() == BUSSINESS_TYPE && BUSSINESS_EXCLUDE_URL.contains(requestPath)) {                response.sendRedirect(applicationPath + "/index.do");                return false;            }        }        log.info(requestPath);        try {// 存日志失败,也要继续,查询操作不存日志,简单规则TODO            String lowerpath = requestPath.toLowerCase();            if (!lowerpath.contains("index.do") && !lowerpath.contains("list.do") && !lowerpath.contains("query.do")) {                systemManagementService.saveLog(user.getUsername(), IPUtil.findRequestIP(request), requestPath);            }        } catch (RuntimeException e) {            log.error(e.getMessage(), e);        }        return true;    }}
0 0
原创粉丝点击