- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我当前的项目中,我们将用户登录信息存储在 MongoDB 集合中。我们希望实现一种身份验证机制,根据存储在所述 MongoDB 中的信息检查请求中的凭据。有一个教程可以做到这一点with JPA + Postgres但没有关于以相同容量使用 MongoDB 的信息。我怀疑我需要为这种情况编写一个自定义 IdentityProvider。我尝试使用 JPA 身份提供程序作为基础,但看起来 security-jpa 源代码仅包含 an abstract identity provider ,而actual provider is generated automatically using black magic 。有没有人成功地将现有的 Quarkus 安全架构适应 MongoDB 或 security-jpa 未涵盖的其他任何内容?
最佳答案
经过一些研究,我能够让自定义的 IdentityProvider
工作。这是一个非常简单的演示(没有任何 MongoDB 逻辑):
@ApplicationScoped
public class DemoIdentityProvider implements IdentityProvider<UsernamePasswordAuthenticationRequest> {
private static final Map<String, String> CREDENTIALS = Map.of("bob", "password124", "alice", "hunter2");
@Override
public Class<UsernamePasswordAuthenticationRequest> getRequestType() {
return UsernamePasswordAuthenticationRequest.class;
}
@Override
public Uni<SecurityIdentity> authenticate(UsernamePasswordAuthenticationRequest request,
AuthenticationRequestContext authenticationRequestContext) {
if (new String(request.getPassword().getPassword()).equals(CREDENTIALS.get(request.getUsername()))) {
return Uni.createFrom().item(QuarkusSecurityIdentity.builder()
.setPrincipal(new QuarkusPrincipal(request.getUsername()))
.addCredential(request.getPassword())
.setAnonymous(false)
.addRole("admin")
.build());
}
throw new AuthenticationFailedException("password invalid or user not found");
}
}
请注意,为了访问 QuarkusSecurityIdentity
,需要将 quarkus-security
扩展作为依赖项包含在 pom.xml
中:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security</artifactId>
</dependency>
此外,需要将 quarkus.http.auth.basic=true
添加到 application.properties
中,以便将身份提供程序与基本身份验证一起使用。
关于quarkus - 在 Quarkus 中使用自定义身份提供商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74621459/
我在前几天的测验中遇到了以下问题。 Consider the code fragment (assumed to be in a program in which all variables are
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我刚开始接触 Objective-C,一般来说是 C,所以我想这也是一个 C 问题。它更像是一个为什么的问题,而不是一个如何做的问题问题。 我注意到,在除以两个整数时,小数部分向下舍入为 0,即使结果
我是一名优秀的程序员,十分优秀!