package com.jiayue.ipfcst.common.security.handle;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Service;

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

/**
 * 登录失败：解决匿名用户访问无权限资源时的异常
 *
 * @author zzy
 * @version 1.0
 * @since 2018/8/23 14:39
 */
@Service
public class EntryPointUnauthorizedHandler implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) {
          response.setHeader("Access-Control-Allow-Origin", "*");
        response.setStatus(403);
    }

}
