gpt4 book ai didi

quarkus - 如何在 Quarkus 中使用 Jasypt 加密和解密数据库密码

转载 作者:行者123 更新时间:2023-12-05 06:47:18 37 4
gpt4 key购买 nike

我们如何在 Quarkus 中使用 jasypt 加密和解密属性文件中的数据库密码。解密将在加载或启动应用程序时发生。请分享您对此的意见或想法。

@chrisgleissner 非常感谢任何帮助。

应用程序属性

quarkus.datasource.db-kind=postgrequarkus.datasource.username=用户名quarkus.datasource.password=encrypted pwd(加密需要加载应用时解密)

最佳答案

您可以实现自定义凭据提供程序。界面是:

public interface CredentialsProvider {

String USER_PROPERTY_NAME = "user";
String PASSWORD_PROPERTY_NAME = "password";

Map<String, String> getCredentials(String credentialsProviderName);

}

来自文档:

USER_PROPERTY_NAME and PASSWORD_PROPERTY_NAME are standard properties that should be recognized by any consuming extension that support username/password based authentication. It is required that implementations be valid @ApplicationScoped CDI beans.

例如,您的加密密码应该可以通过系统属性或环境变量获得。

例子:

@ApplicationScoped
@Unremovable
public class MyCredentialsProvider implements CredentialsProvider {

@Override
public Map<String, String> getCredentials(String credentialsProviderName) {

Map<String, String> properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "hibernate_orm_test");
properties.put(PASSWORD_PROPERTY_NAME, decryptPassword());
return properties;
}

}

并在 application.properties 中将凭证提供程序设置为自定义。

quarkus.datasource.credentials-provider=custom

您可以在文档指南中查看此部分:custom credentials provider

关于quarkus - 如何在 Quarkus 中使用 Jasypt 加密和解密数据库密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67159572/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com