1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.verify;
24  
25  import com.liferay.portal.util.PropsUtil;
26  import com.liferay.util.SystemProperties;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  /**
32   * <a href="VerifyProperties.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class VerifyProperties extends VerifyProcess {
38  
39      public void verify() throws VerifyException {
40          _log.info("Verifying");
41  
42          try {
43              verifyProperties();
44          }
45          catch (Exception e) {
46              throw new VerifyException(e);
47          }
48      }
49  
50      protected void verifyProperties() throws Exception {
51  
52          // system.properties
53  
54          for (String[] keys : _MIGRATED_SYSTEM_KEYS) {
55              String oldKey = keys[0];
56              String newKey = keys[1];
57  
58              verifyMigratedSystemProperty(oldKey, newKey);
59          }
60  
61          for (String[] keys : _RENAMED_SYSTEM_KEYS) {
62              String oldKey = keys[0];
63              String newKey = keys[1];
64  
65              verifyRenamedSystemProperty(oldKey, newKey);
66          }
67  
68          for (String key : _OBSOLETE_SYSTEM_KEYS) {
69              verifyObsoleteSystemProperty(key);
70          }
71  
72          // portal.properties
73  
74          for (String[] keys : _RENAMED_PORTAL_KEYS) {
75              String oldKey = keys[0];
76              String newKey = keys[1];
77  
78              verifyRenamedPortalProperty(oldKey, newKey);
79          }
80  
81          for (String key : _OBSOLETE_PORTAL_KEYS) {
82              verifyObsoletePortalProperty(key);
83          }
84      }
85  
86      protected void verifyMigratedSystemProperty(String oldKey, String newKey)
87          throws Exception {
88  
89          String value = SystemProperties.get(oldKey);
90  
91          if (value != null) {
92              _log.error(
93                  "System property \"" + oldKey +
94                      "\" was migrated to the portal property \"" + newKey +
95                          "\"");
96          }
97      }
98  
99      protected void verifyRenamedPortalProperty(String oldKey, String newKey)
100         throws Exception {
101 
102         String value = PropsUtil.get(oldKey);
103 
104         if (value != null) {
105             _log.error(
106                 "Portal property \"" + oldKey + "\" was renamed to \"" +
107                     newKey + "\"");
108         }
109     }
110 
111     protected void verifyRenamedSystemProperty(String oldKey, String newKey)
112         throws Exception {
113 
114         String value = SystemProperties.get(oldKey);
115 
116         if (value != null) {
117             _log.error(
118                 "System property \"" + oldKey + "\" was renamed to \"" +
119                     newKey + "\"");
120         }
121     }
122 
123     protected void verifyObsoletePortalProperty(String key) throws Exception {
124         String value = PropsUtil.get(key);
125 
126         if (value != null) {
127             _log.error("Portal property \"" + key + "\" is obsolete");
128         }
129     }
130 
131     protected void verifyObsoleteSystemProperty(String key) throws Exception {
132         String value = SystemProperties.get(key);
133 
134         if (value != null) {
135             _log.error("System property \"" + key + "\" is obsolete");
136         }
137     }
138 
139     private static final String[][] _MIGRATED_SYSTEM_KEYS = new String[][] {
140         new String[] {
141             "com.liferay.filters.compression.CompressionFilter",
142             "com.liferay.portal.servlet.filters.compression.CompressionFilter"
143         },
144         new String[] {
145             "com.liferay.filters.doubleclick.DoubleClickFilter",
146             "com.liferay.portal.servlet.filters.doubleclick.DoubleClickFilter"
147         },
148         new String[] {
149             "com.liferay.filters.strip.StripFilter",
150             "com.liferay.portal.servlet.filters.strip.StripFilter"
151         },
152         new String[] {
153             "com.liferay.util.Http.max.connections.per.host",
154             "com.liferay.portal.util.HttpImpl.max.connections.per.host"
155         },
156         new String[] {
157             "com.liferay.util.Http.max.total.connections",
158             "com.liferay.portal.util.HttpImpl.max.total.connections"
159         },
160         new String[] {
161             "com.liferay.util.Http.proxy.auth.type",
162             "com.liferay.portal.util.HttpImpl.proxy.auth.type"
163         },
164         new String[] {
165             "com.liferay.util.Http.proxy.ntlm.domain",
166             "com.liferay.portal.util.HttpImpl.proxy.ntlm.domain"
167         },
168         new String[] {
169             "com.liferay.util.Http.proxy.ntlm.host",
170             "com.liferay.portal.util.HttpImpl.proxy.ntlm.host"
171         },
172         new String[] {
173             "com.liferay.util.Http.proxy.password",
174             "com.liferay.portal.util.HttpImpl.proxy.password"
175         },
176         new String[] {
177             "com.liferay.util.Http.proxy.username",
178             "com.liferay.portal.util.HttpImpl.proxy.username"
179         },
180         new String[] {
181             "com.liferay.util.Http.timeout",
182             "com.liferay.portal.util.HttpImpl.timeout"
183         },
184         new String[] {
185             "com.liferay.util.servlet.UploadServletRequest.max.size",
186             "com.liferay.portal.upload.UploadServletRequestImpl.max.size"
187         },
188         new String[] {
189             "com.liferay.util.servlet.UploadServletRequest.temp.dir",
190             "com.liferay.portal.upload.UploadServletRequestImpl.temp.dir"
191         },
192         new String[] {
193             "com.liferay.util.servlet.fileupload.LiferayFileItem." +
194                 "threshold.size",
195             "com.liferay.portal.upload.LiferayFileItem.threshold.size"
196         },
197         new String[] {
198             "com.liferay.util.servlet.fileupload.LiferayInputStream." +
199                 "threshold.size",
200             "com.liferay.portal.upload.LiferayInputStream.threshold.size"
201         }
202     };
203 
204     private static final String[] _OBSOLETE_PORTAL_KEYS = new String[] {
205         "auth.simultaneous.logins",
206         "xss.allow"
207     };
208 
209     private static final String[] _OBSOLETE_SYSTEM_KEYS = new String[] {
210         "com.liferay.util.Http.proxy.host",
211         "com.liferay.util.Http.proxy.port",
212         "com.liferay.util.XSSUtil.regexp.pattern"
213     };
214 
215     private static final String[][] _RENAMED_PORTAL_KEYS = new String[][] {
216         new String[] {
217             "amazon.license.0",
218             "amazon.access.key.id"
219         },
220         new String[] {
221             "amazon.license.1",
222             "amazon.access.key.id"
223         },
224         new String[] {
225             "amazon.license.2",
226             "amazon.access.key.id"
227         },
228         new String[] {
229             "amazon.license.3",
230             "amazon.access.key.id"
231         },
232         new String[] {
233             "default.guest.friendly.url",
234             "default.guest.public.layout.friendly.url"
235         },
236         new String[] {
237             "default.guest.layout.column",
238             "default.guest.public.layout.column"
239         },
240         new String[] {
241             "default.guest.layout.name",
242             "default.guest.public.layout.name"
243         },
244         new String[] {
245             "default.guest.layout.template.id",
246             "default.guest.public.layout.template.id"
247         },
248         new String[] {
249             "default.user.layout.column",
250             "default.user.public.layout.column"
251         },
252         new String[] {
253             "default.user.layout.name",
254             "default.user.public.layout.name"
255         },
256         new String[] {
257             "default.user.layout.template.id",
258             "default.user.public.layout.template.id"
259         },
260         new String[] {
261             "default.user.private.layout.lar",
262             "default.user.private.layouts.lar"
263         },
264         new String[] {
265             "default.user.public.layout.lar",
266             "default.user.public.layouts.lar"
267         }
268     };
269 
270     private static final String[][] _RENAMED_SYSTEM_KEYS = new String[][] {
271     };
272 
273     private static Log _log = LogFactory.getLog(VerifyProperties.class);
274 
275 }