1 /** 2 * This file Copyright (c) 2013-2016 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.groovy.rescue; 35 36 import info.magnolia.cms.core.SystemProperty; 37 import info.magnolia.cms.security.RescueSecuritySupport; 38 import info.magnolia.cms.security.SecuritySupport; 39 import info.magnolia.context.MgnlContext; 40 import info.magnolia.context.SingleJCRSessionSystemContext; 41 import info.magnolia.i18nsystem.SimpleTranslator; 42 import info.magnolia.i18nsystem.TranslationService; 43 import info.magnolia.module.groovy.terminal.Terminal; 44 import info.magnolia.objectfactory.Components; 45 import info.magnolia.ui.framework.message.MessagesManager; 46 47 import org.slf4j.Logger; 48 import org.slf4j.LoggerFactory; 49 50 import com.vaadin.annotations.Title; 51 import com.vaadin.server.VaadinRequest; 52 import com.vaadin.ui.CssLayout; 53 import com.vaadin.ui.UI; 54 55 /** 56 * A special app which makes at your disposal the Magnolia's Groovy interactive console bypassing the 57 * normal Magnolia's filters chain. This can be useful, for instance, to perform rescue operations on a corrupted Magnolia instance. 58 * <strong>Warning:</strong> All operations are executed in system context, meaning that no security restrictions are enforced which 59 * might expose your data to risk of irreversible damages if you are not aware of what you are doing. In other words, <strong>use it at your own risk</strong>. <br> 60 * To use it, in your <code>web.xml</code> you must explicitly comment out the Magnolia filter chain part and add or uncomment the Vaadin servlet. 61 * For a sample configuration, see the <code>web.xml</code> fragment below: 62 * 63 * <pre> 64 * [...] 65 * <!-- 66 * <filter> 67 * <display-name>Magnolia global filters</display-name> 68 * <filter-name>magnoliaFilterChain</filter-name> 69 * <filter-class>info.magnolia.cms.filters.MgnlMainFilter</filter-class> 70 * </filter> 71 * <filter-mapping> 72 * <filter-name>magnoliaFilterChain</filter-name> 73 * <url-pattern>/*</url-pattern> 74 * <dispatcher>REQUEST</dispatcher> 75 * <dispatcher>FORWARD</dispatcher> 76 * <dispatcher>INCLUDE</dispatcher> 77 * <dispatcher>ERROR</dispatcher> 78 * </filter-mapping> 79 * --> 80 * <servlet> 81 * <servlet-name>Vaadin</servlet-name> 82 * <servlet-class>com.vaadin.server.VaadinServlet</servlet-class> 83 * <init-param> 84 * <description>Groovy Rescue App</description> 85 * <param-name>UI</param-name> 86 * <param-value>info.magnolia.module.groovy.rescue.MgnlGroovyRescueApp</param-value> 87 * </init-param> 88 * </servlet> 89 * <servlet-mapping> 90 * <servlet-name>Vaadin</servlet-name> 91 * <url-pattern>/*</url-pattern> 92 * </servlet-mapping> 93 * [...] 94 * </pre> 95 * 96 * Once configured and having restarted the web container, you can access the console like this 97 * http://server[:port]/contextname 98 * <p> 99 * If you need to restart the app, you can append the Vaadin <code>?restartApplication</code> to the URL. 100 */ 101 102 @Title("Magnolia Groovy Rescue App") 103 public class MgnlGroovyRescueApp extends UI { 104 private static final long serialVersionUID = 222L; 105 106 private static final Logger log = LoggerFactory.getLogger(MgnlGroovyRescueApp.class); 107 108 private CssLayout layout = new CssLayout(); 109 110 @Override 111 protected void init(VaadinRequest request) { 112 log.info("Initializing MgnlGroovyRescueApp..."); 113 log.warn("Setting value of {} to {}", SecuritySupport.class.getName(), RescueSecuritySupport.class.getName()); 114 // following call will implicitly register this implementation. 115 Components.newInstance(RescueSecuritySupport.class); 116 SystemProperty.setProperty(SecuritySupport.class.getName(), RescueSecuritySupport.class.getName()); 117 118 MgnlContext.setInstance(new SingleJCRSessionSystemContext()); 119 120 layout.setSizeFull(); 121 TranslationService translationService = Components.getComponent(TranslationService.class); 122 translationService.reloadMessageBundles(); 123 124 // no notification to send to pulse here 125 Terminal terminal = new Terminal(Components.getComponent(SimpleTranslator.class), true, false, Components.getComponent(MessagesManager.class)); 126 127 layout.addComponent(terminal); 128 setContent(layout); 129 } 130 }