View Javadoc

1   /**
2    * This file Copyright (c) 2008-2011 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.initial;
35  
36  import info.magnolia.cms.core.MgnlNodeType;
37  import info.magnolia.cms.core.SystemProperty;
38  import info.magnolia.cms.security.Realm;
39  import info.magnolia.module.delta.ArrayDelegateTask;
40  import info.magnolia.module.delta.BootstrapConditionally;
41  import info.magnolia.module.delta.BootstrapSingleModuleResource;
42  import info.magnolia.module.delta.BootstrapSingleResource;
43  import info.magnolia.module.delta.CheckOrCreatePropertyTask;
44  import info.magnolia.module.delta.CreateNodeTask;
45  import info.magnolia.module.delta.IsAuthorInstanceDelegateTask;
46  import info.magnolia.module.delta.ModuleFilesExtraction;
47  import info.magnolia.module.delta.MoveAndRenamePropertyTask;
48  import info.magnolia.module.delta.MoveNodeTask;
49  import info.magnolia.module.delta.NewPropertyTask;
50  import info.magnolia.module.delta.NodeExistsDelegateTask;
51  import info.magnolia.module.delta.PropertyExistsDelegateTask;
52  import info.magnolia.module.delta.RegisterModuleServletsTask;
53  import info.magnolia.module.delta.RemoveNodeTask;
54  import info.magnolia.module.delta.RemovePropertyTask;
55  import info.magnolia.module.delta.Task;
56  import info.magnolia.module.delta.WarnTask;
57  import info.magnolia.repository.RepositoryConstants;
58  import info.magnolia.setup.CoreModuleVersionHandler;
59  
60  import java.util.Arrays;
61  import java.util.List;
62  
63  import javax.jcr.ImportUUIDBehavior;
64  
65  import org.apache.commons.codec.binary.Base64;
66  import org.apache.commons.lang.StringUtils;
67  
68  /**
69   * Groups tasks which are need to do a fresh install of magnolia 4.5 (or higher).
70   *
71   * @see info.magnolia.setup.CoreModuleVersionHandler
72   *
73   * @version $Id$
74   */
75  public class GenericTasks {
76      /**
77       * @return tasks which have to be executed upon new installation (not update)
78       */
79      public static List<Task> genericTasksForNewInstallation() {
80          final String areWeBootstrappingAuthorInstance = StringUtils.defaultIfEmpty(SystemProperty.getProperty(CoreModuleVersionHandler.BOOTSTRAP_AUTHOR_INSTANCE_PROPERTY), "true");
81          return Arrays.asList(
82                  // - install server node
83                  new NodeExistsDelegateTask("Server node", "Creates the server node in the config repository if needed.", RepositoryConstants.CONFIG, "/server", null,
84                          new CreateNodeTask(null, null, RepositoryConstants.CONFIG, "/", "server", MgnlNodeType.NT_CONTENT)),
85  
86                  // - install or update modules node
87                  new NodeExistsDelegateTask("Modules node", "Creates the modules node in the config repository if needed.", RepositoryConstants.CONFIG, "/modules", null,
88                          new CreateNodeTask(null, null, RepositoryConstants.CONFIG, "/", "modules", MgnlNodeType.NT_CONTENT)),
89  
90                  new BootstrapSingleResource("Bootstrap", "Bootstraps the new filter configuration", "/mgnl-bootstrap/core/config.server.filters.xml", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW),
91  
92                  new BootstrapSingleResource("IPConfig rules changed",
93                          "Updates the existing ip access rules to match the new configuration structure or bootstraps the new default configuration.",
94                          "/mgnl-bootstrap/core/config.server.IPConfig.xml"),
95  
96                  new BootstrapSingleModuleResource("i18n content", "bootstrap the config", "config.server.i18n.content.xml"),
97                  new BootstrapSingleModuleResource("i18n system", "bootstrap the config", "config.server.i18n.system.xml"),
98  
99  
100                 new BootstrapSingleResource("New security configuration", "Install new configuration for security managers.", "/mgnl-bootstrap/core/config.server.security.xml"),
101                 new BootstrapSingleResource("New rendering strategy for links", "Install new configuration for link resolving.", "/mgnl-bootstrap/core/config.server.rendering.linkManagement.xml"),
102 
103                 new BootstrapConditionally("MIME mappings", "Adds MIMEMappings to server config, if not already present.", "/mgnl-bootstrap/core/config.server.MIMEMapping.xml"),
104                 new BootstrapConditionally("URI2Repository mappings", "Installs new configuration of URI2Repository mappings.", "/mgnl-bootstrap/core/config.server.URI2RepositoryMapping.xml", new UpdateURI2RepositoryMappings()),
105 
106                 // -- /server configuration tasks
107                 new PropertyExistsDelegateTask("Cleanup", "Config property /server/defaultMailServer was unused.", "config", "/server", "defaultMailServer",
108                         new RemovePropertyTask("", "", "config", "/server", "defaultMailServer")),
109 
110                 // the two following tasks replace the config.server.xml bootstrap file
111                 new CheckOrCreatePropertyTask("defaultExtension property", "Checks that the defaultExtension property exists in config:/server", "config", "/server", "defaultExtension", "html"),
112 
113                 new CheckOrCreatePropertyTask("admin property", "Checks that the admin property exists in config:/server", "config", "/server", "admin", areWeBootstrappingAuthorInstance),
114 
115                 new ArrayDelegateTask("defaultBaseUrl property",
116                         new NewPropertyTask("defaultBaseUrl property", "Adds the new defaultBaseUrl property with a default value.", "config", "/server", "defaultBaseUrl", "http://localhost:8080/magnolia/"),
117                         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.")
118                 ),
119 
120                 // this is only valid when updating - if /server/login exists
121                 new NodeExistsDelegateTask("Login configuration", "The login configuration was moved to filters configuration.", "config", "/server/login",
122                         new ArrayDelegateTask("",
123                                 new LoginAuthTypePropertyMovedToFilter(),
124                                 new LoginFormPropertyMovedToFilter(),
125                                 new MoveAndRenamePropertyTask("unsecuredPath is now handled by the bypass mechanism.", "/server/login", "UnsecuredPath", "/server/filters/uriSecurity/bypasses/login", "pattern"),
126                                 new RemoveNodeTask("Login configuration changed", "Removes /server/login as it is not used anymore.", "config", "/server/login")
127                         )),
128 
129                 // --- user/roles repositories related tasks
130                 new CreateNodeTask("Adds system folder node to users workspace", "Add system realm folder /system to users workspace.", RepositoryConstants.USERS, "/", Realm.REALM_SYSTEM.getName(), MgnlNodeType.NT_FOLDER),
131                 new CreateNodeTask("Adds admin folder node to users workspace", "Add magnolia realm folder /admin to users workspace.", RepositoryConstants.USERS, "/", Realm.REALM_ADMIN.getName(), MgnlNodeType.NT_FOLDER),
132 
133                 new IsAuthorInstanceDelegateTask("URI permissions", "Introduction of URI-based security. All existing roles will have GET/POST permissions on /*.",
134                         new AddURIPermissionsToAllRoles(true),
135                         new AddURIPermissionsToAllRoles(false)),
136 
137                 new IsAuthorInstanceDelegateTask("Anonymous role", "Anonymous role must exist.",
138                         new BootstrapConditionally("", "Author permissions", "/info/magnolia/setup/author/userroles.anonymous.xml"),
139                         new BootstrapConditionally("", "Public permissions", "/info/magnolia/setup/public/userroles.anonymous.xml")),
140 
141                 new BootstrapConditionally("Superuser role", "Bootstraps the superuser role if needed.", "/mgnl-bootstrap/core/userroles.superuser.xml"),
142 
143                 new BootstrapConditionally("Anonymous user", "Anonymous user must exist in the system realm: will move the existing one or bootstrap it.",
144                         RepositoryConstants.USERS, "/anonymous", "/mgnl-bootstrap/core/users.system.anonymous.xml",
145                         new ArrayDelegateTask("",
146                                 new MoveNodeTask("", "", RepositoryConstants.USERS, "/anonymous", "/system/anonymous", false),
147                                 new NewPropertyTask("Anonymous user", "Anonymous user must have a password.", RepositoryConstants.USERS, "/system/anonymous", "pswd", new String(Base64.encodeBase64("anonymous".getBytes())))
148                         )),
149 
150                 new BootstrapConditionally("Superuser user", "Superuser user must exist in the system realm: will move the existing one or bootstrap it.",
151                         RepositoryConstants.USERS, "/superuser", "/mgnl-bootstrap/core/users.system.superuser.xml",
152                         new MoveNodeTask("", "", RepositoryConstants.USERS, "/superuser", "/system/superuser", false)),
153 
154                 // --- generic tasks
155                 new ModuleFilesExtraction(),
156                 new RegisterModuleServletsTask(),
157 
158                 // --- system-wide tasks (impact all modules)
159                 new WarnIgnoredModuleFilters(),
160                 new UpdateURIMappings()
161         );
162     }
163 
164 }