jasypt 属性 占位符不起作用
jasypt property placeholder not working
我有这个属性文件:
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>
有人知道为什么吗?
加密密码需要在ENC()函数中写入,并且应该加密。
让我们考虑在密码值为 Login@123 的属性文件中......现在属性文件中的加密值将是:-
password=ENC(B0u7D8wLwq/ugin31KNpP78gBcLP7VIN)
Step1 :- 我们可以在 \jasypt-1.9.2\bin 目录的命令提示符下使用以下命令生成密钥 :- encrypt input="Login@123" password=sqlpassword algorithm=PBEWithMD5AndDES
Step2 :- 在运行环境中我们需要给(右击->运行 As->运行 配置->环境):-变量:- MULE_ENCRYPTION_PASSWORD 和值:-sqlpassword
在你的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
我遇到了类似的问题,我按照 Activemq web site . In my case issue was PropertyPlaceholderConfigurer bean was loaded for to load other properties before the EncryptablePropertyPlaceholderConfigurer bean. So remove PropertyPlaceholderConfigurer bean's if any just add EncryptablePropertyPlaceholderConfigurer bean even for other non-encrypted properties as explained in Activemq 中的说明配置了所有内容,然后一切正常。
我有这个属性文件:
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>
有人知道为什么吗?
加密密码需要在ENC()函数中写入,并且应该加密。
让我们考虑在密码值为 Login@123 的属性文件中......现在属性文件中的加密值将是:-
password=ENC(B0u7D8wLwq/ugin31KNpP78gBcLP7VIN)
Step1 :- 我们可以在 \jasypt-1.9.2\bin 目录的命令提示符下使用以下命令生成密钥 :- encrypt input="Login@123" password=sqlpassword algorithm=PBEWithMD5AndDES
Step2 :- 在运行环境中我们需要给(右击->运行 As->运行 配置->环境):-变量:- MULE_ENCRYPTION_PASSWORD 和值:-sqlpassword
在你的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
我遇到了类似的问题,我按照 Activemq web site . In my case issue was PropertyPlaceholderConfigurer bean was loaded for to load other properties before the EncryptablePropertyPlaceholderConfigurer bean. So remove PropertyPlaceholderConfigurer bean's if any just add EncryptablePropertyPlaceholderConfigurer bean even for other non-encrypted properties as explained in Activemq 中的说明配置了所有内容,然后一切正常。