001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.verify;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.PropsKeys;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.kernel.util.SystemProperties;
023    import com.liferay.portal.kernel.util.UnicodeProperties;
024    import com.liferay.portal.security.ldap.LDAPSettingsUtil;
025    import com.liferay.portal.service.CompanyLocalServiceUtil;
026    import com.liferay.portal.util.PortalInstances;
027    import com.liferay.portal.util.PrefsPropsUtil;
028    import com.liferay.portal.util.PropsUtil;
029    import com.liferay.portlet.documentlibrary.store.StoreFactory;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class VerifyProperties extends VerifyProcess {
035    
036            @Override
037            protected void doVerify() throws Exception {
038    
039                    // system.properties
040    
041                    for (String[] keys : _MIGRATED_SYSTEM_KEYS) {
042                            String oldKey = keys[0];
043                            String newKey = keys[1];
044    
045                            verifyMigratedSystemProperty(oldKey, newKey);
046                    }
047    
048                    for (String[] keys : _RENAMED_SYSTEM_KEYS) {
049                            String oldKey = keys[0];
050                            String newKey = keys[1];
051    
052                            verifyRenamedSystemProperty(oldKey, newKey);
053                    }
054    
055                    for (String key : _OBSOLETE_SYSTEM_KEYS) {
056                            verifyObsoleteSystemProperty(key);
057                    }
058    
059                    // portal.properties
060    
061                    for (String[] keys : _MIGRATED_PORTAL_KEYS) {
062                            String oldKey = keys[0];
063                            String newKey = keys[1];
064    
065                            verifyMigratedPortalProperty(oldKey, newKey);
066                    }
067    
068                    for (String[] keys : _RENAMED_PORTAL_KEYS) {
069                            String oldKey = keys[0];
070                            String newKey = keys[1];
071    
072                            verifyRenamedPortalProperty(oldKey, newKey);
073                    }
074    
075                    for (String key : _OBSOLETE_PORTAL_KEYS) {
076                            verifyObsoletePortalProperty(key);
077                    }
078    
079                    // Document library
080    
081                    StoreFactory.checkProperties();
082    
083                    // LDAP
084    
085                    verifyLDAPProperties();
086            }
087    
088            protected void verifyLDAPProperties() throws Exception {
089                    long[] companyIds = PortalInstances.getCompanyIdsBySQL();
090    
091                    for (long companyId : companyIds) {
092                            UnicodeProperties properties = new UnicodeProperties();
093    
094                            long[] ldapServerIds = StringUtil.split(
095                                    PrefsPropsUtil.getString(companyId, "ldap.server.ids"), 0L);
096    
097                            for (long ldapServerId : ldapServerIds) {
098                                    String postfix = LDAPSettingsUtil.getPropertyPostfix(
099                                            ldapServerId);
100    
101                                    for (String key : _LDAP_KEYS) {
102                                            String value = PrefsPropsUtil.getString(
103                                                    companyId, key + postfix, null);
104    
105                                            if (value == null) {
106                                                    properties.put(key + postfix, StringPool.BLANK);
107                                            }
108                                    }
109                            }
110    
111                            if (!properties.isEmpty()) {
112                                    CompanyLocalServiceUtil.updatePreferences(
113                                            companyId, properties);
114                            }
115                    }
116            }
117    
118            protected void verifyMigratedPortalProperty(String oldKey, String newKey)
119                    throws Exception {
120    
121                    String value = PropsUtil.get(oldKey);
122    
123                    if (value != null) {
124                            _log.error(
125                                    "Portal property \"" + oldKey +
126                                            "\" was migrated to the system property \"" + newKey +
127                                                    "\"");
128                    }
129            }
130    
131            protected void verifyMigratedSystemProperty(String oldKey, String newKey)
132                    throws Exception {
133    
134                    String value = SystemProperties.get(oldKey);
135    
136                    if (value != null) {
137                            _log.error(
138                                    "System property \"" + oldKey +
139                                            "\" was migrated to the portal property \"" + newKey +
140                                                    "\"");
141                    }
142            }
143    
144            protected void verifyObsoletePortalProperty(String key) throws Exception {
145                    String value = PropsUtil.get(key);
146    
147                    if (value != null) {
148                            _log.error("Portal property \"" + key + "\" is obsolete");
149                    }
150            }
151    
152            protected void verifyObsoleteSystemProperty(String key) throws Exception {
153                    String value = SystemProperties.get(key);
154    
155                    if (value != null) {
156                            _log.error("System property \"" + key + "\" is obsolete");
157                    }
158            }
159    
160            protected void verifyRenamedPortalProperty(String oldKey, String newKey)
161                    throws Exception {
162    
163                    String value = PropsUtil.get(oldKey);
164    
165                    if (value != null) {
166                            _log.error(
167                                    "Portal property \"" + oldKey + "\" was renamed to \"" +
168                                            newKey + "\"");
169                    }
170            }
171    
172            protected void verifyRenamedSystemProperty(String oldKey, String newKey)
173                    throws Exception {
174    
175                    String value = SystemProperties.get(oldKey);
176    
177                    if (value != null) {
178                            _log.error(
179                                    "System property \"" + oldKey + "\" was renamed to \"" +
180                                            newKey + "\"");
181                    }
182            }
183    
184            private static final String[] _LDAP_KEYS = {
185                    PropsKeys.LDAP_CONTACT_CUSTOM_MAPPINGS, PropsKeys.LDAP_CONTACT_MAPPINGS,
186                    PropsKeys.LDAP_USER_CUSTOM_MAPPINGS
187            };
188    
189            private static final String[][] _MIGRATED_PORTAL_KEYS = new String[][] {
190                    new String[] {
191                            "finalize.manager.thread.enabled",
192                            "com.liferay.portal.kernel.memory.FinalizeManager.thread.enabled"
193                    }
194            };
195    
196            private static final String[][] _MIGRATED_SYSTEM_KEYS = new String[][] {
197                    new String[] {
198                            "com.liferay.filters.compression.CompressionFilter",
199                            "com.liferay.portal.servlet.filters.gzip.GZipFilter"
200                    },
201                    new String[] {
202                            "com.liferay.filters.doubleclick.DoubleClickFilter",
203                            "com.liferay.portal.servlet.filters.doubleclick.DoubleClickFilter"
204                    },
205                    new String[] {
206                            "com.liferay.filters.strip.StripFilter",
207                            "com.liferay.portal.servlet.filters.strip.StripFilter"
208                    },
209                    new String[] {
210                            "com.liferay.util.Http.max.connections.per.host",
211                            "com.liferay.portal.util.HttpImpl.max.connections.per.host"
212                    },
213                    new String[] {
214                            "com.liferay.util.Http.max.total.connections",
215                            "com.liferay.portal.util.HttpImpl.max.total.connections"
216                    },
217                    new String[] {
218                            "com.liferay.util.Http.proxy.auth.type",
219                            "com.liferay.portal.util.HttpImpl.proxy.auth.type"
220                    },
221                    new String[] {
222                            "com.liferay.util.Http.proxy.ntlm.domain",
223                            "com.liferay.portal.util.HttpImpl.proxy.ntlm.domain"
224                    },
225                    new String[] {
226                            "com.liferay.util.Http.proxy.ntlm.host",
227                            "com.liferay.portal.util.HttpImpl.proxy.ntlm.host"
228                    },
229                    new String[] {
230                            "com.liferay.util.Http.proxy.password",
231                            "com.liferay.portal.util.HttpImpl.proxy.password"
232                    },
233                    new String[] {
234                            "com.liferay.util.Http.proxy.username",
235                            "com.liferay.portal.util.HttpImpl.proxy.username"
236                    },
237                    new String[] {
238                            "com.liferay.util.Http.timeout",
239                            "com.liferay.portal.util.HttpImpl.timeout"
240                    },
241                    new String[] {
242                            "com.liferay.util.format.PhoneNumberFormat",
243                            "phone.number.format.impl"
244                    },
245                    new String[] {
246                            "com.liferay.util.servlet.UploadServletRequest.max.size",
247                            "com.liferay.portal.upload.UploadServletRequestImpl.max.size"
248                    },
249                    new String[] {
250                            "com.liferay.util.servlet.UploadServletRequest.temp.dir",
251                            "com.liferay.portal.upload.UploadServletRequestImpl.temp.dir"
252                    },
253                    new String[] {
254                            "com.liferay.util.servlet.fileupload.LiferayFileItem." +
255                                    "threshold.size",
256                            "com.liferay.portal.upload.LiferayFileItem.threshold.size"
257                    },
258                    new String[] {
259                            "com.liferay.util.servlet.fileupload.LiferayInputStream." +
260                                    "threshold.size",
261                            "com.liferay.portal.upload.LiferayInputStream.threshold.size"
262                    }
263            };
264    
265            private static final String[] _OBSOLETE_PORTAL_KEYS = new String[] {
266                    "asset.entry.increment.view.counter.enabled", "auth.max.failures.limit",
267                    "buffered.increment.parallel.queue.size",
268                    "buffered.increment.serial.queue.size", "cas.validate.url",
269                    "cluster.executor.heartbeat.interval", "commons.pool.enabled",
270                    "dl.file.entry.read.count.enabled",
271                    "dynamic.data.lists.template.language.parser[ftl]",
272                    "dynamic.data.lists.template.language.parser[vm]",
273                    "dynamic.data.lists.template.language.parser[xsl]",
274                    "dynamic.data.mapping.template.language.types", "jbi.workflow.url",
275                    "journal.template.language.parser[css]",
276                    "journal.template.language.parser[ftl]",
277                    "journal.template.language.parser[vm]",
278                    "journal.template.language.parser[xsl]",
279                    "journal.template.language.types", "lucene.analyzer",
280                    "lucene.store.jdbc.auto.clean.up",
281                    "lucene.store.jdbc.auto.clean.up.enabled",
282                    "lucene.store.jdbc.auto.clean.up.interval",
283                    "lucene.store.jdbc.dialect.db2", "lucene.store.jdbc.dialect.derby",
284                    "lucene.store.jdbc.dialect.hsqldb", "lucene.store.jdbc.dialect.jtds",
285                    "lucene.store.jdbc.dialect.microsoft",
286                    "lucene.store.jdbc.dialect.mysql", "lucene.store.jdbc.dialect.oracle",
287                    "lucene.store.jdbc.dialect.postgresql",
288                    "message.boards.thread.locking.enabled",
289                    "portal.security.manager.enable", "scheduler.classes",
290                    "shard.available.names", "velocity.engine.resource.manager",
291                    "velocity.engine.resource.manager.cache.enabled",
292                    "webdav.storage.class", "webdav.storage.show.edit.url",
293                    "webdav.storage.show.view.url", "webdav.storage.tokens", "xss.allow"
294            };
295    
296            private static final String[] _OBSOLETE_SYSTEM_KEYS = new String[] {
297                    "com.liferay.util.Http.proxy.host", "com.liferay.util.Http.proxy.port",
298                    "com.liferay.util.XSSUtil.regexp.pattern"
299            };
300    
301            private static final String[][] _RENAMED_PORTAL_KEYS = new String[][] {
302                    new String[] {
303                            "amazon.license.0", "amazon.access.key.id"
304                    },
305                    new String[] {
306                            "amazon.license.1", "amazon.access.key.id"
307                    },
308                    new String[] {
309                            "amazon.license.2", "amazon.access.key.id"
310                    },
311                    new String[] {
312                            "amazon.license.3", "amazon.access.key.id"
313                    },
314                    new String[] {
315                            "cdn.host", "cdn.host.http"
316                    },
317                    new String[] {
318                            "com.liferay.portal.servlet.filters.compression.CompressionFilter",
319                            "com.liferay.portal.servlet.filters.gzip.GZipFilter"
320                    },
321                    new String[] {
322                            "default.guest.friendly.url",
323                            "default.guest.public.layout.friendly.url"
324                    },
325                    new String[] {
326                            "default.guest.layout.column", "default.guest.public.layout.column"
327                    },
328                    new String[] {
329                            "default.guest.layout.name", "default.guest.public.layout.name"
330                    },
331                    new String[] {
332                            "default.guest.layout.template.id",
333                            "default.guest.public.layout.template.id"
334                    },
335                    new String[] {
336                            "default.user.layout.column", "default.user.public.layout.column"
337                    },
338                    new String[] {
339                            "default.user.layout.name", "default.user.public.layout.name"
340                    },
341                    new String[] {
342                            "default.user.layout.template.id",
343                            "default.user.public.layout.template.id"
344                    },
345                    new String[] {
346                            "default.user.private.layout.lar",
347                            "default.user.private.layouts.lar"
348                    },
349                    new String[] {
350                            "default.user.public.layout.lar", "default.user.public.layouts.lar"
351                    },
352                    new String[] {
353                            "dl.hook.cmis.credentials.password",
354                            "dl.store.cmis.credentials.password"
355                    },
356                    new String[] {
357                            "dl.hook.cmis.credentials.username",
358                            "dl.store.cmis.credentials.username"
359                    },
360                    new String[] {
361                            "dl.hook.cmis.repository.url", "dl.store.cmis.repository.url"
362                    },
363                    new String[] {
364                            "dl.hook.cmis.system.root.dir", "dl.store.cmis.system.root.dir"
365                    },
366                    new String[] {
367                            "dl.hook.file.system.root.dir", "dl.store.file.system.root.dir"
368                    },
369                    new String[] {
370                            "dl.hook.impl", "dl.store.impl"
371                    },
372                    new String[] {
373                            "dl.hook.jcr.fetch.delay", "dl.store.jcr.fetch.delay"
374                    },
375                    new String[] {
376                            "dl.hook.jcr.fetch.max.failures", "dl.store.jcr.fetch.max.failures"
377                    },
378                    new String[] {
379                            "dl.hook.jcr.move.version.labels",
380                            "dl.store.jcr.move.version.labels"
381                    },
382                    new String[] {
383                            "dl.hook.s3.access.key", "dl.store.s3.access.key"
384                    },
385                    new String[] {
386                            "dl.hook.s3.bucket.name", "dl.store.s3.bucket.name"
387                    },
388                    new String[] {
389                            "dl.hook.s3.secret.key", "dl.store.s3.secret.key"
390                    },
391                    new String[] {
392                            "editor.wysiwyg.portal-web.docroot.html.portlet.calendar." +
393                                    "edit_configuration.jsp",
394                            "editor.wysiwyg.portal-web.docroot.html.portlet.calendar." +
395                                    "configuration.jsp"
396                    },
397                    new String[] {
398                            "editor.wysiwyg.portal-web.docroot.html.portlet.invitation." +
399                                    "edit_configuration.jsp",
400                            "editor.wysiwyg.portal-web.docroot.html.portlet.invitation." +
401                                    "configuration.jsp"
402                    },
403                    new String[] {
404                            "editor.wysiwyg.portal-web.docroot.html.portlet.journal." +
405                                    "edit_configuration.jsp",
406                            "editor.wysiwyg.portal-web.docroot.html.portlet.journal." +
407                                    "configuration.jsp"
408                    },
409                    new String[] {
410                            "editor.wysiwyg.portal-web.docroot.html.portlet.message_boards." +
411                                    "edit_configuration.jsp",
412                            "editor.wysiwyg.portal-web.docroot.html.portlet.message_boards." +
413                                    "configuration.jsp"
414                    },
415                    new String[] {
416                            "editor.wysiwyg.portal-web.docroot.html.portlet.shopping." +
417                                    "edit_configuration.jsp",
418                            "editor.wysiwyg.portal-web.docroot.html.portlet.shopping." +
419                                    "configuration.jsp"
420                    },
421                    new String[] {
422                            "journal.error.template.freemarker", "journal.error.template[ftl]"
423                    },
424                    new String[] {
425                            "journal.error.template.velocity", "journal.error.template[vm]"
426                    },
427                    new String[] {
428                            "journal.error.template.xsl", "journal.error.template[xsl]"
429                    },
430                    new String[] {
431                            "referer.url.domains.allowed", "redirect.url.domains.allowed"
432                    },
433                    new String[] {
434                            "referer.url.ips.allowed", "redirect.url.ips.allowed"
435                    },
436                    new String[] {
437                            "referer.url.security.mode", "redirect.url.security.mode"
438                    },
439                    new String[] {
440                            "tags.asset.increment.view.counter.enabled",
441                            "asset.entry.increment.view.counter.enabled"
442                    }
443            };
444    
445            private static final String[][] _RENAMED_SYSTEM_KEYS = new String[][] {
446                    new String[] {
447                            "com.liferay.portal.kernel.util.StringBundler.unsafe.create." +
448                                    "threshold",
449                            "com.liferay.portal.kernel.util.StringBundler.threadlocal.buffer." +
450                                    "limit",
451                    }
452            };
453    
454            private static Log _log = LogFactoryUtil.getLog(VerifyProperties.class);
455    
456    }