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.MgnlNodeType;
37  import info.magnolia.cms.security.SecurityUtil;
38  import info.magnolia.module.DefaultModuleVersionHandler;
39  import info.magnolia.module.InstallContext;
40  import info.magnolia.module.delta.AbstractTask;
41  import info.magnolia.module.delta.ArrayDelegateTask;
42  import info.magnolia.module.delta.BootstrapSingleModuleResource;
43  import info.magnolia.module.delta.BootstrapSingleResource;
44  import info.magnolia.module.delta.CreateNodeTask;
45  import info.magnolia.module.delta.DeltaBuilder;
46  import info.magnolia.module.delta.FilterOrderingTask;
47  import info.magnolia.module.delta.IsAuthorInstanceDelegateTask;
48  import info.magnolia.module.delta.SetPropertyTask;
49  import info.magnolia.module.delta.Task;
50  import info.magnolia.module.delta.TaskExecutionException;
51  import info.magnolia.repository.RepositoryConstants;
52  
53  import java.security.NoSuchAlgorithmException;
54  import java.util.ArrayList;
55  import java.util.List;
56  
57  /**
58   * VersionHandler of the ExchangeSimple module.
59   *
60   * @version $Id$
61   */
62  public class ExchangeSimpleModuleVersionHandler extends DefaultModuleVersionHandler {
63      private final Task createEmptyActivationConfig = new ArrayDelegateTask("Activation configuration", "Creates an empty activation configuration", new Task[] {
64              new CreateNodeTask("Activation configuration", "Creates empty activation configuration", RepositoryConstants.CONFIG, "/server", "activation", MgnlNodeType.NT_CONTENT),
65              new SetPropertyTask(RepositoryConstants.CONFIG, "/server/activation", "class", info.magnolia.module.exchangesimple.DefaultActivationManager.class.getName()),
66              new CreateNodeTask("Activation configuration", "Creates empty subscribers node", RepositoryConstants.CONFIG, "/server/activation", "subscribers", MgnlNodeType.NT_CONTENT)
67      });
68  
69      public ExchangeSimpleModuleVersionHandler() {
70          super();
71  
72          register(DeltaBuilder.update("4.5", "URL of activation filter is no longer password protected but uses encryption instead.")
73                  .addTask(new BootstrapSingleModuleResource("Configure ActivationPage", "Register class to be used.", "config.modules.exchange-simple.pages.activationPage.xml"))
74                  .addTask(new BootstrapSingleModuleResource("ActivationPage Menu", "Configure menu in AdminInterface.", "config.modules.adminInterface.config.menu.tools.activationPage.xml"))
75                  .addTask(new IsAuthorInstanceDelegateTask("Security update", "Update security keys if on author instance.", new AbstractTask("", "") {
76  
77                      @Override
78                      public void execute(InstallContext installContext) throws TaskExecutionException {
79                          try {
80                              SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024));
81                          } catch (NoSuchAlgorithmException e) {
82                              throw new TaskExecutionException(e.getMessage(), e);
83                          }
84                      }
85                  }))
86                  .addTask(new FilterOrderingTask("activation", new String[] { "context", "login", "multipartRequest" })));
87  
88      }
89  
90      @Override
91      protected List<Task> getBasicInstallTasks(InstallContext installContext) {
92          final List<Task> installTasks = new ArrayList<Task>(super.getBasicInstallTasks(installContext));
93          installTasks.add(new FilterOrderingTask("activation", new String[] { "context", "login", "multipartRequest" }));
94          installTasks.add(new IsAuthorInstanceDelegateTask("", "", new BootstrapSingleResource("Bootstrap new activation configuration", "Bootstrap new activation configuration",
95                  "/info/magnolia/module/exchangesimple/setup/config.server.activation.xml"), createEmptyActivationConfig));
96  
97          return installTasks;
98      }
99  
100     @Override
101     protected List<Task> getExtraInstallTasks(InstallContext installContext) {
102         List<Task> tasks = new ArrayList<Task>();
103         tasks.addAll(super.getExtraInstallTasks(installContext));
104         tasks.add(new IsAuthorInstanceDelegateTask("Activation Keys", "Generate new Activation Key Pair.", new AbstractTask("", "") {
105 
106             @Override
107             public void execute(InstallContext installContext) throws TaskExecutionException {
108                 try {
109                     SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024));
110                 } catch (NoSuchAlgorithmException e) {
111                     throw new TaskExecutionException(e.getMessage(), e);
112                 }
113             }
114         }));
115 
116         return tasks;
117     }
118 
119 
120 }