54.4. 使用 Java DSL 的示例
在 Spring Boot 和 Quarkus 运行时中,可以通过配置属性配置 Camel Jasypt。如需更多信息,请参阅其相应的文档页面。
在 Java DSL 中,您需要将 Jasypt 配置为 JasyptPropertiesParser 实例,并在 Properties 组件中设置属性,如下所示:
// create the jasypt properties parser
JasyptPropertiesParser jasypt = new JasyptPropertiesParser();
// set the master password (see above for how to do this in a secure way)
jasypt.setPassword("secret");
// create the properties' component
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:org/apache/camel/component/jasypt/secret.properties");
// and use the jasypt properties parser, so we can decrypt values
pc.setPropertiesParser(jasypt);
// end enable nested placeholder support
pc.setNestedPlaceholder(true);
// add properties component to camel context
context.setPropertiesComponent(pc);
可以在 JasyptPropertiesParser 上配置自定义算法,如下所示:
JasyptPropertiesParser jasyptPropertiesParser = new JasyptPropertiesParser();
jasyptPropertiesParser.setAlgorithm("PBEWithHmacSHA256AndAES_256");
jasyptPropertiesParser.setRandomSaltGeneratorAlgorithm("PKCS11");
jasyptPropertiesParser.setRandomIvGeneratorAlgorithm("PKCS11");
属性文件 secret.properties 将包含您的加密配置值,如下所示。注意密码值如何加密,并像 ENC (这里的值) 括起来。
my.secret.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)