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