View Javadoc

1   /**
2    * This file Copyright (c) 2003-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.module.exchangesimple.setup;
35  
36  import info.magnolia.cms.core.HierarchyManager;
37  import info.magnolia.cms.core.ItemType;
38  import info.magnolia.cms.security.SecurityUtil;
39  import info.magnolia.module.DefaultModuleVersionHandler;
40  import info.magnolia.module.InstallContext;
41  import info.magnolia.module.delta.AbstractTask;
42  import info.magnolia.module.delta.ArrayDelegateTask;
43  import info.magnolia.module.delta.BootstrapSingleResource;
44  import info.magnolia.module.delta.ConditionalDelegateTask;
45  import info.magnolia.module.delta.CreateNodeTask;
46  import info.magnolia.module.delta.DeltaBuilder;
47  import info.magnolia.module.delta.FilterOrderingTask;
48  import info.magnolia.module.delta.IsAuthorInstanceDelegateTask;
49  import info.magnolia.module.delta.SetPropertyTask;
50  import info.magnolia.module.delta.Task;
51  import info.magnolia.module.delta.TaskExecutionException;
52  import info.magnolia.module.exchangesimple.setup.for3_5.UpdateActivationConfigTask;
53  import info.magnolia.repository.RepositoryConstants;
54  
55  import java.security.NoSuchAlgorithmException;
56  import java.util.ArrayList;
57  import java.util.List;
58  
59  /**
60   * 3.5 being the first version of exchange-simple as a module, it is always "installed",
61   * but we need it to behave differently if magnolia was installed previously
62   * (ie. updating from 3.0), which is why there are so many "conditional
63   * tasks". Once 3.5 is out the door, this will need to be revised
64   * completely.
65   *
66   * @author gjoseph
67   * @version $Revision: $ ($Author: $)
68   */
69  public class ExchangeSimpleModuleVersionHandler extends DefaultModuleVersionHandler {
70      private final Task createEmptyActivationConfig = new ArrayDelegateTask("Activation configuration", "Creates an empty activation configuration", new Task[] {
71              new CreateNodeTask("Activation configuration", "Creates empty activation configuration", RepositoryConstants.CONFIG, "/server", "activation", ItemType.CONTENT.getSystemName()),
72              new SetPropertyTask(RepositoryConstants.CONFIG, "/server/activation", "class", info.magnolia.module.exchangesimple.DefaultActivationManager.class.getName()),
73              new CreateNodeTask("Activation configuration", "Creates empty subscribers node", RepositoryConstants.CONFIG, "/server/activation", "subscribers", ItemType.CONTENT.getSystemName())
74      });
75  
76      private final Task updateConfigFrom30OrBootstrap = new ConditionalDelegateTask("Activation configuration", "The activation configuration changed. This either updates your existing configuration or bootstraps a new one",
77              new UpdateActivationConfigTask(),
78              new IsAuthorInstanceDelegateTask("", "", new BootstrapSingleResource("Bootstrap new activation configuration", "Bootstrap new activation configuration",
79              "/mgnl-bootstrap/exchange-simple/config.server.activation.xml"), createEmptyActivationConfig)) {
80  
81          @Override
82          protected boolean condition(InstallContext ctx) {
83              final HierarchyManager hm = ctx.getConfigHierarchyManager();
84              return hm.isExist(UpdateActivationConfigTask.CE30_ROOT_PATH) || hm.isExist(UpdateActivationConfigTask.EE30_ROOT_PATH);
85          }
86      };
87  
88      private final BootstrapSingleResource bootstrapVirtualURIMapping = new BootstrapSingleResource("Bootstrap new virtual uri mapping", "Bootstrap new virtual uri mapping",
89      "/mgnl-bootstrap/exchange-simple/config.modules.exchange-simple.virtualURIMapping.3_0_to_3_5.xml");
90  
91      public ExchangeSimpleModuleVersionHandler() {
92          super();
93  
94          DeltaBuilder deltaTo354 =  DeltaBuilder.update("3.5.4", "URL of activation filter has changed");
95          deltaTo354.addTask(bootstrapVirtualURIMapping);
96          deltaTo354.addTask(new SetPropertyTask(RepositoryConstants.CONFIG, "/server/filters/activation/bypasses/allButActivationHandler","pattern", "/.magnolia/activation"));
97          this.register(deltaTo354);
98  
99          register(DeltaBuilder.update("4.5", "URL of activation filter is no longer password protected but uses encryption instead.")
100                 .addTask(new BootstrapSingleResource("", "", "/mgnl-bootstrap/exchange-simple/config.modules.exchange-simple.pages.activationPage.xml"))
101                 .addTask(new BootstrapSingleResource("", "", "/mgnl-bootstrap/exchange-simple/config.modules.adminInterface.config.menu.tools.activationPage.xml"))
102                 .addTask(new IsAuthorInstanceDelegateTask("", "", new AbstractTask("", "") {
103 
104                     @Override
105                     public void execute(InstallContext installContext) throws TaskExecutionException {
106                         try {
107                             SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024));
108                         } catch (NoSuchAlgorithmException e) {
109                             throw new TaskExecutionException(e.getMessage(), e);
110                         }
111                     }
112                 }))
113                 .addTask(new FilterOrderingTask("activation", new String[] { "context", "login", "multipartRequest" })));
114 
115     }
116 
117     @Override
118     protected List getBasicInstallTasks(InstallContext installContext) {
119         final List installTasks = new ArrayList(super.getBasicInstallTasks(installContext));
120         installTasks.add(new FilterOrderingTask("activation", new String[] { "context", "login", "multipartRequest" }));
121         return installTasks;
122     }
123 
124     @Override
125     protected List<Task> getExtraInstallTasks(InstallContext installContext) {
126         List<Task> tasks = new ArrayList<Task>();
127         tasks.addAll(super.getExtraInstallTasks(installContext));
128         tasks.add(new IsAuthorInstanceDelegateTask("Activation Keys", "Generate new Activation Key Pair.", new AbstractTask("", "") {
129 
130             @Override
131             public void execute(InstallContext installContext) throws TaskExecutionException {
132                 try {
133                     SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024));
134                 } catch (NoSuchAlgorithmException e) {
135                     throw new TaskExecutionException(e.getMessage(), e);
136                 }
137             }
138         }));
139 
140         return tasks;
141     }
142 
143 
144 }