【问题标题】:Log authorisation failures on Spring Boot RESTful API在 Spring Boot RESTful API 上记录授权失败
【发布时间】:2017-03-21 22:41:57
【问题描述】:

在 Spring Boot 中,在 RESTful API 上记录失败的授权尝试的最佳方法是什么,即在下面,如果用户没有管理员角色,默认情况下 Spring 不会记录访问此方法的失败尝试:

    @PreAuthorize("hasAuthority('admin')")
    @RequestMapping(value = "/getVersion", method = RequestMethod.GET)
    public ResponseEntity<?> printVersion() {
        logger.info("Received get request for version");
        return new ResponseEntity<String>(applicationDetails.getAppVersion(), HttpStatus.OK);
    }

我尝试使用ApplicationListener&lt;AuthorizedEvent&gt;,虽然类似的方法适用于ApplicationListener&lt;AbstractAuthenticationEvent&gt;,但它似乎不适用于AuthorizedEvents

【问题讨论】:

标签: spring-boot spring-security


【解决方案1】:

你使用了错误的事件,见AuthorizationFailureEvent

表示安全对象调用失败,因为无法授权主体进行请求。

AccessDecisionManagerAfterInvocationManager 可能会引发此事件。

【讨论】:

    猜你喜欢
    • 2016-05-13
    • 2022-08-04
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2012-11-28
    • 1970-01-01
    相关资源
    最近更新 更多