001    /**
002     * Copyright 2010-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.common.util.property.processor;
017    
018    import java.util.List;
019    import java.util.Properties;
020    
021    import org.jasypt.util.text.TextEncryptor;
022    import org.kuali.common.util.PropertyUtils;
023    import org.springframework.util.Assert;
024    
025    public class DecryptProcessor implements PropertyProcessor {
026    
027            TextEncryptor encryptor;
028    
029            public DecryptProcessor() {
030                    this(null);
031            }
032    
033            public DecryptProcessor(TextEncryptor encryptor) {
034                    super();
035                    this.encryptor = encryptor;
036            }
037    
038            @Override
039            public void process(Properties properties) {
040                    Assert.notNull(encryptor, "encryptor is null");
041                    List<String> keys = PropertyUtils.getSortedKeys(properties);
042                    for (String key : keys) {
043                            String encryptedValue = properties.getProperty(key);
044                            String decryptedValue = encryptor.decrypt(encryptedValue);
045                            properties.setProperty(key, decryptedValue);
046                    }
047            }
048    
049            public TextEncryptor getEncryptor() {
050                    return encryptor;
051            }
052    
053            public void setEncryptor(TextEncryptor encryptor) {
054                    this.encryptor = encryptor;
055            }
056    
057    }