AjaxAuthenticationEntryPoint.java 1.1 KB

12345678910111213141516171819202122232425
  1. package com.jkcredit.invoice.hub.config;
  2. import com.alibaba.fastjson.JSON;
  3. import com.jkcredit.invoice.hub.model.vo.common.AjaxResponseBody;
  4. import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
  5. import org.springframework.security.core.AuthenticationException;
  6. import org.springframework.security.web.AuthenticationEntryPoint;
  7. import org.springframework.stereotype.Component;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import java.io.IOException;
  12. @Component
  13. public class AjaxAuthenticationEntryPoint implements AuthenticationEntryPoint {
  14. @Override
  15. public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
  16. httpServletResponse.setContentType("application/json;charset=UTF-8");
  17. httpServletResponse.setContentType("application/json");
  18. httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  19. httpServletResponse.getWriter().write(JSON.toJSONString(new AppResponseVo(401, "未登录", "")));
  20. }
  21. }