MyHandlerExceptionResolver.java 1.2 KB
Newer Older
liqin's avatar
liqin committed
1
package cn.chnmuseum.party.auth.resolver;
liqin's avatar
liqin committed
2 3 4 5 6 7 8 9 10

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

liqin's avatar
liqin committed
11
public class MyHandlerExceptionResolver implements HandlerExceptionResolver {
liqin's avatar
liqin committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println("==============异常开始=============");
        System.out.println(ex.getMessage());

        // 如果是shiro无权操作,因为shiro 在操作auno等一部分不进行转发至无权限url
        if (ex instanceof UnauthorizedException) {
            System.out.println("==============超时未登录=============");
            return new ModelAndView("login");
        }

        if (ex instanceof AuthorizationException) {
            System.out.println("==============无权限=============");
        }
        System.out.println("==============异常结束=============");
        return null;
    }

}