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