001/**
002 * Copyright 2010-2014 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 */
016package org.kuali.common.util.property.processor;
017
018import java.util.List;
019import java.util.Properties;
020
021import org.jasypt.util.text.TextEncryptor;
022import org.kuali.common.util.PropertyUtils;
023
024public class EncryptProcessor implements PropertyProcessor {
025
026        TextEncryptor encryptor;
027
028        public EncryptProcessor() {
029                this(null);
030        }
031
032        public EncryptProcessor(TextEncryptor encryptor) {
033                super();
034                this.encryptor = encryptor;
035        }
036
037        @Override
038        public void process(Properties properties) {
039                List<String> keys = PropertyUtils.getSortedKeys(properties);
040                for (String key : keys) {
041                        String clearTextValue = properties.getProperty(key);
042                        String encryptedValue = encryptor.encrypt(clearTextValue);
043                        properties.setProperty(key, encryptedValue);
044                }
045        }
046
047        public TextEncryptor getEncryptor() {
048                return encryptor;
049        }
050
051        public void setEncryptor(TextEncryptor encryptor) {
052                this.encryptor = encryptor;
053        }
054
055}