0

I have see some solutions for this without the autowire but I am trying to get it to work with with the auto wire. I have been trying this since last week but found no solutions that worked in my case, it may be that I am not implementing it correctly so any help would be great.

I have a properties file myprops.properties:

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

and in my servlet.xml file I replaced

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

with

    <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>

and in my service.java I am auto wiring these values like this:

    @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;
    }

Thing is this works when I don't have the password encripted i.e. UserPassword=nonencriptedpassword

but as soon as I encripted it and use ENC() I get the following error

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

This may be down something stupidly simple that I am unaware of or have over looked but I have tried following tutorials on the Jasypt wiki and site as well as tutorials xmx1024 and on jayway and I'm sure I had found one using the autowired but I can't seem to find it again.

FYI: I am using spring 3.0.4, Spring Security 3.0.4 and jasypt 1.9

any help would be Awesome

Update

I have set an Enviorment Variable APP_ENCRYPTION_PASSWORD equal to the plain text password and set the password in the properties file as the returned value of encrypt input=plaintextpassword password=APP_ENCRYPTION_PASSWORD

I now get the Error

<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
> 

Password encription was done in the following way

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****
jonnie
  • 12,260
  • 16
  • 54
  • 91
  • Instead of autowiring, try just having class fields for each property and annotate those with `@Value`. – Sotirios Delimanolis Mar 11 '13 at 14:35
  • @SotiriosDelimanolis But Should I be able to accomplish this using the Autowire? – jonnie Mar 11 '13 at 14:50
  • I'm not sure. `@Autowired` should be used with Spring beans. Your Strings aren't declared as beans anywhere. `@Value` is used to give a default value to a field and I think that is what you're looking for. – Sotirios Delimanolis Mar 11 '13 at 14:55
  • I'm not very experienced with spring and was kinda thrown into the deep end awhile back so excuse my ignorance but if I remove the `@Autowired` and leave the `@Value` where it is, is that what you mean? – jonnie Mar 11 '13 at 14:59
  • Remove the `@Autowired`, get rid of setter methods and just annotate your private fields with the `@Value`. You can keep the setters, but annotate your fields instead of the annotating the argument of the methods. – Sotirios Delimanolis Mar 11 '13 at 15:00
  • I get the exact same error using the `@Value` as using the `@Autowired` It only happens when I use the ENC() because both publish to the server fine when I don't use ENC() – jonnie Mar 11 '13 at 15:08
  • That's not it, EnvironmentStringPBEConfig returns null if the value is not configured...hmm – Sotirios Delimanolis Mar 11 '13 at 15:15
  • Change the `passwordEnvName` property value in your xml to `UserPassword`. Let's try everything. – Sotirios Delimanolis Mar 11 '13 at 15:17
  • I get `Invalid property 'UserPassword' of bean class [org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig]: Bean property 'UserPassword' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?` and I tried it with the setters restored as well and get same error – jonnie Mar 11 '13 at 15:26
  • I meant change it to `` instead of `` – Sotirios Delimanolis Mar 11 '13 at 15:28
  • ah sorry. I tried that now and I get the Original error `java.lang.NullPointerException at org.jasypt.encryption.pbe.config.SimplePBEConfig.getPasswordCharArray(SimplePBEConfig.java:434)` – jonnie Mar 11 '13 at 15:32
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25966/discussion-between-sotirios-delimanolis-and-jonniem) – Sotirios Delimanolis Mar 11 '13 at 15:39

2 Answers2

1

This blog post has a nice example of using @Value on a bean that is build using @Service. The test uses @Autowire to set up the @Service bean.

rzrelyea
  • 1,467
  • 1
  • 13
  • 19
0
  1. Set the below variable Eclipse - go to run config and under environment tab set below new variable key/value APP_ENCRYPTION_PASSWORD=MyKey If running on UNIX - export APP_ENCRYPTION_PASSWORD=MyKey

  2. Create the beans like below =>

    classpath:/app1.properties classpath:/app2.properties

Jay
  • 11