View Javadoc
1   /**
2    * This file Copyright (c) 2003-2015 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.setup;
35  
36  import info.magnolia.cms.security.Permission;
37  import info.magnolia.commands.impl.MarkNodeAsDeletedCommand;
38  import info.magnolia.jcr.util.NodeTypes;
39  import info.magnolia.module.AbstractModuleVersionHandler;
40  import info.magnolia.module.InstallContext;
41  import info.magnolia.module.delta.AddURIPermissionTask;
42  import info.magnolia.module.delta.ArrayDelegateTask;
43  import info.magnolia.module.delta.BootstrapConditionally;
44  import info.magnolia.module.delta.BootstrapSingleModuleResource;
45  import info.magnolia.module.delta.BootstrapSingleResource;
46  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
47  import info.magnolia.module.delta.Condition;
48  import info.magnolia.module.delta.DeltaBuilder;
49  import info.magnolia.module.delta.FindAndChangeTemplateIdTask;
50  import info.magnolia.module.delta.FixUserRolePermissionsPropertyTask;
51  import info.magnolia.module.delta.MoveAndRenamePropertyTask;
52  import info.magnolia.module.delta.NoSameNameSiblingsCondition;
53  import info.magnolia.module.delta.NodeExistsDelegateTask;
54  import info.magnolia.module.delta.OrderFilterBeforeTask;
55  import info.magnolia.module.delta.OrderNodeBeforeTask;
56  import info.magnolia.module.delta.PartialBootstrapTask;
57  import info.magnolia.module.delta.PathExistenceDelegateTask;
58  import info.magnolia.module.delta.PropertyExistsDelegateTask;
59  import info.magnolia.module.delta.PropertyValueDelegateTask;
60  import info.magnolia.module.delta.RemoveInstallFilesTask;
61  import info.magnolia.module.delta.RemoveNodeTask;
62  import info.magnolia.module.delta.RemovePermissionTask;
63  import info.magnolia.module.delta.SetPropertyTask;
64  import info.magnolia.module.delta.Task;
65  import info.magnolia.module.delta.WarnTask;
66  import info.magnolia.module.delta.WebXmlConditionsUtil;
67  import info.magnolia.module.delta.WorkspaceXmlConditionsUtil;
68  import info.magnolia.repository.RepositoryConstants;
69  import info.magnolia.repository.RepositoryManager;
70  import info.magnolia.setup.for5_0.CheckOrCreateLastActivatedPropertyTask;
71  import info.magnolia.setup.for5_0.ConvertMetaDataUpdateTask;
72  import info.magnolia.setup.for5_0.Register50NodeTypeTask;
73  import info.magnolia.setup.for5_0.RemoveMetaDataInNodeTypeDefinitionTask;
74  import info.magnolia.setup.for5_2.AddActivatableMixinForContentNodeTask;
75  import info.magnolia.setup.for5_2.GrantReadPermissionToRolesTask;
76  import info.magnolia.setup.for5_2.IsNotAProblematicEnvironmentCondition;
77  import info.magnolia.setup.for5_2.RemoveOpenWFEPermissionsTask;
78  import info.magnolia.setup.initial.GenericTasks;
79  
80  import java.util.ArrayList;
81  import java.util.Arrays;
82  import java.util.List;
83  
84  import javax.inject.Inject;
85  import javax.jcr.ImportUUIDBehavior;
86  
87  /**
88   * Special VersionHandler for the core module. As it does not extend {@link info.magnolia.module.DefaultModuleVersionHandler} it has a special getBasicInstallTasks(InstallContext) that
89   * e.g. will not automatically bootstrap xml-files placed in mgnl-bootstrap/core.
90   */
91  public class CoreModuleVersionHandler extends AbstractModuleVersionHandler {
92      public static final String BOOTSTRAP_AUTHOR_INSTANCE_PROPERTY = "magnolia.bootstrap.authorInstance";
93      public static final String SECURITY_BASE_ROLE = "security-base";
94  
95      // TODO : why is this a BootstrapConditionally and not a BootstrapSingleResource ?
96      private final BootstrapConditionally auditTrailManagerTask = new BootstrapConditionally("New auditory log configuration", "Install new configuration for auditory log manager.", "/mgnl-bootstrap/core/config.server.auditLogging.xml");
97      private final BootstrapSingleResource bootstrapWebContainerResources = new BootstrapSingleResource("Web container resources configuration", "Global configuration which resources are not meant to be handled by Magnolia. For instance JSP files.", "/mgnl-bootstrap/core/config.server.webContainerResources.xml");
98      private final BootstrapSingleModuleResource bootstrapChannelManagement = new BootstrapSingleModuleResource("ChannelManagement configuration", "", "config.server.rendering.channelManagement.xml");
99  
100     private final BootstrapSingleModuleResource bootstrapChannelFilter = new BootstrapSingleModuleResource("ChannelFilter configuration", "", "config.server.filters.channel.xml");
101     private final Task placeChannelBeforeLogout = new OrderFilterBeforeTask("channel", new String[]{"logout"});
102 
103     private final Task removeObsoleteInstallFiles = new RemoveInstallFilesTask("Remove obsolete dms templates install files", "templates/dms");
104 
105     private final RepositoryManager repositoryManager;
106 
107     /**
108      * Cleans up security-base role from no longer valid URis (basically legacy adminInterface pages not yet ported to M5). Also allows basic access to AdminCentral.
109      */
110     protected static List<String> PERMISSIONS_FOR_LEGACY_PAGES = Arrays.asList(
111             "/.magnolia/pages/messages*",
112             "/.magnolia/pages/installedModulesList*",
113             "/.magnolia/pages/jcrUtils*",
114             "/.magnolia/pages/configuration*",
115             "/.magnolia/pages/logViewer*",
116             "/.magnolia/pages/sendMail*",
117             "/.magnolia/pages/users*",
118             "/.magnolia/pages/activationTools*",
119             "/.magnolia/pages/activationMonitor*",
120             "/.magnolia/pages/groovyInteractiveConsole*",
121             "/.magnolia/pages/migrationReport*",
122             "/.magnolia/pages/backup*",
123             "/.magnolia/pages/allModulesList*",
124             "/.magnolia/pages/cacheTools*",
125             "/.magnolia/pages/flows*",
126             "/.magnolia/pages/import*",
127             "/.magnolia/pages/export*",
128             "/.magnolia/pages/permission*",
129             "/.magnolia/pages/developmentUtils*"
130     );
131 
132     protected Task updateSecurityBaseRolePermissions() {
133         ArrayDelegateTask permissionsTask = new ArrayDelegateTask("Update security-base role", "Disallows access to some sensitive URIs and grants basic access to AdminCentral.");
134         for (String path : PERMISSIONS_FOR_LEGACY_PAGES) {
135             permissionsTask.addTask(new RemovePermissionTask("", SECURITY_BASE_ROLE, "uri", path, AddURIPermissionTask.DENY));
136         }
137         permissionsTask.addTask(new RemovePermissionTask("", SECURITY_BASE_ROLE, RepositoryConstants.USER_ROLES, "/" + SECURITY_BASE_ROLE, Permission.READ));
138         return permissionsTask;
139     }
140 
141     @Inject
142     public CoreModuleVersionHandler(RepositoryManager repositoryManager) {
143         super();
144         this.repositoryManager = repositoryManager;
145 
146         register(DeltaBuilder.checkPrecondition("4.5", "5.0"));
147 
148         register(DeltaBuilder.update("4.5.2", "")
149                 .addTask(new PropertyExistsDelegateTask("Fix property name", "", RepositoryConstants.CONFIG, "/server/security/userManagers/system", "realName", new MoveAndRenamePropertyTask("Fix propertyName", "/server/security/userManagers/system", "realName", "/server/security/userManagers/system", "realmName")))
150                 .addTask(new PropertyExistsDelegateTask("Fix property name", "", RepositoryConstants.CONFIG, "/server/security/userManagers/admin", "realName", new MoveAndRenamePropertyTask("Fix propertyName", "/server/security/userManagers/admin", "realName", "/server/security/userManagers/admin", "realmName"))));
151 
152         register((DeltaBuilder.update("4.5.9", ""))
153                 .addTask(new NodeExistsDelegateTask("AuditLogging configurations", "Add auditLogging configurations for delete action", "config", "/server/auditLogging/logConfigurations/delete", null, new PartialBootstrapTask("", "", "/mgnl-bootstrap/core/config.server.auditLogging.xml", "/auditLogging/logConfigurations/delete", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW)))
154                 .addTask(new CheckAndModifyPropertyValueTask("AuditLogging configurations", "Change auditLogging class", "config", "/server/auditLogging", "class", "info.magnolia.logging.AuditLoggingManager", "info.magnolia.audit.AuditLoggingManager")));
155 
156         register(DeltaBuilder.update("5.0", "")
157                 .addTask(new Register50NodeTypeTask("Register the new M5 node Type", "", RepositoryConstants.CONFIG))
158                 .addTask(new RemoveMetaDataInNodeTypeDefinitionTask("Un register the metaData child node", "", RepositoryConstants.CONFIG))
159                 .addTask(new ConvertMetaDataUpdateTask("Convert MetaData Task", "Remove the metaData sub node and replace them with mixIn when appropriate"))
160                 .addTask(new RemoveNodeTask("Remove PageEditorServlet", "Remove obsolete PageEditorServlet configuration.", RepositoryConstants.CONFIG, "/server/filters/servlets/PageEditorServlet"))
161                 .addTask(new RemoveNodeTask("Remove obsolete 'templating-editor' configuration", "", RepositoryConstants.CONFIG, "/modules/magnolia-templating-editor"))
162                 .addTask(new PartialBootstrapTask("Bootstrap link transformers", "Bootstrap 'server/rendering/linkManagement/transformers", "/mgnl-bootstrap/core/config.server.rendering.linkManagement.xml", "/linkManagement/transformers")));
163         register((DeltaBuilder.update("5.0.1", ""))
164                 .addTask(new CheckAndModifyPropertyValueTask("MIMEMapping", "Change xsl extension mime-type from text/xml to application/xml", RepositoryConstants.CONFIG, "/server/MIMEMapping/xsl", "mime-type", "text/xml", "application/xml"))
165                 .addTask(new CheckAndModifyPropertyValueTask("MIMEMapping", "Change xml extension mime-type from text/xml to application/xml", RepositoryConstants.CONFIG, "/server/MIMEMapping/xml", "mime-type", "text/xml", "application/xml")));
166         register((DeltaBuilder.update("5.0.3", ""))
167                 .addTask(new PartialBootstrapTask("JSON", "Add JSON mime-type", "/mgnl-bootstrap/core/config.server.MIMEMapping.xml", "/MIMEMapping/json")));
168         register((DeltaBuilder.update("5.1", ""))
169                 .addTask(new WarnTask("respectOrderDocument parameter", "As of Magnolia 5.1, the respectOrderDocument parameter has been reintroduced in repo config files and set to true by default. You will need to set it manually for each workspace in your installation. Please, refer to the release notes for more details."))
170                 .addTask(new RemoveNodeTask("Remove intercept filter", "Removes no longer used intercept filter.", RepositoryConstants.CONFIG, "/server/filters/cms/intercept")));
171         register((DeltaBuilder.update("5.1.1", ""))
172                 .addTask(new NodeExistsDelegateTask("Set mgnl:lastActivated date of the user superuser", "Set mgnl:lastActivated date of the user superuser (if not set yet)", RepositoryConstants.USERS, "/system/superuser",
173                         new CheckOrCreateLastActivatedPropertyTask("", "", RepositoryConstants.USERS, "/system/superuser")))
174                 .addTask(new NodeExistsDelegateTask("Set mgnl:lastActivated date of the user anonymous", "Set mgnl:lastActivated date of the user anonymous (if not set yet)", RepositoryConstants.USERS, "/system/anonymous",
175                         new CheckOrCreateLastActivatedPropertyTask("", "", RepositoryConstants.USERS, "/system/anonymous")))
176                 .addTask(new NodeExistsDelegateTask("Set mgnl:lastActivated date of the superuser role", "Set mgnl:lastActivated date of the superuser role (if not set yet)", RepositoryConstants.USER_ROLES, "/superuser",
177                         new CheckOrCreateLastActivatedPropertyTask("", "", RepositoryConstants.USER_ROLES, "/superuser")))
178                 .addTask(new NodeExistsDelegateTask("Set mgnl:lastActivated date of the anonymous role", "Set mgnl:lastActivated date of the anonymous role (if not set yet)", RepositoryConstants.USER_ROLES, "/anonymous",
179                         new CheckOrCreateLastActivatedPropertyTask("", "", RepositoryConstants.USER_ROLES, "/anonymous")))
180                 .addTask(new NodeExistsDelegateTask("Set mgnl:lastActivated date of the security-base role", "Set mgnl:lastActivated date of the security-base role (if not set yet)", RepositoryConstants.USER_ROLES, "/security-base",
181                         new CheckOrCreateLastActivatedPropertyTask("", "", RepositoryConstants.USER_ROLES, "/security-base")))
182                 .addTask(new FindAndChangeTemplateIdTask("Change template id mgnlDelete", "Change template id mgnlDeleted to ui-admincentral:deleted for all content marked as deleted in website repository", RepositoryConstants.WEBSITE, "mgnlDeleted", MarkNodeAsDeletedCommand.DELETED_NODE_TEMPLATE))
183                 .addTask(new FindAndChangeTemplateIdTask("Change template id adminInterface:mgnlDeleted", "Change template id adminInterface:mgnlDeleted to ui-admincentral:deleted for all content marked as deleted in website repository", RepositoryConstants.WEBSITE, "adminInterface:mgnlDeleted", MarkNodeAsDeletedCommand.DELETED_NODE_TEMPLATE)));
184         register((DeltaBuilder.update("5.1.2", ""))
185                 .addTask(new ChangeNodeTypeOfSubAppsTask("Change primary node type of subapps", "If primary node type of subapps node is set to " + NodeTypes.Content.NAME + " then change it to " + NodeTypes.ContentNode.NAME))
186                 .addTask(new PartialBootstrapTask("Anonymous user", "Change anonymous user permission. He can't have write access to himself.", "/mgnl-bootstrap/core/users.system.anonymous.xml", "/anonymous/acl_users")));
187 
188         register((DeltaBuilder.update("5.2.1", ""))
189                 .addTask(new RemoveOpenWFEPermissionsTask("Find and remove all openWFE permissions from the userroles workspace", ""))
190                 .addTask(new GrantReadPermissionToRolesTask("Set read-permission to role itself", "If a role do not have a read permission to itself, add it")));
191         register((DeltaBuilder.update("5.2.2", ""))
192                 .addTask(removeObsoleteInstallFiles)
193                 .addTask(new AddActivatableMixinForContentNodeTask("Add the mixIn '" + NodeTypes.Activatable.NAME + "' to the '" + NodeTypes.ContentNode.NAME + "' node type definition", "", RepositoryConstants.CONFIG)));
194         register((DeltaBuilder.update("5.2.3", ""))
195                 .addTask(new RemovePermissionTask("Remove 'anonymous' role permission", "anonymous", RepositoryConstants.USER_ROLES, "/anonymous", Permission.READ)));
196 
197         register((DeltaBuilder.update("5.3.2", ""))
198                 .addTask(new NodeExistsDelegateTask("Add csrfSecurity Filter", "/server/filters/csrfSecurity",
199                         /* Partially bootstrap new bypass for Vaadin requests if filter already exists */
200                         new PathExistenceDelegateTask("Add csrfSecurity Filter", "", new String[]{"/server/filters/csrfSecurity/bypasses/BypassWhenVaadinRequest"}, new String[]{"/server/filters/csrfSecurity/bypasses/BypassWhenNotInAdminCentral", "/server/filters/csrfSecurity/bypasses/BypassWhenNotAuthenticated", "/server/filters/csrfSecurity/bypasses/BypassWhenNoQueryParameters"},
201                                 new PartialBootstrapTask("Add csrfSecurity Filter", "", "/mgnl-bootstrap/core/config.server.filters.xml", "/filters/csrfSecurity/bypasses/BypassWhenVaadinRequest", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW)),
202                         /* Partially bootstrap whole csrf filter if it doesn't exists */
203                         new PartialBootstrapTask("Add csrfSecurity Filter", "", "/mgnl-bootstrap/core/config.server.filters.xml", "/filters/csrfSecurity", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW)))
204                 .addTask(new NodeExistsDelegateTask("Order csrfSecurity Filter", "Put csrfSecurity before uriSecurity Filter.", RepositoryConstants.CONFIG, "/server/filters/uriSecurity",
205                         new OrderNodeBeforeTask("Order csrfSecurity Filter", "Put csrfSecurity before uriSecurity Filter.", RepositoryConstants.CONFIG, "/server/filters/csrfSecurity", "uriSecurity"),
206                         new WarnTask("CSRF Security Filter is inactive.", "CSRF Security Filter inactive. The installed csrfFilter would normally be ordered before the uriSecurity filter, but could not be moved there as a uriFilter node does not exist in the /server/filters node. The installed csrfFilter must be movded up the filters list manually.")))
207                 .addTask(new NodeExistsDelegateTask("Add csrfSecurity Filter", "/server/auditLogging/logConfigurations/security", null,
208                         new PartialBootstrapTask("Add 'security' AuditLogging logConfiguration.", "", "/mgnl-bootstrap/core/config.server.auditLogging.xml", "/auditLogging/logConfigurations/security", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW))));
209 
210         register((DeltaBuilder.update("5.3.5", ""))
211 
212                 .addTask(new FixUserRolePermissionsPropertyTask("/superuser")));
213 
214         register((DeltaBuilder.update("5.4.1", ""))
215                 .addTask(updateSecurityBaseRolePermissions()));
216 
217         register((DeltaBuilder.update("5.4.3", ""))
218                 .addTask(new PropertyValueDelegateTask("Change MIME mapping of Javascript resources", "/server/MIMEMapping/js", "mime-type", "application/x-javascript", true,
219                         new SetPropertyTask("config", "/server/MIMEMapping/js", "mime-type", "application/javascript"))));
220     }
221 
222     @Override
223     protected List<Task> getBasicInstallTasks(InstallContext ctx) {
224         final List<Task> tasks = new ArrayList<Task>();
225         tasks.addAll(GenericTasks.genericTasksForNewInstallation());
226         tasks.add(auditTrailManagerTask);
227         tasks.add(bootstrapWebContainerResources);
228         tasks.add(new BootstrapConditionally("Security", "Bootstraps security-base role.", "/mgnl-bootstrap/core/userroles.security-base.xml"));
229         // always hash passwords. Task will not re-hash so it is safe to run this op at any time, multiple times.
230         tasks.add(new HashUsersPasswords());
231         tasks.add(bootstrapChannelManagement);
232         tasks.add(bootstrapChannelFilter);
233         tasks.add(placeChannelBeforeLogout);
234 
235         return tasks;
236     }
237 
238     @Override
239     protected List<Condition> getInstallConditions() {
240         final ArrayList<Condition> conditions = new ArrayList<Condition>();
241 
242         conditions.add(new IsNotAProblematicEnvironmentCondition());
243 
244         final WebXmlConditionsUtil u = new WebXmlConditionsUtil(conditions);
245         u.servletIsNowWrapped("ActivationHandler");
246         u.servletIsNowWrapped("AdminTreeServlet");
247         u.servletIsNowWrapped("classpathspool");
248         u.servletIsNowWrapped("DialogServlet");
249         u.servletIsNowWrapped("PageServlet");
250         u.servletIsNowWrapped("log4j");
251         u.servletIsNowWrapped("FCKEditorSimpleUploadServlet");
252         u.servletIsDeprecated("uuidRequestDispatcher");
253         u.filterIsDeprecated("info.magnolia.cms.filters.MagnoliaManagedFilter", "info.magnolia.cms.filters.MgnlMainFilter");
254         u.filterMustBeRegisteredWithCorrectDispatchers("info.magnolia.cms.filters.MgnlMainFilter");
255         u.listenerIsDeprecated("info.magnolia.cms.servlets.PropertyInitializer", "info.magnolia.cms.servlets.MgnlServletContextListener");
256         u.listenerIsDeprecated("info.magnolia.cms.beans.config.ShutdownManager", "info.magnolia.cms.servlets.MgnlServletContextListener");
257         final WorkspaceXmlConditionsUtil u2 = new WorkspaceXmlConditionsUtil(conditions);
258         u2.textFilterClassesAreNotSet();
259 
260         conditions.add(new SystemTmpDirCondition());
261         conditions.add(new NoSameNameSiblingsCondition(repositoryManager));
262 
263         return conditions;
264     }
265 }
266