Coverage Report - org.kuali.rice.core.impl.config.property.ConfigLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigLogger
0%
0/30
0%
0/10
2.667
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.rice.core.impl.config.property;
 17  
 
 18  
 import org.kuali.rice.core.api.config.property.Config;
 19  
 
 20  
 import java.util.Arrays;
 21  
 import java.util.HashMap;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 /**
 27  
  * Logs information about the configuration at the DEBUG level.
 28  
  *
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class ConfigLogger {
 32  
 
 33  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ConfigLogger.class);
 34  
 
 35  
         /**
 36  
          * List of keys to suppress the values for and the associated values to print instead.
 37  
          */
 38  0
         private static final String[][] SECRET_KEYS = 
 39  
         { 
 40  
                 {"password", "Top Secret Password"}, 
 41  
                 {"encryption.key", "Top Secret Encryption Key"}
 42  
         };
 43  
         
 44  
         /**
 45  
          * These are a list of keys that we know we can display regardless of whether they
 46  
          * are considered "secret"
 47  
          */
 48  0
         private static final String[] PUBLIC_KEYS = 
 49  
         { 
 50  
                 "cas.validate.password"
 51  
                 
 52  
         };
 53  
          
 54  
         
 55  
         public static void logConfig(Config config) {
 56  0
                 Map<String, String> safeConfig = getDisplaySafeConfig(config.getProperties());
 57  0
                 String props = "";
 58  0
                 for (Iterator iter = safeConfig.entrySet().iterator(); iter.hasNext();) {
 59  0
                         Map.Entry property = (Map.Entry) iter.next();
 60  0
                         String key = (String) property.getKey();
 61  0
                         String value = (String) property.getValue();
 62  0
                         props += key + "=[" + value + "],";
 63  0
                 }
 64  0
                 LOG.debug("Properties used " + props);
 65  0
         }
 66  
         
 67  
         /**
 68  
          * Returns a value for a parameter that is safe for displaying on screen or in a log file.
 69  
          * @param name the name of the parameter
 70  
          * @param value the parameter value
 71  
          * @return the parameter value if the parameter is non-secret, or a replacement if the parameter is secret
 72  
          */
 73  
         public static String getDisplaySafeValue(String name, String value) {
 74  0
             String safeValue = value;
 75  
             
 76  0
             List<String> l = Arrays.asList(PUBLIC_KEYS);
 77  
             
 78  0
         for (String[] secretKey : SECRET_KEYS) {
 79  0
             if (name.contains(secretKey[0]) && !l.contains(name)) {
 80  0
                 safeValue = secretKey[1];
 81  0
                 break;
 82  
             }   
 83  
         }
 84  0
         return safeValue;
 85  
         }
 86  
 
 87  
         /**
 88  
          * Returns a Map of configuration paramters that have display-safe values.  This allows for the suppression
 89  
          * of sensitive configuration paramters from being displayed (i.e. passwords).
 90  
          */
 91  
         public static Map<String, String> getDisplaySafeConfig(Map properties) {
 92  0
                 Map<String, String> parameters = new HashMap<String, String>();
 93  0
                 for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
 94  0
                         Map.Entry property = (Map.Entry) iter.next();
 95  0
                         String key = (String) property.getKey();
 96  0
                         String value = (String) property.getValue();
 97  0
                         String safeValue = getDisplaySafeValue(key, value);
 98  0
                         parameters.put(key, safeValue);
 99  0
                 }
 100  0
                 return parameters;
 101  
         }
 102  
 }