未调用 Micronaut AuthenticationProvider
Micronaut AuthenticationProvider is not called
我想将自定义 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 [...]
}
}
为什么从未调用过身份验证方法?
更多可能相关的信息:
- 我在后端使用 micronaut。
- micronaut.security.authentication-提供商策略:任何(保留为默认值)
解决方案:Micronaut 中的 AuthenticationProviders
仅在请求实际包含 Authorization
Header 时被调用。实际上是一个不错的性能改进。但是需要知道。调试时可能会产生误导。
我想将自定义 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 [...]
}
}
为什么从未调用过身份验证方法?
更多可能相关的信息:
- 我在后端使用 micronaut。
- micronaut.security.authentication-提供商策略:任何(保留为默认值)
解决方案:Micronaut 中的 AuthenticationProviders
仅在请求实际包含 Authorization
Header 时被调用。实际上是一个不错的性能改进。但是需要知道。调试时可能会产生误导。