1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.property.processor;
17
18 import java.util.List;
19 import java.util.Properties;
20
21 import org.jasypt.util.text.TextEncryptor;
22 import org.kuali.common.util.Mode;
23 import org.kuali.common.util.PropertyUtils;
24 import org.kuali.common.util.property.Constants;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class EndsWithEncryptProcessor extends DecryptProcessor {
29
30 private static final Logger logger = LoggerFactory.getLogger(EndsWithEncryptProcessor.class);
31
32 String suffix = Constants.DEFAULT_ENCRYPTED_SUFFIX;
33 boolean removeUnencryptedProperties = true;
34 Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
35
36 public EndsWithEncryptProcessor() {
37 this(null);
38 }
39
40 public EndsWithEncryptProcessor(TextEncryptor encryptor) {
41 super(encryptor);
42 }
43
44 @Override
45 public void process(Properties properties) {
46 List<String> keys = PropertyUtils.getSortedKeys(properties);
47 for (String key : keys) {
48 String decryptedValue = properties.getProperty(key);
49 String encryptedValue = encryptor.encrypt(decryptedValue);
50 String newKey = key + suffix;
51 PropertyUtils.addOrOverrideProperty(properties, newKey, encryptedValue, propertyOverwriteMode);
52 if (removeUnencryptedProperties) {
53 logger.debug("Removing {}", key);
54 properties.remove(key);
55 }
56 }
57 }
58
59 public String getSuffix() {
60 return suffix;
61 }
62
63 public void setSuffix(String suffix) {
64 this.suffix = suffix;
65 }
66
67 public boolean isRemoveUnencryptedProperties() {
68 return removeUnencryptedProperties;
69 }
70
71 public void setRemoveUnencryptedProperties(boolean removeUnencryptedProperties) {
72 this.removeUnencryptedProperties = removeUnencryptedProperties;
73 }
74
75 public Mode getPropertyOverwriteMode() {
76 return propertyOverwriteMode;
77 }
78
79 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
80 this.propertyOverwriteMode = propertyOverwriteMode;
81 }
82
83 }