首页 > 解决方案 > 未调用 Micronaut AuthenticationProvider

问题描述

我想按照文档中的描述AuthenticationProvidermicronaut-security添加一个自定义。但是我的自定义实现从未被调用:

控制器:

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

自定义 AuthenticationProvider

@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 [...]

    }
}

为什么从不调用身份验证方法?

一些可能相关的更多信息:

标签: micronaut

解决方案


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


推荐阅读