View Javadoc

1   /**
2    * This file Copyright (c) 2008-2010 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.for3_5;
35  
36  import info.magnolia.cms.beans.config.ContentRepository;
37  import info.magnolia.cms.core.ItemType;
38  import info.magnolia.cms.core.SystemProperty;
39  import info.magnolia.cms.security.IPSecurityManagerImpl;
40  import info.magnolia.cms.security.Realm;
41  import info.magnolia.module.delta.ArrayDelegateTask;
42  import info.magnolia.module.delta.BootstrapConditionally;
43  import info.magnolia.module.delta.BootstrapSingleResource;
44  import info.magnolia.module.delta.CheckOrCreatePropertyTask;
45  import info.magnolia.module.delta.CopyOrReplaceNodePropertiesTask;
46  import info.magnolia.module.delta.CreateNodeTask;
47  import info.magnolia.module.delta.IsAuthorInstanceDelegateTask;
48  import info.magnolia.module.delta.ModuleFilesExtraction;
49  import info.magnolia.module.delta.MoveAndRenamePropertyTask;
50  import info.magnolia.module.delta.MoveNodeTask;
51  import info.magnolia.module.delta.NewPropertyTask;
52  import info.magnolia.module.delta.NodeExistsDelegateTask;
53  import info.magnolia.module.delta.PropertyExistsDelegateTask;
54  import info.magnolia.module.delta.RegisterModuleServletsTask;
55  import info.magnolia.module.delta.RemoveNodeTask;
56  import info.magnolia.module.delta.RemovePropertyTask;
57  import info.magnolia.module.delta.Task;
58  import info.magnolia.module.delta.WarnTask;
59  import info.magnolia.setup.CoreModuleVersionHandler;
60  import org.apache.commons.codec.binary.Base64;
61  import org.apache.commons.lang.StringUtils;
62  
63  import java.util.Arrays;
64  import java.util.List;
65  
66  /**
67   * This class just groups all tasks which are need to update to Magnolia 3.5,
68   * in order to cleanup CoreModuleVersionHandler.
69   *
70   * @see info.magnolia.setup.CoreModuleVersionHandler
71   *
72   * @author gjoseph
73   * @version $Revision: $ ($Author: $)
74   */
75  public class GenericTasks {
76      private static final String UNSECURE_URIS_BACKUP_PATH = "/server/install/backup/unsecureURIList";
77      private static final String SECURE_URIS_BACKUP_PATH = "/server/install/backup/secureURIList";
78  
79      /**
80       * @return tasks which have to be executed whether we're installing or upgrading from 3.0
81       */
82      public static List<Task> genericTasksFor35() {
83          final String areWeBootstrappingAuthorInstance = StringUtils.defaultIfEmpty(SystemProperty.getProperty(CoreModuleVersionHandler.BOOTSTRAP_AUTHOR_INSTANCE_PROPERTY), "true");
84          return Arrays.asList(
85                  // - install server node
86                  new NodeExistsDelegateTask("Server node", "Creates the server node in the config repository if needed.", ContentRepository.CONFIG, "/server", null,
87                          new CreateNodeTask(null, null, ContentRepository.CONFIG, "/", "server", ItemType.CONTENT.getSystemName())),
88  
89                  // - install or update modules node
90                  new NodeExistsDelegateTask("Modules node", "Creates the modules node in the config repository if needed.", ContentRepository.CONFIG, "/modules", null,
91                          new CreateNodeTask(null, null, ContentRepository.CONFIG, "/", "modules", ItemType.CONTENT.getSystemName())),
92  
93                  new MigrateFilterConfiguration("/mgnl-bootstrap/core/config.server.filters.xml"),
94  
95                  new BootstrapConditionally("IPConfig rules changed",
96                          "Updates the existing ip access rules to match the new configuration structure or bootstraps the new default configuration.",
97                          "/mgnl-bootstrap/core/config.server.IPConfig.xml",
98                          new ArrayDelegateTask(null,
99                                  new NewPropertyTask("IPSecurityManager class property", "IPSecurity is now a component which can be configured through the repository.", "config", "/server/IPConfig", "class", IPSecurityManagerImpl.class.getName()),
100                                 new IPConfigRulesUpdate()
101                         )),
102 
103                 new UpdateI18nConfiguration(),
104 
105                 new BootstrapSingleResource("New security configuration", "Install new configuration for security managers.", "/mgnl-bootstrap/core/config.server.security.xml"),
106                 new BootstrapSingleResource("New rendering strategy for links", "Install new configuration for link resolving.", "/mgnl-bootstrap/core/config.server.rendering.linkManagement.xml"),
107 
108                 new BootstrapConditionally("MIME mappings", "Adds MIMEMappings to server config, if not already present.", "/mgnl-bootstrap/core/config.server.MIMEMapping.xml"),
109                 new BootstrapConditionally("URI2Repository mappings", "Installs new configuration of URI2Repository mappings.", "/mgnl-bootstrap/core/config.server.URI2RepositoryMapping.xml", new UpdateURI2RepositoryMappings()),
110 
111                 // -- /server configuration tasks
112                 new PropertyExistsDelegateTask("Cleanup", "Config property /server/defaultMailServer was unused.", "config", "/server", "defaultMailServer",
113                         new RemovePropertyTask("", "", "config", "/server", "defaultMailServer")),
114 
115                 // the two following tasks replace the config.server.xml bootstrap file
116                 new CheckOrCreatePropertyTask("defaultExtension property", "Checks that the defaultExtension property exists in config:/server", "config", "/server", "defaultExtension", "html"),
117 
118                 new CheckOrCreatePropertyTask("admin property", "Checks that the admin property exists in config:/server", "config", "/server", "admin", areWeBootstrappingAuthorInstance),
119                 new MoveAndRenamePropertyTask("basicRealm property", "/server", "basicRealm", "magnolia 3.0", "/server/filters/uriSecurity/clientCallback", "realmName", "Magnolia"),
120                 new ArrayDelegateTask("defaultBaseUrl property",
121                         new NewPropertyTask("defaultBaseUrl property", "Adds the new defaultBaseUrl property with a default value.", "config", "/server", "defaultBaseUrl", "http://localhost:8080/magnolia/"),
122                         new WarnTask("defaultBaseUrl property", "Please set the config:/server/defaultBaseUrl property to a full URL to be used when generating absolute URLs for external systems.")
123                 ),
124 
125                 // this is only valid when updating - if /server/login exists
126                 new NodeExistsDelegateTask("Login configuration", "The login configuration was moved to filters configuration.", "config", "/server/login",
127                         new ArrayDelegateTask("",
128                                 new LoginAuthTypePropertyMovedToFilter(),
129                                 new LoginFormPropertyMovedToFilter(),
130                                 new MoveAndRenamePropertyTask("unsecuredPath is now handled by the bypass mechanism.", "/server/login", "UnsecuredPath", "/server/filters/uriSecurity/bypasses/login", "pattern"),
131                                 new RemoveNodeTask("Login configuration changed", "Removes /server/login as it is not used anymore.", "config", "/server/login")
132                         )),
133 
134                 new CopyOrReplaceNodePropertiesTask("clientCallback configuration for content security", "The clientCallback configuration needs to be configuration for each security filter. This is copying the one from the URI security filter to the content security filter.",
135                         "config", "/server/filters/uriSecurity/clientCallback", "/server/filters/cms/contentSecurity/clientCallback"),
136 
137                 // --- user/roles repositories related tasks
138                 new CreateNodeTask("Adds system folder node to users workspace", "Add system realm folder /system to users workspace.", ContentRepository.USERS, "/", Realm.REALM_SYSTEM, ItemType.NT_FOLDER),
139                 new CreateNodeTask("Adds admin folder node to users workspace", "Add magnolia realm folder /admin to users workspace.", ContentRepository.USERS, "/", Realm.REALM_ADMIN, ItemType.NT_FOLDER),
140 
141                 new IsAuthorInstanceDelegateTask("URI permissions", "Introduction of URI-based security. All existing roles will have GET/POST permissions on /*.",
142                         new AddURIPermissionsToAllRoles(true),
143                         new AddURIPermissionsToAllRoles(false)),
144 
145                 new IsAuthorInstanceDelegateTask("Anonymous role", "Anonymous role must exist.",
146                         new BootstrapConditionally("", "Author permissions", "/info/magnolia/setup/author/userroles.anonymous.xml"),
147                         new BootstrapConditionally("", "Public permissions", "/info/magnolia/setup/public/userroles.anonymous.xml")),
148 
149                 new BootstrapConditionally("Superuser role", "Bootstraps the superuser role if needed.", "/mgnl-bootstrap/core/userroles.superuser.xml"),
150 
151                 new BootstrapConditionally("Anonymous user", "Anonymous user must exist in the system realm: will move the existing one or bootstrap it.",
152                         ContentRepository.USERS, "/anonymous", "/mgnl-bootstrap/core/users.system.anonymous.xml",
153                         new ArrayDelegateTask("",
154                                 new MoveNodeTask("", "", ContentRepository.USERS, "/anonymous", "/system/anonymous", false),
155                                 new NewPropertyTask("Anonymous user", "Anonymous user must have a password.", ContentRepository.USERS, "/system/anonymous", "pswd", new String(Base64.encodeBase64("anonymous".getBytes())))
156                         )),
157 
158                 new BootstrapConditionally("Superuser user", "Superuser user must exist in the system realm: will move the existing one or bootstrap it.",
159                         ContentRepository.USERS, "/superuser", "/mgnl-bootstrap/core/users.system.superuser.xml",
160                         new MoveNodeTask("", "", ContentRepository.USERS, "/superuser", "/system/superuser", false)),
161 
162                 // only relevant if updating, but does not hurt if installing since it checks for mgnl:user nodes
163                 new MoveMagnoliaUsersToRealmFolder(),
164 
165                 // --- generic tasks
166                 new ModuleFilesExtraction(),
167                 new RegisterModuleServletsTask(),
168 
169                 // --- check and update old security configuration if necessary
170                 new NodeExistsDelegateTask("Security configuration", "The unsecureURIList configuration was removed from /servers and will be handled by the uriSecurityFilter in 3.5.", ContentRepository.CONFIG, "/server/unsecureURIList", new ArrayDelegateTask("UnsecureURIList update", new Task[]{
171                         new MoveNodeTask("Unsecure URIs", "Moves the current configuration of unsecure URIs to a backup location", ContentRepository.CONFIG, "/server/unsecureURIList", UNSECURE_URIS_BACKUP_PATH, true),
172                         new CheckAndUpdateUnsecureURIs(UNSECURE_URIS_BACKUP_PATH)
173                 })),
174                 new NodeExistsDelegateTask("Security configuration", "The secureURIList configuration was removed from /servers and will be handled by the URI-based security mechanism in 3.5.", ContentRepository.CONFIG, "/server/secureURIList", new ArrayDelegateTask("SecureURIList update", new Task[]{
175                         new MoveNodeTask("Secure URIs", "Moves the current configuration of secure URIs to a backup location", ContentRepository.CONFIG, "/server/secureURIList", SECURE_URIS_BACKUP_PATH, true),
176                         new CheckAndUpdateSecureURIs(SECURE_URIS_BACKUP_PATH)
177                 })),
178 
179                 // --- system-wide tasks (impact all modules)
180                 new WarnIgnoredModuleFilters(),
181                 new RenamedRenderersToTemplateRenderers(),
182                 new ReconfigureCommands(),
183                 new UpdateURIMappings(),
184                 new RemoveModuleDescriptorDetailsFromRepo()
185         );
186     }
187 
188 }