【问题标题】:Spring property loading - decrypting encrypted properties on the flySpring 属性加载 - 动态解密加密属性
【发布时间】:2013-12-17 08:24:54
【问题描述】:

我正在使用 spring-PropertySourcesPlaceholderConfigurer 公开的最新属性加载机制,并尝试即时解密加密的属性。请问PropertyPlaceholderConfigurer 可以覆盖resolvePlaceholder,并为其添加解密机制。

但是,我不知道如何在 PropertySourcesPlaceholderConfigurer 中执行此操作。已尝试覆盖 processProperties,并传入我的自定义 ConfigurablePropertyResolver[with getProperty Overriden],但这不起作用。

MutablePropertySources propertySources = new MutablePropertySources();

try {
    propertySources.addFirst(getExtendPortsProperties());
    propertySources.addFirst(new ResourcePropertySource("classpath:/X.properties"));
    propertySources.addFirst(new ResourcePropertySource("classpath:/Y.properties"));
} catch (IOException e) {
    throw new RuntimeException("failed to read property source", e);
}

这就是我阅读属性的方式。然后,

PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
result.setPropertySources(firePropertiesSources);

这就是我设置属性的方式。

现在,这些 props 中的属性之一已加密,我需要指示 Spring 在用实际值替换占位符之前对其进行解密。[我需要指定我的自定义实现]

【问题讨论】:

    标签: java spring encryption properties


    【解决方案1】:

    您没有自己制作,而是看过 jasypt 吗?它具有您需要的确切功能。看看http://www.jasypt.org/spring31.html

    【讨论】:

    • 谢谢大卫。这符合我的目的。
    • 我已将此添加到我的项目中,它似乎正在发挥作用;但是,在例外情况下,它并没有给我正确的信息。例如 - ,如果 pwd 加密不正确,jasypt 应该给我一个有意义的 - Encyption*** 异常,但它没有。我正在使用“EncryptablePropertiesPropertySource”进行解密。我将所有文件添加为 EncryptablePropertiesPropertySource,然后使用 PropertySourcesPlaceholderConfigurer。有什么指点吗?
    猜你喜欢
    • 2019-09-23
    • 2015-12-29
    • 2015-01-14
    • 1970-01-01
    • 2019-02-28
    • 2011-11-07
    • 1970-01-01
    • 2011-04-15
    • 2017-03-11
    相关资源
    最近更新 更多