@Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); // create the jasypt properties parser JasyptPropertiesParser jasypt = new JasyptPropertiesParser(); // and set the master password jasypt.setPassword("supersecret"); // we can avoid keeping the master password in plaintext in the application // by referencing a environment variable // export CAMEL_ENCRYPTION_PASSWORD=supersecret // jasypt.setPassword("sysenv:CAMEL_ENCRYPTION_PASSWORD"); // setup the properties component to use the production file PropertiesComponent prop = context.getComponent("properties", PropertiesComponent.class); prop.setLocation("classpath:rider-test.properties"); // and use the jasypt properties parser so we can decrypt values prop.setPropertiesParser(jasypt); return context; }
@Override public CamelContext createCamelContext() { // normally this would be set along the lines of -DjasyptMasterPassword=encryptionPassword // in a place appropriate to the runtime System.setProperty("jasyptMasterPassword", "encryptionPassword"); JasyptPropertiesParser propParser = new JasyptPropertiesParser(); propParser.setPassword("sys:jasyptMasterPassword"); PropertiesComponent propComponent = new PropertiesComponent(); propComponent.setLocation("classpath:placeholder.properties"); propComponent.setPropertiesParser(propParser); CamelContext camelContext = new DefaultCamelContext(); camelContext.addComponent("properties", propComponent); return camelContext; }
@Override public CamelContext createCamelContext() { JasyptPropertiesParser propParser = new JasyptPropertiesParser(); propParser.setPassword("encryptionPassword"); PropertiesComponent propComponent = new PropertiesComponent(); propComponent.setLocation("classpath:placeholder.properties"); propComponent.setPropertiesParser(propParser); CamelContext camelContext = new DefaultCamelContext(); camelContext.addComponent("properties", propComponent); return camelContext; }
@Test public void testPasswordDecryption() throws Exception { // create the jasypt properties parser JasyptPropertiesParser jasypt = new JasyptPropertiesParser(); // and set the master password jasypt.setPassword("secret"); // create the properties component PropertiesComponent pc = new PropertiesComponent(); pc.setLocation("classpath:password.properties"); // and use the jasypt properties parser so we can decrypt values pc.setPropertiesParser(jasypt); CamelContext camelctx = new DefaultCamelContext(); camelctx.addComponent("properties", pc); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").transform().simple("Hi ${body} the decrypted password is: ${properties:cool.password}"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "John", String.class); Assert.assertEquals("Hi John the decrypted password is: tiger", result.trim()); } finally { camelctx.stop(); } }