PageRenderTime 118ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java

https://gitlab.com/mrsunchangemyselfsun/ruoyi-vue
Java | 34 lines | 26 code | 3 blank | 5 comment | 0 complexity | 333fb424743a513414bb79bbb3c0d49a MD5 | raw file
  1. package com.ruoyi.framework.security.handle;
  2. import java.io.IOException;
  3. import java.io.Serializable;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.springframework.security.core.AuthenticationException;
  7. import org.springframework.security.web.AuthenticationEntryPoint;
  8. import org.springframework.stereotype.Component;
  9. import com.alibaba.fastjson.JSON;
  10. import com.ruoyi.common.constant.HttpStatus;
  11. import com.ruoyi.common.core.domain.AjaxResult;
  12. import com.ruoyi.common.utils.ServletUtils;
  13. import com.ruoyi.common.utils.StringUtils;
  14. /**
  15. * 认证失败处理类 返回未授权
  16. *
  17. * @author ruoyi
  18. */
  19. @Component
  20. public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable
  21. {
  22. private static final long serialVersionUID = -8970718410437077606L;
  23. @Override
  24. public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
  25. throws IOException
  26. {
  27. int code = HttpStatus.UNAUTHORIZED;
  28. String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
  29. ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
  30. }
  31. }