Spring Boot (XML Configuration) & Jasypt Integration



我的应用程序只是启动一个ActiveMQ代理。

我想在 Spring Boot 中使用基于 XML 的配置,以使用 ActiveMQ 代理的 XML 配置(此处引用(。

我正在使用 jasypt-spring-boot-starter 来满足我的加密需求,但在初始化 XML 配置时,我的密码的加密值似乎没有被解密。

启动期间没有错误。只是当我尝试使用管理员/用户访问代理时,它将失败并显示错误"用户名 [user] 或密码无效"。

主 Spring 启动应用类

@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
@RestController
@ImportResource({"classpath:activemq.xml"})
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}

自 Broker Config (activemq.xml(

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core 
http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="${activemq.broker.name}" dataDirectory="${activemq.broker.data}">
<plugins>
<runtimeConfigurationPlugin checkPeriod="1000" />
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="admin" password="${activemq.broker.admin.password}" groups="users,admins" />
<authenticationUser username="user" password="${activemq.broker.user.password}" groups="users" />
<authenticationUser username="guest" password="${activemq.broker.guest.password}" groups="guests" />
</users>
</simpleAuthenticationPlugin>
</plugins>
...more

应用程序属性

jasypt.encryptor.password=thisisnotapassword
jasypt.encryptor.algorithm=PBEWITHMD5ANDTRIPLEDES
activemq.broker.admin.password=ENC(OZRghRNXYpRiiw18KD7P6Uf2Y7fOieI7)
activemq.broker.user.password=ENC(yOiHeJlh6Z+VRVmSZe//Yw==)
activemq.broker.guest.password=guest

我从启动日志中注意到的一件事是 activemq.xml 在 jasypt 相关日志出现之前加载

Loading XML bean definitions from class path resource [activemq.xml]
...some logs
String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor

这可以通过使用自定义环境来解决,如 https://github.com/ulisesbocchio/jasypt-spring-boot 中所述:

new SpringApplicationBuilder()
.environment(new StandardEncryptableEnvironment())
.sources(Application.class).run(args);

从 README.md:

此方法对于提前访问加密属性非常有用 启动。虽然在大多数情况下不需要,但在以下情况下可能很有用 自定义 Spring Boot 的初始化行为或与某些集成 很早就配置的功能,例如日志记录 配置。

最新更新