Jasypt 1.9.2 与 Spring 4.3.8 兼容吗?

Is Jasypt 1.9.2 compatible with Spring 4.3.8?

我们正在将基于 Ant 的 spring 3.1 应用程序迁移到基于 Maven 的 spring 4.3.8。我们正在使用 Jasypt 1.9.2 加密 属性 文件条目。但是,当应用程序启动时,它会抛出

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer] for bean with name 'propertyPlaceholderConfigurer' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer

jasypt-1.9.2 和 jasypt-spring31-1.9.2 jar 在 WEB-INF/lib 文件夹下可用。以下是应用上下文:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <mvc:annotation-driven />
    <mvc:resources mapping="*.html" location="/" />

    <context:component-scan base-package="com.xyz" />
     <bean id="propertyPlaceholderConfigurer"
      class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
        <constructor-arg ref="configurationEncryptor" />
    </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="password" value="xxxx" /> 
    </bean>
</beans> 

Maven 条目是:

<dependency>
        <groupId>org.jasypt</groupId>
        <artifactId>jasypt-spring31</artifactId>
        <version>1.9.2</version>
</dependency>

没有。根据http://jasypt.org/encrypting-configuration.html:

Spring-集成.properties文件透明解密:Jasypt可以集成到Spring框架([​​=15=]和3.x)的配置系统中,透明解密Spring 应用程序使用的 .properties 文件。了解更多:Spring 2.x, Spring 3.0, Spring 3.1.

不可直接替代,但可以轻松修复

我们在尝试升级到 Jasypt 1.9.3 时也遇到了 Cannot find class [org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer]

我们使用的是 Jasypt 1.4.1,由于漏洞不得不迁移,所以我们唯一的选择(根据漏洞扫描器)是“1.9.2 或更高版本”。

1.9.3 不是 1.4.1 的直接替代品。 class 层次结构发生变化,并且由于我们有 spring 框架 4.x,我们不得不使用 jasypt-spring4 工件:

<dependency>
    <groupId>org.jasypt</groupId>
    <artifactId>jasypt-spring4</artifactId>
    <version>1.9.3</version>
</dependency>

所以我们的 beans(我们直接从 XML 和 spring 使用它)现在看起来像这样:

<bean id="myBasicTextEncryptor" class="org.jasypt.util.text.BasicTextEncryptor">
    <property name="password" value="YouWishIShowYou" />
</bean>

<bean id="myPropertyConfigurer" class="org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <constructor-arg ref="myBasicTextEncryptor" />
    <property name="locations">
        <list>
            <value>classpath:/properties/localSecrets.properties</value>
        </list>
    </property>
</bean>

我们唯一要做的改变就是在 org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer

中添加 4