com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceWrapper Maven / Gradle / Ivy
package com.ulisesbocchio.jasyptspringboot;
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.properties.PropertyValueEncryptionUtils;
import org.springframework.core.env.PropertySource;
import org.springframework.util.Assert;
/**
* Wrapper for {@link PropertySource} instances that simply delegates the {@link #getProperty} method
* to the {@link PropertySource} delegate instance to retrieve properties, while checking if the resulting
* property is encrypted or not using the Jasypt convention of surrounding encrypted values with "ENC()".
* When an encrypted property is detected, it is decrypted using the provided {@link StringEncryptor}
*
* @author Ulises Bocchio
*/
public class EncryptablePropertySourceWrapper extends PropertySource implements EncryptablePropertySource {
private final PropertySource delegate;
private final StringEncryptor encryptor;
public EncryptablePropertySourceWrapper(PropertySource delegate, StringEncryptor encryptor) {
super(delegate.getName(), delegate.getSource());
Assert.notNull(delegate, "PropertySource delegate cannot be null");
Assert.notNull(encryptor, "StringEncryptor cannot be null");
this.delegate = delegate;
this.encryptor = encryptor;
}
@Override
public Object getProperty(String name) {
return getProperty(encryptor, delegate, name);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy