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.strip.StripFilter",
203                            "com.liferay.portal.servlet.filters.strip.StripFilter"
204                    },
205                    new String[] {
206                            "com.liferay.util.Http.max.connections.per.host",
207                            "com.liferay.portal.util.HttpImpl.max.connections.per.host"
208                    },
209                    new String[] {
210                            "com.liferay.util.Http.max.total.connections",
211                            "com.liferay.portal.util.HttpImpl.max.total.connections"
212                    },
213                    new String[] {
214                            "com.liferay.util.Http.proxy.auth.type",
215                            "com.liferay.portal.util.HttpImpl.proxy.auth.type"
216                    },
217                    new String[] {
218                            "com.liferay.util.Http.proxy.ntlm.domain",
219                            "com.liferay.portal.util.HttpImpl.proxy.ntlm.domain"
220                    },
221                    new String[] {
222                            "com.liferay.util.Http.proxy.ntlm.host",
223                            "com.liferay.portal.util.HttpImpl.proxy.ntlm.host"
224                    },
225                    new String[] {
226                            "com.liferay.util.Http.proxy.password",
227                            "com.liferay.portal.util.HttpImpl.proxy.password"
228                    },
229                    new String[] {
230                            "com.liferay.util.Http.proxy.username",
231                            "com.liferay.portal.util.HttpImpl.proxy.username"
232                    },
233                    new String[] {
234                            "com.liferay.util.Http.timeout",
235                            "com.liferay.portal.util.HttpImpl.timeout"
236                    },
237                    new String[] {
238                            "com.liferay.util.format.PhoneNumberFormat",
239                            "phone.number.format.impl"
240                    },
241                    new String[] {
242                            "com.liferay.util.servlet.UploadServletRequest.max.size",
243                            "com.liferay.portal.upload.UploadServletRequestImpl.max.size"
244                    },
245                    new String[] {
246                            "com.liferay.util.servlet.UploadServletRequest.temp.dir",
247                            "com.liferay.portal.upload.UploadServletRequestImpl.temp.dir"
248                    },
249                    new String[] {
250                            "com.liferay.util.servlet.fileupload.LiferayFileItem." +
251                                    "threshold.size",
252                            "com.liferay.portal.upload.LiferayFileItem.threshold.size"
253                    },
254                    new String[] {
255                            "com.liferay.util.servlet.fileupload.LiferayInputStream." +
256                                    "threshold.size",
257                            "com.liferay.portal.upload.LiferayInputStream.threshold.size"
258                    }
259            };
260    
261            private static final String[] _OBSOLETE_PORTAL_KEYS = new String[] {
262                    "asset.entry.increment.view.counter.enabled", "auth.max.failures.limit",
263                    "buffered.increment.parallel.queue.size",
264                    "buffered.increment.serial.queue.size", "cas.validate.url",
265                    "cluster.executor.heartbeat.interval",
266                    "com.liferay.filters.doubleclick.DoubleClickFilter",
267                    "com.liferay.portal.servlet.filters.doubleclick.DoubleClickFilter",
268                    "commons.pool.enabled", "dl.file.entry.read.count.enabled",
269                    "dynamic.data.lists.template.language.parser[ftl]",
270                    "dynamic.data.lists.template.language.parser[vm]",
271                    "dynamic.data.lists.template.language.parser[xsl]",
272                    "dynamic.data.mapping.template.language.types",
273                    "ehcache.statistics.enabled", "jbi.workflow.url",
274                    "journal.template.language.parser[css]",
275                    "journal.template.language.parser[ftl]",
276                    "journal.template.language.parser[vm]",
277                    "journal.template.language.parser[xsl]",
278                    "journal.template.language.types", "lucene.analyzer",
279                    "lucene.store.jdbc.auto.clean.up",
280                    "lucene.store.jdbc.auto.clean.up.enabled",
281                    "lucene.store.jdbc.auto.clean.up.interval",
282                    "lucene.store.jdbc.dialect.db2", "lucene.store.jdbc.dialect.derby",
283                    "lucene.store.jdbc.dialect.hsqldb", "lucene.store.jdbc.dialect.jtds",
284                    "lucene.store.jdbc.dialect.microsoft",
285                    "lucene.store.jdbc.dialect.mysql", "lucene.store.jdbc.dialect.oracle",
286                    "lucene.store.jdbc.dialect.postgresql",
287                    "memory.cluster.scheduler.lock.cache.enabled",
288                    "message.boards.thread.locking.enabled", "portal.ctx",
289                    "portal.security.manager.enable", "permissions.user.check.algorithm",
290                    "scheduler.classes", "schema.run.minimal", "shard.available.names",
291                    "velocity.engine.resource.manager",
292                    "velocity.engine.resource.manager.cache.enabled",
293                    "webdav.storage.class", "webdav.storage.show.edit.url",
294                    "webdav.storage.show.view.url", "webdav.storage.tokens", "xss.allow"
295            };
296    
297            private static final String[] _OBSOLETE_SYSTEM_KEYS = new String[] {
298                    "com.liferay.util.Http.proxy.host", "com.liferay.util.Http.proxy.port",
299                    "com.liferay.util.XSSUtil.regexp.pattern"
300            };
301    
302            private static final String[][] _RENAMED_PORTAL_KEYS = new String[][] {
303                    new String[] {
304                            "amazon.license.0", "amazon.access.key.id"
305                    },
306                    new String[] {
307                            "amazon.license.1", "amazon.access.key.id"
308                    },
309                    new String[] {
310                            "amazon.license.2", "amazon.access.key.id"
311                    },
312                    new String[] {
313                            "amazon.license.3", "amazon.access.key.id"
314                    },
315                    new String[] {
316                            "cdn.host", "cdn.host.http"
317                    },
318                    new String[] {
319                            "com.liferay.portal.servlet.filters.compression.CompressionFilter",
320                            "com.liferay.portal.servlet.filters.gzip.GZipFilter"
321                    },
322                    new String[] {
323                            "default.guest.friendly.url",
324                            "default.guest.public.layout.friendly.url"
325                    },
326                    new String[] {
327                            "default.guest.layout.column", "default.guest.public.layout.column"
328                    },
329                    new String[] {
330                            "default.guest.layout.name", "default.guest.public.layout.name"
331                    },
332                    new String[] {
333                            "default.guest.layout.template.id",
334                            "default.guest.public.layout.template.id"
335                    },
336                    new String[] {
337                            "default.user.layout.column", "default.user.public.layout.column"
338                    },
339                    new String[] {
340                            "default.user.layout.name", "default.user.public.layout.name"
341                    },
342                    new String[] {
343                            "default.user.layout.template.id",
344                            "default.user.public.layout.template.id"
345                    },
346                    new String[] {
347                            "default.user.private.layout.lar",
348                            "default.user.private.layouts.lar"
349                    },
350                    new String[] {
351                            "default.user.public.layout.lar", "default.user.public.layouts.lar"
352                    },
353                    new String[] {
354                            "dl.hook.cmis.credentials.password",
355                            "dl.store.cmis.credentials.password"
356                    },
357                    new String[] {
358                            "dl.hook.cmis.credentials.username",
359                            "dl.store.cmis.credentials.username"
360                    },
361                    new String[] {
362                            "dl.hook.cmis.repository.url", "dl.store.cmis.repository.url"
363                    },
364                    new String[] {
365                            "dl.hook.cmis.system.root.dir", "dl.store.cmis.system.root.dir"
366                    },
367                    new String[] {
368                            "dl.hook.file.system.root.dir", "dl.store.file.system.root.dir"
369                    },
370                    new String[] {
371                            "dl.hook.impl", "dl.store.impl"
372                    },
373                    new String[] {
374                            "dl.hook.jcr.fetch.delay", "dl.store.jcr.fetch.delay"
375                    },
376                    new String[] {
377                            "dl.hook.jcr.fetch.max.failures", "dl.store.jcr.fetch.max.failures"
378                    },
379                    new String[] {
380                            "dl.hook.jcr.move.version.labels",
381                            "dl.store.jcr.move.version.labels"
382                    },
383                    new String[] {
384                            "dl.hook.s3.access.key", "dl.store.s3.access.key"
385                    },
386                    new String[] {
387                            "dl.hook.s3.bucket.name", "dl.store.s3.bucket.name"
388                    },
389                    new String[] {
390                            "dl.hook.s3.secret.key", "dl.store.s3.secret.key"
391                    },
392                    new String[] {
393                            "editor.wysiwyg.portal-web.docroot.html.portlet.calendar." +
394                                    "edit_configuration.jsp",
395                            "editor.wysiwyg.portal-web.docroot.html.portlet.calendar." +
396                                    "configuration.jsp"
397                    },
398                    new String[] {
399                            "editor.wysiwyg.portal-web.docroot.html.portlet.invitation." +
400                                    "edit_configuration.jsp",
401                            "editor.wysiwyg.portal-web.docroot.html.portlet.invitation." +
402                                    "configuration.jsp"
403                    },
404                    new String[] {
405                            "editor.wysiwyg.portal-web.docroot.html.portlet.journal." +
406                                    "edit_configuration.jsp",
407                            "editor.wysiwyg.portal-web.docroot.html.portlet.journal." +
408                                    "configuration.jsp"
409                    },
410                    new String[] {
411                            "editor.wysiwyg.portal-web.docroot.html.portlet.message_boards." +
412                                    "edit_configuration.jsp",
413                            "editor.wysiwyg.portal-web.docroot.html.portlet.message_boards." +
414                                    "configuration.jsp"
415                    },
416                    new String[] {
417                            "editor.wysiwyg.portal-web.docroot.html.portlet.shopping." +
418                                    "edit_configuration.jsp",
419                            "editor.wysiwyg.portal-web.docroot.html.portlet.shopping." +
420                                    "configuration.jsp"
421                    },
422                    new String[] {
423                            "field.editable.com.liferay.portal.model.User.emailAddress",
424                            "field.editable.user.types"
425                    },
426                    new String[] {
427                            "field.editable.com.liferay.portal.model.User.screenName",
428                            "field.editable.user.types"
429                    },
430                    new String[] {
431                            "journal.error.template.freemarker", "journal.error.template[ftl]"
432                    },
433                    new String[] {
434                            "journal.error.template.velocity", "journal.error.template[vm]"
435                    },
436                    new String[] {
437                            "journal.error.template.xsl", "journal.error.template[xsl]"
438                    },
439                    new String[] {
440                            "journal.template.freemarker.restricted.variables",
441                            "freemarker.engine.restricted.variables"
442                    },
443                    new String[] {
444                            "journal.template.velocity.restricted.variables",
445                            "velocity.engine.restricted.variables"
446                    },
447                    new String[] {
448                            "referer.url.domains.allowed", "redirect.url.domains.allowed"
449                    },
450                    new String[] {
451                            "referer.url.ips.allowed", "redirect.url.ips.allowed"
452                    },
453                    new String[] {
454                            "referer.url.security.mode", "redirect.url.security.mode"
455                    },
456                    new String[] {
457                            "tags.asset.increment.view.counter.enabled",
458                            "asset.entry.increment.view.counter.enabled"
459                    }
460            };
461    
462            private static final String[][] _RENAMED_SYSTEM_KEYS = new String[][] {
463                    new String[] {
464                            "com.liferay.portal.kernel.util.StringBundler.unsafe.create." +
465                                    "threshold",
466                            "com.liferay.portal.kernel.util.StringBundler.threadlocal.buffer." +
467                                    "limit",
468                    }
469            };
470    
471            private static Log _log = LogFactoryUtil.getLog(VerifyProperties.class);
472    
473    }