micronaut - 未调用 Micronaut AuthenticationProvider
问题描述
我想按照文档中的描述AuthenticationProvider
为micronaut-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。
- micronaut.security.authentication-provider-strategy:ANY(默认保留)
解决方案
解决方案: AuthenticationProviders
在 Micronaut 中,仅在请求实际包含Authorization
标头时才调用。实际上是一个不错的性能改进。但需要知道。调试时可能会产生误导。
推荐阅读
- ios - 如何使标签栏项目仅可用于特定目标?
- javascript - Web Speech API 无法在 Chrome for Android 中正确加载语音
- spring - 休眠自动更新列未由代码更改
- cors - ASP.NET Core 3.1 + CORS + Windows 身份验证 = 401 未经授权
- azure-pipelines - 如何在 azure piplines 中交换之前将文件从生产复制到暂存槽
- python - MySQL order table 按添加行的顺序
- php - 在 Ubuntu 16.04 上使用 PHP7.x 安装 Apache 2.2
- python - Python pyglet 不停地重复播放音频
- php - 限制循环的数量,然后将其传递给下一个进程
- c# - c#指纹生物识别,UserConsentVerificationResult()无响应(WPF)