jasypt属性占位符不工作

时间:2015-07-23 23:19:30

标签: mule mule-studio

我有这个属性文件:

secret.key = ENC(foobar)
region = ABC

然后在config.xml

<spring:beans>

    <encryption:encryptor-config id="eConf" password-sys-property-name="MULE_ENCRYPTION_PASSWORD" algorithm="PBEWithMD5AndDES" password="" />
    <encryption:string-encryptor id="stringEnc" config-bean="eConf" />
    <encryption:encryptable-property-placeholder encryptor="stringEnc" location="${env}.properties" />

</spring:beans>

但是,财产占位符不起作用,例如:

<sqs:config secretKey="${secret.key}" region="${region}"></sqs-config>

有谁知道为什么?

2 个答案:

答案 0 :(得分:4)

加密密码需要在ENC()函数内写入,并且应加密。

让我们在属性文件中考虑密码值为Login @ 123 ...现在属性文件中的加密值将是: -

password=ENC(B0u7D8wLwq/ugin31KNpP78gBcLP7VIN) 

Step1 : - 我们可以使用\ jasypt-1.9.2 \ bin目录的命令提示符中的以下命令生成密钥: - encrypt input="Login@123" password=sqlpassword algorithm=PBEWithMD5AndDES

Step2 : - 在运行时环境中我们需要给出(右键单击&gt;运行As-&gt;运行配置 - &gt;环境): - 变量: - MULE_ENCRYPTION_PASSWORD和值:-sqlpassword < / p>

Mule配置中,您需要将其配置如下: -

 <spring:beans>
        <spring:bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
            <spring:property name="algorithm" value="PBEWithMD5AndDES"/>
            <spring:property name="passwordEnvName" value="MULE_ENCRYPTION_PASSWORD"/>
        </spring:bean>

        <!-- The will be the encryptor used for decrypting configuration values. -->
        <spring:bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
            <spring:property name="config" ref="environmentVariablesConfiguration"/>
        </spring:bean>

        <!-- The EncryptablePropertyPlaceholderConfigurer will read the -->
        <!-- .properties files and make their values accessible as ${var} -->
        <!-- Our "configurationEncryptor" bean (which implements -->
        <!-- org.jasypt.encryption.StringEncryptor) is set as a constructor arg. -->

        <spring:bean id="propertyConfigurer" class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
            <spring:constructor-arg ref="configurationEncryptor"/>
            <spring:property name="locations">
                <spring:list>
                    <spring:value>conf/yourPropertyFile.properties</spring:value>
                </spring:list>
            </spring:property>
        </spring:bean>

然后您可以使用加密值,例如: - ${password}

参考: - http://blogs.mulesoft.org/encrypting-passwords-in-mule/
http://pragmaticintegrator.wordpress.com/2014/03/09/using-encrypted-passwords-with-mule-esb/
https://code.google.com/p/soi-toolkit/issues/detail?id=183
http://soi-toolkit.googlecode.com/svn-history/r2022/wiki/UG_PropertyFile.wiki

答案 1 :(得分:0)

我有类似的问题,我确实按照Activemq web site中的说明配置了所有内容。就我而言,问题是在PropertyPlaceholderConfigurer bean之前加载了EncryptablePropertyPlaceholderConfigurer bean来加载其他属性。因此,请删除PropertyPlaceholderConfigurer bean,如果有的话只需添加EncryptablePropertyPlaceholderConfigurer bean,甚至为Activemq中所述的其他非加密属性添加它,也可以正常工作。