【发布时间】:2023-01-24 15:48:37
【问题描述】:
添加自定义 HttpAuthenticationMechanism 时,@TestSecurity 注释不再起作用。
- 按照 https://quarkus.io/guides/security-jwt 中的描述设置一个带有 SmallRye JWT 身份验证的项目
- 使用@TestSecurity(user = "user") 注释的测试方法创建@QuarkusTest 测试,检查状态代码 200
- 运行测试,成功,状态码为200
- 添加一个没有任何自定义逻辑的自定义 HttpAuthenticationMechanism,只是转发调用(见下文,记录在https://quarkus.io/guides/security-customization#dealing-with-more-than-one-http-auth-mechanisms)
- 测试不再成功,因为返回的结果是 401
@Alternative @Priority(1) @ApplicationScoped public class MyHttpAuthenticationMechanism implements HttpAuthenticationMechanism { @Inject JWTAuthMechanism jwt; @Override public Uni<SecurityIdentity> authenticate(RoutingContext context, IdentityProviderManager identityProviderManager) { return jwt.authenticate(context, identityProviderManager); } @Override public Uni<ChallengeData> getChallenge(RoutingContext context) { return jwt.getChallenge(context); } @Override public Set<Class<? extends AuthenticationRequest>> getCredentialTypes() { return jwt.getCredentialTypes(); } @Override public Uni<HttpCredentialTransport> getCredentialTransport(RoutingContext context) { return jwt.getCredentialTransport(context); } }我怎样才能使测试再次成功?
【问题讨论】:
标签: quarkus