Wie verwende ich Jasypt mit Federn autowire?

Habe ich finden Sie einige Lösungen für diese ohne die autowire aber ich bin versucht, es zu erhalten zu arbeiten, mit dem auto Draht. Ich habe versucht, dies seit der letzten Woche, fand aber keine Lösung, die funktionierte in meinem Fall, kann es sein, dass ich mich nicht an der Umsetzung ist es richtig, so dass jede Hilfe wäre toll.

Ich habe eine properties-Datei myprops.properties:

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

und in meinem servlet.xml die Datei habe ich ersetzt

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

mit

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

und in meinem service.java ich bin auto-Verdrahtung diese Werte wie diese:

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

Sache ist, das funktioniert, wenn ich nicht das Passwort verschlüsselt, d.h. UserPassword=nonencriptedpassword

aber sobald ich verschlüsselt es und verwenden ENC() bekomme ich die folgende Fehlermeldung

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

So kann es etwas blöd einfach, dass ich bin nicht bewusst, oder Sie haben über sehen, aber ich haben versucht folgenden tutorials auf der Jasypt wiki und Website sowie tutorials xmx1024 und auf jayway und ich bin sicher, ich hatte eine gefunden, mit der autowired aber ich kann nicht scheinen, um es wieder zu finden.

FYI: ich bin mit spring 3.0.4, Spring Security 3.0.4 und jasypt 1.9

jede Hilfe wäre Genial

Update

Habe ich eine Enviorment Variable APP_ENCRYPTION_PASSWORD gleich dem Klartext-Passwort und legen Sie das Kennwort in den Eigenschaften der Datei, wie Sie den zurückgegebenen Wert
encrypt input=plaintextpassword password=APP_ENCRYPTION_PASSWORD

Bekomme ich jetzt den Fehler

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

Passwort-Verschlüsselung wurde in der folgenden Weise

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****
  • Anstelle von autowiring, versuchen Sie einfach Klasse Felder für die einzelnen Eigenschaften und kommentieren diese mit @Value.
  • Aber Sollte ich in der Lage sein, dies zu erreichen, mit der Autowire?
  • Ich bin mir nicht sicher. @Autowired verwendet werden, sollten mit Spring beans. Deine Saiten sind nicht deklariert, wie Bohnen überall. @Value wird verwendet, um einen Standardwert für ein Feld und ich denke, dass ist das, was du bist suchen für.
  • Ich bin nicht sehr erfahren mit Feder und war irgendwie geworfen in the deep end eine Weile zurück, so entschuldigt meine Unwissenheit, aber wenn ich entfernen Sie die @Autowired und lassen Sie die @Value wo es ist, ist es das, was du meinst?
  • Entfernen Sie die @Autowired loswerden setter-Methoden und nur kommentieren Ihre privaten Felder mit der @Value. Sie können halten Sie die setter, sondern kommentieren Sie Ihre Felder statt der Anmerkungen zu den argument der Methoden.
  • Ich bekomme den exakt gleichen Fehler mit den @Value als mit der @Autowired Es nur passiert, wenn ich den ENC (), da beide veröffentlichen auf dem server in Ordnung, wenn ich nicht verwenden, ENC()
  • Das ist es nicht, EnvironmentStringPBEConfig gibt null zurück, wenn der Wert nicht konfiguriert ist...hmm
  • Ändern Sie die passwordEnvName - Eigenschaft-Wert in Ihrem xml zu UserPassword. Lasst uns alles versuchen.
  • Ich bekomme 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? und ich habe es versucht mit dem setter auch wiederhergestellt und erhalten die gleichen Fehler
  • Ich meinte es ändern zu <property name="passwordEnvName" value="UserPassword" /> statt <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" />
  • ah sorry. Das habe ich versucht und bekomme jetzt den Ursprünglichen Fehler java.lang.NullPointerException at org.jasypt.encryption.pbe.config.SimplePBEConfig.getPasswordCharArray(SimplePBEConfig.java:434)
  • lassen Sie uns weiterhin diese Diskussion im chat

InformationsquelleAutor jonnie | 2013-03-11
Schreibe einen Kommentar