Class JsonAuthenticationEntryPoint

java.lang.Object
io.leandev.appfuse.security.auth.JsonAuthenticationEntryPoint
All Implemented Interfaces:
org.springframework.security.web.AuthenticationEntryPoint

public class JsonAuthenticationEntryPoint extends Object implements org.springframework.security.web.AuthenticationEntryPoint

認證入口點,回傳 RFC 7807 格式的 JSON 錯誤回應

原始認證例外會保留到最後的 ErrorDisclosurePolicy 接點;框架預設輸出完整診斷,應用可注入 最小揭露政策收斂 wire response。

回應範例:

{
  "type": "urn:appfuse:error:bad-credentials",
  "title": "Bad Credentials",
  "status": 401,
  "detail": "Password hash did not match for account alice",
  "errorCode": "bad-credentials",
  "exceptionType": "org.springframework.security.authentication.BadCredentialsException",
  "exceptionMessage": "Password hash did not match for account alice",
  "stackTrace": "...",
  "instance": "/auth/login"
}

使用範例:

@Bean
public JsonAuthenticationEntryPoint jsonAuthenticationEntryPoint(
        ObjectMapper objectMapper,
        ErrorDisclosurePolicy disclosurePolicy) {
    return new JsonAuthenticationEntryPoint(objectMapper, disclosurePolicy);
}
  • Constructor Details

    • JsonAuthenticationEntryPoint

      public JsonAuthenticationEntryPoint(tools.jackson.databind.ObjectMapper objectMapper)
    • JsonAuthenticationEntryPoint

      public JsonAuthenticationEntryPoint(tools.jackson.databind.ObjectMapper objectMapper, ErrorDisclosurePolicy disclosurePolicy)
  • Method Details

    • commence

      public void commence(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException
      Specified by:
      commence in interface org.springframework.security.web.AuthenticationEntryPoint
      Throws:
      IOException