Spring4 Jasypt1.9.2 Integration

1.add jasypt with maven

       <!-- Encryption / Decryption -->

        <dependency>

            <groupId>org.jasypt</groupId>

            <artifactId>jasypt-spring3</artifactId>

            <version>${jasypt.version}</version>

 

       </dependency>

2.Download jasypt to encrypt passwod on tomcat server

   1)execute command under folder bin to list available algorithms

      ./listAlgorithms.sh

   2)select a algorithm listed above to encrypt database password

     ./encrypt.sh input=dbpasword algorithm=PBEWITHSHA1ANDRC2_40 password=jasypt_is_cool

 

  note:----ERROR-----------------------

 

          Operation not possible (Bad input or parameters)

           Please select another algorithm  

   

3.add properties file:spring.properties

 

   jdbc.driverClassName=oracle.jdbc.driver.OracleDriver

   jdbc.url=jdbc:oracle:thin:@192.168.88.230:1521:xe

   jdbc.username=cms

 

   jdbc.password=ENC(xBpvib/4aRiUz0nH5besvA==)

 

4.add the following information in spring configuration file

 

  <bean id="jasyptConfiguration"

      class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig"

      p:algorithm="PBEWITHSHA1ANDRC2_40"

      p:passwordEnvName="JASYPT"/>

 

<bean id="propertyPasswordEncryptor"

      class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"

      p:config-ref="jasyptConfiguration"/>

      

<bean class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">

   <constructor-arg>

      <ref bean="propertyPasswordEncryptor"/>

    </constructor-arg>

    <property name="location" value="classpath:spring.properties"/> 

    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>

</bean>

 

 

5. Set environment variable in /etc/init.d/tomcat8 file

    JASYPT="dbpassword"

    export JASYPT

6. Restart tomcat

 

猜你喜欢

转载自lyh7609.iteye.com/blog/2400777