49.4. 使用 Java DSL 的示例
在 Spring Boot 和 Quarkus 运行时中,Camel Jasypt 可通过配置属性进行配置。如需更多信息,请参阅对应的文档页面。
在 Java DSL 中,您需要将 Jasyptpt 配置为 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==)