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.Mode;
023import org.kuali.common.util.PropertyUtils;
024import org.kuali.common.util.property.Constants;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027
028/**
029 * @deprecated
030 */
031@Deprecated
032public class EndsWithEncryptProcessor extends DecryptProcessor {
033
034        private static final Logger logger = LoggerFactory.getLogger(EndsWithEncryptProcessor.class);
035
036        String suffix = Constants.DEFAULT_ENCRYPTED_SUFFIX;
037        boolean removeUnencryptedProperties = true;
038        Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
039
040        public EndsWithEncryptProcessor() {
041                this(null);
042        }
043
044        public EndsWithEncryptProcessor(TextEncryptor encryptor) {
045                super(encryptor);
046        }
047
048        @Override
049        public void process(Properties properties) {
050                List<String> keys = PropertyUtils.getSortedKeys(properties);
051                for (String key : keys) {
052                        String decryptedValue = properties.getProperty(key);
053                        String encryptedValue = encryptor.encrypt(decryptedValue);
054                        String newKey = key + suffix;
055                        PropertyUtils.addOrOverrideProperty(properties, newKey, encryptedValue, propertyOverwriteMode);
056                        if (removeUnencryptedProperties) {
057                                logger.debug("Removing {}", key);
058                                properties.remove(key);
059                        }
060                }
061        }
062
063        public String getSuffix() {
064                return suffix;
065        }
066
067        public void setSuffix(String suffix) {
068                this.suffix = suffix;
069        }
070
071        public boolean isRemoveUnencryptedProperties() {
072                return removeUnencryptedProperties;
073        }
074
075        public void setRemoveUnencryptedProperties(boolean removeUnencryptedProperties) {
076                this.removeUnencryptedProperties = removeUnencryptedProperties;
077        }
078
079        public Mode getPropertyOverwriteMode() {
080                return propertyOverwriteMode;
081        }
082
083        public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
084                this.propertyOverwriteMode = propertyOverwriteMode;
085        }
086
087}