View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   
8   package net.kwfgrid.gwes.servlet;
9   
10  import org.apache.log4j.Logger;
11  
12  import java.util.Properties;
13  import java.io.IOException;
14  
15  import net.kwfgrid.gwes.Constants;
16  
17  /**
18   * @author Andreas Hoheisel
19   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
20   * @version $Id: GWESProperties.java 1520 2011-02-28 16:44:35Z hoheisel $
21   */
22  public class GWESProperties extends Properties {
23  
24      final static Logger logger = Logger.getLogger(GWESProperties.class);
25  
26      private static GWESProperties _props;
27  
28      public String gwesBaseUrlInternal;
29      public String gwesBaseUrlExternal;
30      public String existUrl;
31      public String graphvizServiceUri;
32      public String gworkflowdlXsdPath;
33      public int width;
34      public int height;
35  
36      private GWESProperties(String fn) throws IOException {
37          super();
38          if (fn == null) fn = "/gwes.properties";
39          logger.debug("reading GWES properties from "+fn+ " ...");
40          load(getClass().getResourceAsStream(fn));
41          gwesBaseUrlInternal = getProperty(Constants.PROP_SYSTEM_GWES_SERVICE_BASE_URL_INTERNAL);
42          if (gwesBaseUrlInternal != null) System.setProperty(Constants.PROP_SYSTEM_GWES_SERVICE_BASE_URL_INTERNAL,gwesBaseUrlInternal);
43          gwesBaseUrlExternal = getProperty(Constants.PROP_SYSTEM_GWES_SERVICE_BASE_URL_EXTERNAL);
44          if (gwesBaseUrlExternal != null) System.setProperty(Constants.PROP_SYSTEM_GWES_SERVICE_BASE_URL_EXTERNAL,gwesBaseUrlExternal);
45          existUrl = getProperty(Constants.PROP_SYSTEM_WORKFLOW_REPOSITORY_URL);
46          if (existUrl != null) System.setProperty(Constants.PROP_SYSTEM_WORKFLOW_REPOSITORY_URL,existUrl);
47          graphvizServiceUri = getProperty(Constants.PROP_SYSTEM_GRAPHVIZ_SERVICE_URI);
48          gworkflowdlXsdPath = getProperty(Constants.PROP_SYSTEM_GWORKFLOWDL_XSD_PATH);
49          if (gworkflowdlXsdPath != null) System.setProperty(Constants.PROP_SYSTEM_GWORKFLOWDL_XSD_PATH,gworkflowdlXsdPath);
50          String geometry = getProperty(Constants.PROP_SYSTEM_GWUI_GEOMETRY);
51          int xIndex = geometry.indexOf("x");
52          width = Integer.parseInt(geometry.substring(0, xIndex));
53          height = Integer.parseInt(geometry.substring(xIndex + 1));
54      }
55  
56      public static GWESProperties getInstance(String fn) throws IOException {
57          if (_props == null) {
58              _props = new GWESProperties(fn);
59          }
60          return _props;
61      }
62  
63      public static Properties getPropertiesWithoutSecrets(String fn) throws IOException {
64          Properties propsSec = getInstance(fn);
65          Properties propsNonSec = new Properties();
66          for (Object keyObj : propsSec.keySet()) {
67              String key = (String) keyObj;
68              String value = (isSecret(key) ? "***" : propsSec.getProperty(key));
69              propsNonSec.put(key,value);
70          }
71          return propsNonSec;
72      }
73  
74      private static boolean isSecret(String propertyName) {
75          if (propertyName.contains("user")) return true;
76          if (propertyName.contains("passwd")) return true;
77          if (propertyName.contains("password")) return true;
78          if (propertyName.contains("Password")) return true;
79          if (propertyName.contains("login")) return true;
80          if (propertyName.contains("X509_USER_PROXY")) return true;
81          if (propertyName.contains("javax.net.ssl.")) return true;
82          return false;
83      }
84  
85  }