01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.kuali.rice.config;
18:
19: import java.util.HashMap;
20: import java.util.Iterator;
21: import java.util.Map;
22: import java.util.Properties;
23:
24: /**
25: * Logs information about the configuration at the DEBUG level.
26: *
27: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
28: */
29: public class ConfigLogger {
30:
31: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
32: .getLogger(ConfigLogger.class);
33:
34: /**
35: * List of keys to suppress the values for and the associated values to print instead.
36: */
37: private static final String[][] SECRET_KEYS = {
38: { "password", "Top Secret Password" },
39: { "encryption.key", "Top Secret Encryption Key" } };
40:
41: public static void logConfig(Config config) {
42: Map<String, String> safeConfig = getDisplaySafeConfig(config
43: .getProperties());
44: String props = "";
45: for (Iterator iter = safeConfig.entrySet().iterator(); iter
46: .hasNext();) {
47: Map.Entry property = (Map.Entry) iter.next();
48: String key = (String) property.getKey();
49: String value = (String) property.getValue();
50: props += key + "=[" + value + "],";
51: }
52: LOG.debug("Properties used " + props);
53: }
54:
55: /**
56: * Returns a Map of configuration paramters that have display-safe values. This allows for the suppression
57: * of sensitive configuration paramters from being displayed (i.e. passwords).
58: */
59: public static Map<String, String> getDisplaySafeConfig(
60: Properties properties) {
61: Map<String, String> parameters = new HashMap<String, String>();
62: for (Iterator iter = properties.entrySet().iterator(); iter
63: .hasNext();) {
64: Map.Entry property = (Map.Entry) iter.next();
65: String key = (String) property.getKey();
66: String value = (String) property.getValue();
67: String safeValue = value;
68: for (String[] secretKey : SECRET_KEYS) {
69: if (key.indexOf(secretKey[0]) > -1) {
70: safeValue = secretKey[1];
71: break;
72: }
73: }
74: parameters.put(key, safeValue);
75: }
76: return parameters;
77: }
78: }
|