View Javadoc

1   package org.kuali.common.util.property.processor;
2   
3   import java.util.List;
4   import java.util.Properties;
5   
6   import org.jasypt.util.text.TextEncryptor;
7   import org.kuali.common.util.PropertyUtils;
8   import org.springframework.util.Assert;
9   
10  public class DecryptProcessor implements PropertyProcessor {
11  
12  	TextEncryptor encryptor;
13  
14  	public DecryptProcessor() {
15  		this(null);
16  	}
17  
18  	public DecryptProcessor(TextEncryptor encryptor) {
19  		super();
20  		this.encryptor = encryptor;
21  	}
22  
23  	@Override
24  	public void process(Properties properties) {
25  		Assert.notNull(encryptor, "encryptor is null");
26  		List<String> keys = PropertyUtils.getSortedKeys(properties);
27  		for (String key : keys) {
28  			String encryptedValue = properties.getProperty(key);
29  			String decryptedValue = encryptor.decrypt(encryptedValue);
30  			properties.setProperty(key, decryptedValue);
31  		}
32  	}
33  
34  	public TextEncryptor getEncryptor() {
35  		return encryptor;
36  	}
37  
38  	public void setEncryptor(TextEncryptor encryptor) {
39  		this.encryptor = encryptor;
40  	}
41  
42  }