小编Leo*_*tez的帖子

身份验证入口点 Spring Boot 2

我正在尝试在 Spring Boot 2 中的 WebSecurityConfig 配置方法中实现自定义 AuthenticationEntryPoint。

我见过很多这样的例子:

@Component
public class Http401UnauthorizedEntryPoint implements AuthenticationEntryPoint {

private final Logger log = LoggerFactory.getLogger(Http401UnauthorizedEntryPoint.class);

/**
 * Always returns a 401 error code to the client.
 */
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg2) throws IOException,
        ServletException {

    log.debug("Pre-authenticated entry point called. Rejecting access");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied");
}
}
Run Code Online (Sandbox Code Playgroud)

但我总是得到 403 而不是 401。

我怎样才能在 Spring boot 2 中做到这一点?

security

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

security ×1