【问题标题】:Micronaut AuthenticationProvider is not called未调用 Micronaut AuthenticationProvider
【发布时间】:2020-09-15 10:15:55
【问题描述】:

我想将自定义 AuthenticationProvider 添加到 micronaut-security as described in the docs。但我的自定义实现从未被调用:

控制器:

@Get("/team")
@Secured(SecurityRule.IS_AUTHENTICATED)
HttpResponse getTeam(@Body @Valid JoinTeamRequest req) {
    log.info("Get own team")
    return HttpResponse.ok()
}

自定义身份验证提供者

@Singleton
class LiquidoAuthenticationProvider  implements AuthenticationProvider {

    LiquidoAuthenticationProvider() {
        println "============= INIT LiquidoAuthenticationProvider"  // this gets called. Can set a breakpoint on it
    }

    @Override
    public Publisher<AuthenticationResponse> authenticate(HttpRequest<?> httpRequest, AuthenticationRequest<?, ?> authenticationRequest) {
        println "============= authenticate "    // <=== this never gets called. Breakpoint is never reached ?????????? Why?

        [...] some code to authenticate request that returns flowable UserDetails on succcess [...]

    }
}

为什么从不调用 authenticate 方法?

更多可能相关的信息:

  • 我在后端使用 micronaut。
  • micronaut.security.authentication-provider-strategy:ANY(默认保留)

【问题讨论】:

    标签: micronaut


    【解决方案1】:

    解决方案:只有在请求实际包含 Authorization 标头时,才会调用 Micronaut 中的 AuthenticationProviders。实际上是一个不错的性能改进。但需要知道。调试时可能会产生误导。

    【讨论】:

    • 所以基本上不可能实现使用不同标头的AuthenticationProvider?
    • 如果您需要对特定的 HTTP 标头进行特殊处理,我建议您查看过滤器。在那里您可以处理任何请求数据(标头、方法、正文、url、查询参数等)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2011-12-31
    • 2014-11-20
    • 2017-09-19
    • 2014-01-07
    • 1970-01-01
    • 2019-05-23
    相关资源
    最近更新 更多