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.exceptions.EncryptionOperationNotPossibleException; 022import org.jasypt.util.text.TextEncryptor; 023import org.kuali.common.util.Mode; 024import org.kuali.common.util.PropertyUtils; 025import org.kuali.common.util.property.Constants; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028 029/** 030 * @deprecated 031 */ 032@Deprecated 033public class EndsWithDecryptProcessor extends DecryptProcessor { 034 035 private static final Logger logger = LoggerFactory.getLogger(EndsWithDecryptProcessor.class); 036 037 String suffix = Constants.DEFAULT_ENCRYPTED_SUFFIX; 038 boolean removeEncryptedProperties = true; 039 Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE; 040 041 public EndsWithDecryptProcessor() { 042 this(null); 043 } 044 045 public EndsWithDecryptProcessor(TextEncryptor encryptor) { 046 super(encryptor); 047 } 048 049 @Override 050 public void process(Properties properties) { 051 List<String> keys = PropertyUtils.getEndsWithKeys(properties, suffix); 052 logger.info("Decrypting {} property values", keys.size()); 053 for (String key : keys) { 054 logger.debug("Decrypting [{}]", key); 055 String encryptedValue = properties.getProperty(key); 056 String decryptedValue = decrypt(key, encryptedValue, encryptor); 057 int endIndex = key.length() - suffix.length(); 058 String newKey = key.substring(0, endIndex); 059 PropertyUtils.addOrOverrideProperty(properties, newKey, decryptedValue, propertyOverwriteMode); 060 if (removeEncryptedProperties) { 061 logger.debug("Removing {}", key); 062 properties.remove(key); 063 } 064 } 065 } 066 067 protected String decrypt(String key, String encryptedValue, TextEncryptor encryptor) { 068 try { 069 return encryptor.decrypt(encryptedValue); 070 } catch (EncryptionOperationNotPossibleException e) { 071 throw new IllegalStateException("Unexpected error decrypting [" + key + "]=[" + encryptedValue + "]"); 072 } 073 } 074 075 public String getSuffix() { 076 return suffix; 077 } 078 079 public void setSuffix(String suffix) { 080 this.suffix = suffix; 081 } 082 083 public boolean isRemoveEncryptedProperties() { 084 return removeEncryptedProperties; 085 } 086 087 public void setRemoveEncryptedProperties(boolean removeEncryptedProperties) { 088 this.removeEncryptedProperties = removeEncryptedProperties; 089 } 090 091 public Mode getPropertyOverwriteMode() { 092 return propertyOverwriteMode; 093 } 094 095 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) { 096 this.propertyOverwriteMode = propertyOverwriteMode; 097 } 098 099}