View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @deprecated Use ContextDecryptingProcessor instead
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  		// If they asked to decrypt, a password is required
64  		String password = PropertyUtils.getRequiredResolvedProperty(properties, passwordKey);
65  
66  		// Strength is optional (defaults to BASIC)
67  		String strengthString = PropertyUtils.getRequiredResolvedProperty(properties, strengthKey, EncStrength.DEFAULT_VALUE.name());
68  		EncStrength strength = EncStrength.valueOf(strengthString.toUpperCase());
69  
70  		// Setup a TextEncryptor with the appropriate password and strength
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  }