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.Properties;
19
20 import org.jasypt.util.text.TextEncryptor;
21 import org.kuali.common.util.PropertyUtils;
22 import org.kuali.common.util.enc.EncStrength;
23 import org.kuali.common.util.enc.EncUtils;
24
25
26
27
28 @Deprecated
29 public final class DecryptingProcessor implements PropertyProcessor {
30
31 public static final String DEFAULT_DECRYPT_KEY = "properties.decrypt";
32 public static final String DEFAULT_PASSWORD_KEY = "properties.enc.password";
33 public static final String DEFAULT_STRENGTH_KEY = "properties.enc.strength";
34
35 public DecryptingProcessor() {
36 this(DEFAULT_DECRYPT_KEY, DEFAULT_PASSWORD_KEY, DEFAULT_STRENGTH_KEY);
37 }
38
39 public DecryptingProcessor(String passwordKey) {
40 this(DEFAULT_DECRYPT_KEY, passwordKey, DEFAULT_STRENGTH_KEY);
41 }
42
43 public DecryptingProcessor(String decryptKey, String passwordKey, String strengthKey) {
44 this.decryptKey = decryptKey;
45 this.passwordKey = passwordKey;
46 this.strengthKey = strengthKey;
47 }
48
49 private final String decryptKey;
50 private final String passwordKey;
51 private final String strengthKey;
52
53 @Override
54 public void process(Properties properties) {
55 boolean decrypt = PropertyUtils.getBoolean(decryptKey, properties, false);
56 if (decrypt) {
57 TextEncryptor encryptor = getTextEncryptor(properties);
58 PropertyUtils.decrypt(properties, encryptor);
59 }
60 }
61
62 protected TextEncryptor getTextEncryptor(Properties properties) {
63
64 String password = PropertyUtils.getRequiredResolvedProperty(properties, passwordKey);
65
66
67 String strengthString = PropertyUtils.getRequiredResolvedProperty(properties, strengthKey, EncStrength.DEFAULT_VALUE.name());
68 EncStrength strength = EncStrength.valueOf(strengthString.toUpperCase());
69
70
71 return EncUtils.getTextEncryptor(password, strength);
72 }
73
74 public String getDecryptKey() {
75 return decryptKey;
76 }
77
78 public String getPasswordKey() {
79 return passwordKey;
80 }
81
82 public String getStrengthKey() {
83 return strengthKey;
84 }
85
86 }