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 EndsWithDecryptProcessor extends DecryptProcessor {
29
30 private static final Logger logger = LoggerFactory.getLogger(EndsWithDecryptProcessor.class);
31
32 String suffix = Constants.DEFAULT_ENCRYPTED_SUFFIX;
33 boolean removeEncryptedProperties = true;
34 Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
35
36 public EndsWithDecryptProcessor() {
37 this(null);
38 }
39
40 public EndsWithDecryptProcessor(TextEncryptor encryptor) {
41 super(encryptor);
42 }
43
44 @Override
45 public void process(Properties properties) {
46 List<String> keys = PropertyUtils.getEndsWithKeys(properties, suffix);
47 logger.info("Decrypting {} property values", keys.size());
48 for (String key : keys) {
49 logger.debug("Decrypting [{}]", key);
50 String encryptedValue = properties.getProperty(key);
51 String decryptedValue = encryptor.decrypt(encryptedValue);
52 int endIndex = key.length() - suffix.length();
53 String newKey = key.substring(0, endIndex);
54 PropertyUtils.addOrOverrideProperty(properties, newKey, decryptedValue, propertyOverwriteMode);
55 if (removeEncryptedProperties) {
56 logger.debug("Removing {}", key);
57 properties.remove(key);
58 }
59 }
60 }
61
62 public String getSuffix() {
63 return suffix;
64 }
65
66 public void setSuffix(String suffix) {
67 this.suffix = suffix;
68 }
69
70 public boolean isRemoveEncryptedProperties() {
71 return removeEncryptedProperties;
72 }
73
74 public void setRemoveEncryptedProperties(boolean removeEncryptedProperties) {
75 this.removeEncryptedProperties = removeEncryptedProperties;
76 }
77
78 public Mode getPropertyOverwriteMode() {
79 return propertyOverwriteMode;
80 }
81
82 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
83 this.propertyOverwriteMode = propertyOverwriteMode;
84 }
85
86 }