0

我已经看到了一些没有自动接线的解决方案,但我试图让它与自动接线一起使用。自上周以来我一直在尝试这个,但没有找到适合我的解决方案,可能是我没有正确实施它,所以任何帮助都会很棒。

我有一个属性文件myprops.properties

Wsdl=someurl
UserName=admin
UserPassword=ENC(encriptedpassword)

在我的 servlet.xml 文件中我替换了

<context:property-placeholder location="classpath*:myprops.properties" />

    <bean id="propertyPlaceholderConfigurer"
            class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
            <constructor-arg ref="configurationEncryptor" />
            <property name="location" value="classpath:myprops.properties" />
        </bean>
        <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
            <property name="config" ref="environmentVariablesConfiguration" />
        </bean>
        <bean id="environmentVariablesConfiguration"
              class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
              <property name="algorithm" value="PBEWithMD5AndDES" />
              <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" />
</bean>

在我的 service.java 中,我自动连接这些值,如下所示:

    @Autowired
    public void setUserPassword(@Value("${UserPassword}") String userPassword) {
        this.userPassword = userPassword;
    }

    @Autowired
    public void setUserName(@Value("${UserName}") String userName) {
        this.userName = userName;
    }

    @Autowired
    public void setWsdl(@Value("${Wsdl}") String wsdl) {
        this.wsdl = wsdl;
    }

事情是当我没有加密密码时这是有效的,即UserPassword=nonencriptedpassword

但是一旦我将其加密并使用 ENC() 我就会收到以下错误

weblogic.application.ModuleException: 
    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1510)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:482)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.NullPointerException
    at org.jasypt.encryption.pbe.config.SimplePBEConfig.getPasswordCharArray(SimplePBEConfig.java:434)
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.resolveConfigurationPassword(StandardPBEByteEncryptor.java:740)
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:590)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.initialize(StandardPBEStringEncryptor.java:553)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:705)
    Truncated. see log file for complete stacktrace

这可能是一些我不知道或忽略的愚蠢简单的事情,但我已经尝试按照Jasypt wiki和网站上的教程以及教程xmx1024和 jayway 上教程,我确定我找到了一个使用自动连线的但我好像再也找不到了。

仅供参考:我使用的是 spring 3.0.4、Spring Security 3.0.4 和 jasypt 1.9

任何帮助都是极好的

更新

我已将环境变量设置为APP_ENCRYPTION_PASSWORD等于纯文本密码,并将属性文件中的密码设置为的返回值 encrypt input=plaintextpassword password=APP_ENCRYPTION_PASSWORD

我现在得到错误

<11-Mar-2013 16:33:54 o'clock GMT> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.jasypt.exceptions.EncryptionOperationNotPossibleException.
org.jasypt.exceptions.EncryptionOperationNotPossibleException
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:981)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
    at org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:109)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:112)
    Truncated. see log file for complete stacktrace
> 
<11-Mar-2013 16:33:54 o'clock GMT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1363019632631' for task '0'. Error is: 'weblogic.application.ModuleException: '
weblogic.application.ModuleException: 
    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1510)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:482)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
    Truncated. see log file for complete stacktrace
Caused By: org.jasypt.exceptions.EncryptionOperationNotPossibleException
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:981)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
    at org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:109)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:112)
    Truncated. see log file for complete stacktrace
> 
<11-Mar-2013 16:33:54 o'clock GMT> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 1 task for the application 'adminUI_EA'.> 
<11-Mar-2013 16:33:54 o'clock GMT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application 'adminUI_EA'.> 
<11-Mar-2013 16:33:54 o'clock GMT> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: :org.jasypt.exceptions.EncryptionOperationNotPossibleException:null
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:981)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
    at org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:109)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:112)
    Truncated. see log file for complete stacktrace
> 

密码加密是通过以下方式完成的

C:\Users\jonnie\Desktop\jasypt-1.9.0\bin>encrypt input=****** password=APP_ENCRYPTION_PASSWORD

----ENVIRONMENT-----------------

Runtime: Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM 20.12-b01



----ARGUMENTS-------------------

input: *******
password: APP_ENCRYPTION_PASSWORD



----OUTPUT----------------------

****encriptedPassword****
4

2 回答 2

1

这篇文有一个很好的例子,在使用 @Service 构建的 bean 上使用 @Value。该测试使用@Autowire 设置@Service bean。

于 2013-04-29T16:02:21.743 回答
0
  1. 设置以下变量 Eclipse - 转到运行配置并在环境选项卡下设置新变量键/值 APP_ENCRYPTION_PASSWORD=MyKey 如果在 UNIX 上运行 - 导出 APP_ENCRYPTION_PASSWORD=MyKey

  2. 创建如下所示的bean =>

    类路径:/app1.properties 类路径:/app2.properties

于 2014-01-24T17:37:14.733 回答