package com.jiayue.ssi.handler;

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

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 权限不足：认证过的用户访问无权限资源时的异常
 *
 * @author zzy
 * @version 1.0
 * @since 2018/8/23 14:45
 */
@Service
public class RestAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setStatus(402);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("没有接口访问权限！");
    }
}
