From 54f8c657f7790ff31a39d1062a7414d1a76b4f52 Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 20 Jan 2016 18:44:11 +0000 Subject: [PATCH] CCM NG: Finished migiration to new configuration system. Now all jUnit tests have to be checked. git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3809 8810af33-2d31-482b-a856-94f89814c4df --- .../arsdigita/bebop/page/PageTransformer.java | 219 +++++------ .../com/arsdigita/runtime/AbstractConfig.java | 143 ------- .../com/arsdigita/runtime/ConfigError.java | 57 --- .../com/arsdigita/runtime/ConfigRegistry.java | 351 ------------------ .../com/arsdigita/runtime/RegistryConfig.java | 140 ------- .../templating/HostPatternGenerator.java | 51 +-- .../com/arsdigita/templating/Templating.java | 9 +- .../arsdigita/web/BaseApplicationServlet.java | 2 +- .../web/DefaultApplicationFileResolver.java | 8 +- .../com/arsdigita/web/LegacyWebConfig.java | 319 ---------------- .../java/com/arsdigita/web/LoginSignal.java | 1 - .../src/main/java/com/arsdigita/web/URL.java | 29 +- .../src/main/java/com/arsdigita/web/Web.java | 6 +- .../java/com/arsdigita/web/WebConfig.java | 72 +++- .../categorization/Categorization.java | 16 +- .../org/libreccm/categorization/Category.java | 16 +- .../categorization/CategoryManager.java | 11 +- .../categorization/CategoryRepository.java | 7 +- .../org/libreccm/categorization/Domain.java | 13 +- .../categorization/DomainManager.java | 2 +- .../categorization/DomainOwnership.java | 11 +- .../configuration/ConfigurationManager.java | 19 +- .../java/org/libreccm/web/ServletPath.java | 2 +- .../kernel/security/SecurityConfigTest.java | 2 - .../java/com/arsdigita/web/WebConfigTest.java | 12 + .../AuthorizationInterceptorTest.java | 2 - .../security/PermissionCheckerTest.java | 2 - .../security/PermissionManagerTest.java | 2 - .../libreccm/security/RoleManagerTest.java | 2 - .../security/SecuredCollectionTest.java | 2 - .../security/SecuredIteratorTest.java | 2 - .../java/org/libreccm/security/ShiroTest.java | 97 ++--- .../libreccm/security/UserManagerTest.java | 2 - .../ConfigurationManagerTest/log4j2.xml | 21 ++ .../libreccm/security/ShiroTest/log4j2.xml | 17 + ccm-core/src/test/resources/configs/shiro.ini | 10 + 36 files changed, 370 insertions(+), 1307 deletions(-) delete mode 100644 ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java delete mode 100644 ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java delete mode 100644 ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java delete mode 100644 ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java delete mode 100644 ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java create mode 100644 ccm-core/src/test/resources/configs/org/libreccm/configuration/ConfigurationManagerTest/log4j2.xml create mode 100644 ccm-core/src/test/resources/configs/org/libreccm/security/ShiroTest/log4j2.xml create mode 100644 ccm-core/src/test/resources/configs/shiro.ini diff --git a/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java b/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java index df46062e6..b9cfa1c65 100755 --- a/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java +++ b/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java @@ -29,6 +29,7 @@ import com.arsdigita.templating.XSLParameterGenerator; import com.arsdigita.templating.XSLTemplate; import com.arsdigita.util.Assert; import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.web.CCMDispatcherServlet; import com.arsdigita.web.Debugger; import com.arsdigita.web.TransformationDebugger; import com.arsdigita.web.Web; @@ -84,199 +85,199 @@ public class PageTransformer implements PresentationManager { registerXSLParameterGenerator("contextPath", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return request + return request .getContextPath(); - } + } - }); + }); registerXSLParameterGenerator("root-context-prefix", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return Web.getConfig() - .getDispatcherContextPath(); - } + return CCMDispatcherServlet + .getContextPath(); + } - }); + }); registerXSLParameterGenerator("context-prefix", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return Web.getWebContext() + return Web.getWebContext() .getRequestURL() .getContextPath(); - } + } - }); + }); registerXSLParameterGenerator("internal-theme", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return Web.getWebContext() + return Web.getWebContext() .getRequestURL() .getContextPath() + com.arsdigita.web.URL.INTERNAL_THEME_DIR; - } + } - }); + }); registerXSLParameterGenerator("dispatcher-prefix", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return com.arsdigita.web.URL + return com.arsdigita.web.URL .getDispatcherPath(); - } + } - }); + }); registerXSLParameterGenerator("dcp-on-buttons", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - if (BebopConfig.getConfig() + if (BebopConfig.getConfig() .getDcpOnButtons()) { - return "true"; - } else { - return null; + return "true"; + } else { + return null; + } + } - } - - }); + }); registerXSLParameterGenerator("dcp-on-links", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - if (BebopConfig.getConfig() + if (BebopConfig.getConfig() .getDcpOnLinks()) { - return "true"; - } else { - return null; + return "true"; + } else { + return null; + } + } - } - - }); + }); registerXSLParameterGenerator("user-agent", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return request.getHeader( + return request.getHeader( "User-Agent"); - } + } - }); + }); registerXSLParameterGenerator("negotiated-language", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return GlobalizationHelper + return GlobalizationHelper .getNegotiatedLocale() .getLanguage(); - } + } - }); + }); registerXSLParameterGenerator("selected-language", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - Locale selectedLocale - = com.arsdigita.globalization.GlobalizationHelper. - getSelectedLocale(request); - return (selectedLocale != null) - ? selectedLocale + Locale selectedLocale + = com.arsdigita.globalization.GlobalizationHelper + .getSelectedLocale(request); + return (selectedLocale != null) + ? selectedLocale .toString() : ""; - } + } - }); + }); registerXSLParameterGenerator("request-scheme", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return request.getScheme(); - } + return request.getScheme(); + } - }); + }); registerXSLParameterGenerator("server-name", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return request.getServerName(); - } + return request.getServerName(); + } - }); + }); registerXSLParameterGenerator("server-port", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - return Integer.toString( + return Integer.toString( request.getServerPort()); - } + } - }); + }); registerXSLParameterGenerator("host", new XSLParameterGenerator() { - @Override - public String generateValue( + @Override + public String generateValue( HttpServletRequest request) { - if (request.getServerPort() + if (request.getServerPort() == 80) { - return String.format( + return String.format( "%s://%s", request .getScheme(), request .getServerName()); - } else { - return String.format( + } else { + return String.format( "%s://%s:%d", request.getScheme(), request .getServerName(), request .getServerPort()); + } } - } - }); + }); s_log.debug("Static initalizer finished."); } @@ -343,7 +344,7 @@ public class PageTransformer implements PresentationManager { try { return new PrintWriter(new OutputStreamWriter(resp. - getOutputStream(), + getOutputStream(), charset)); } catch (IOException ex) { throw new UncheckedWrapperException(ex); @@ -372,11 +373,11 @@ public class PageTransformer implements PresentationManager { * always be passed to XSLT, which is the value of * req.getWebContextPath(). * - * @param doc the Bebop page to serve - * @param req the servlet request - * @param resp the servlet response + * @param doc the Bebop page to serve + * @param req the servlet request + * @param resp the servlet response * @param params a set of name-value pairs to pass as parameters to the - * Transformer + * Transformer */ public void servePage(final Document doc, final HttpServletRequest req, @@ -393,7 +394,7 @@ public class PageTransformer implements PresentationManager { try { final String charset = Globalization - .getDefaultCharset(DispatcherHelper.getNegotiatedLocale()); + .getDefaultCharset(DispatcherHelper.getNegotiatedLocale()); final String output = req.getParameter("output"); s_log.info("output=" + output); @@ -401,16 +402,16 @@ public class PageTransformer implements PresentationManager { if (output == null) { boolean fancyErrors - = BebopConfig.getConfig().getFancyErrors() + = BebopConfig.getConfig().getFancyErrors() || Boolean.TRUE.equals(req.getAttribute( - FANCY_ERRORS)); + FANCY_ERRORS)); // Get the stylesheet transformer object corresponding to the // current request. final XSLTemplate template = Templating.getTemplate( - req, - fancyErrors, - !Boolean.TRUE.equals(req.getAttribute(CACHE_XSL_NONE))); + req, + fancyErrors, + !Boolean.TRUE.equals(req.getAttribute(CACHE_XSL_NONE))); final PrintWriter writer = getWriter(resp, "text/html", charset); @@ -450,15 +451,15 @@ public class PageTransformer implements PresentationManager { new StreamResult(writer)); } catch (TransformerException ex) { throw new UncheckedWrapperException( - "cannot transform document", ex); + "cannot transform document", ex); } // copy and paste from BasePresentationManager if (KernelConfig.getConfig().isDebugEnabled()) { Document origDoc = (Document) req.getAttribute( - "com.arsdigita.xml.Document"); + "com.arsdigita.xml.Document"); Debugger.addDebugger(new TransformationDebugger(template. - getSource(), template.getDependents())); + getSource(), template.getDependents())); writer.print(Debugger.getDebugging(req)); } @@ -478,11 +479,11 @@ public class PageTransformer implements PresentationManager { // current request. template = Templating.getTemplate(req, Boolean.TRUE.equals(req - .getAttribute( - PageTransformer.FANCY_ERRORS)), + .getAttribute( + PageTransformer.FANCY_ERRORS)), !Boolean.TRUE.equals(req - .getAttribute( - PageTransformer.CACHE_XSL_NONE))); + .getAttribute( + PageTransformer.CACHE_XSL_NONE))); endTransaction(req); } finally { } @@ -490,7 +491,7 @@ public class PageTransformer implements PresentationManager { try { Date now = new Date(); SimpleDateFormat fmt = new SimpleDateFormat( - "yyyy-MM-dd-HH-mm"); + "yyyy-MM-dd-HH-mm"); String prefix = "waf-xsl-" + fmt.format(now); final OutputStream os = resp.getOutputStream(); @@ -509,7 +510,7 @@ public class PageTransformer implements PresentationManager { } } else { throw new IllegalStateException(output - + " is an unknown output"); + + " is an unknown output"); } } finally { } @@ -576,8 +577,8 @@ public class PageTransformer implements PresentationManager { public static String getXSLParameterValue(String name, HttpServletRequest request) { XSLParameterGenerator generator - = (XSLParameterGenerator) s_XSLParameters - .get(name); + = (XSLParameterGenerator) s_XSLParameters + .get(name); if (generator != null) { return generator.generateValue(request); } else { @@ -600,7 +601,7 @@ public class PageTransformer implements PresentationManager { final Map.Entry entry = (Map.Entry) entries.next(); String value = ((XSLParameterGenerator) entry.getValue()). - generateValue(request); + generateValue(request); if (value == null) { // XSL does not like nulls value = ""; diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java b/ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java deleted file mode 100644 index f83501cb2..000000000 --- a/ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.runtime; - -import com.arsdigita.util.parameter.AbstractParameterContext; -import com.arsdigita.util.parameter.ErrorList; -import org.apache.log4j.Logger; - -/** - * AbstractConfig is a base class for groups of customizable - * configuration {@link com.arsdigita.util.parameter parameters}. A - * CCM Developer wishing to add a new group of configuration - * parameters to his application will extend this class and provide a - * public noargs constructer that registers his parameters with the - * superclass. For example: - * - *
- * package com.arsdigita.exampleApp;
- *
- * public final class ExampleConfig extends AbstractConfig {
- *
- *     private Parameter m_string = new StringParameter
- *         ("example.string", Parameter.OPTIONAL, "default");
- *     private Parameter m_integer = new IntegerParameter
- *         ("example.integer", Parameter.OPTIONAL, new Integer(0));
- *     private Parameter m_boolean = new BooleanParameter
- *         ("example.boolean", Parameter.OPTIONAL, Boolean.TRUE);
- *
- *     public ExampleConfig() {
- *         register(m_string);
- *         register(m_integer);
- *         register(m_boolean);
- *         loadInfo();
- *     }
- *
- *     public String getString() {
- *         return (String) get(m_string);
- *     }
- *
- *     public int getInteger() {
- *         return ((Integer) get(m_integer)).intValue();
- *     }
- *
- *     public boolean getBoolean() {
- *         return Boolean.TRUE.equals(get(m_boolean));
- *     }
- *
- * }
- * 
- * - * When this pattern is followed, the resulting subclass of abstract - * config may be used by developers writing java code to access the - * values of customizable configuration parameters in a convenient and - * type safe manner. In addition, the very same class is also usable - * by the ccm configuration tools to allow customization and - * validation of the new parameters. - * - * @author Justin Ross <jross@redhat.com> - * @version $Id$ - */ -public abstract class AbstractConfig extends AbstractParameterContext { - - private static final Logger s_log = Logger.getLogger - (AbstractConfig.class); - - /** - * Default constructor for subclasses. - */ - protected AbstractConfig() {} - - /** - * Loads this AbstractConfig object with values from the default - * configuration registry. Any errors encountered during - * unmarshaling and loading of configuration values are added to - * the errors ErrorList. This method should not be - * called from the constructor of a config object since the ccm - * configuration tools need to be able to construct empty config - * objects. - * - * @param errors The ErrorList used to record errors during - * unmarshaling and loading. - * - * @see ConfigRegistry - */ - public final void load(ErrorList errors) { - ConfigRegistry reg = new ConfigRegistry(); - reg.load(this, errors); - } - - /** - * Invokes the {@link #load(ErrorList)} method with a new and - * empty ErrorList for accumulating errors, and returns that - * ErrorList. This method can be used in combination with the - * {@link ErrorList#check()} method to load and assert that this - * configuration object is valid in one simple idiom. For example: - * - *
-     *     ExampleConfig conf = new ExampleConfig();
-     *     conf.load().check();
-     *     ...
-     * 
- * - * @return Errors that may have been encountered during - * configuration loading. - * - * @see #load(ErrorList) - */ - public final ErrorList load() { - ErrorList errs = new ErrorList(); - load(errs); - return errs; - } - - /** - * @deprecated Use @{link #load()} instead. - */ - public final ErrorList load(final String resource) { - return load(); - } - - /** - * @deprecated Use @{link #load()} instead. - */ - public final ErrorList require(final String resource) { - return load(); - } -} diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java b/ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java deleted file mode 100644 index 5f98d6963..000000000 --- a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.runtime; - -import com.arsdigita.util.Assert; -import org.apache.log4j.Logger; - -/** - * Subject to change. - * - * An error to indicate invalid configurations. - * - * Usage: throw new ConfigError( "message" ); - * - * @author Justin Ross <jross@redhat.com> - */ -public class ConfigError extends Error { - - private static final long serialVersionUID = 5224480607138738741L; - - /** - * Constructs a new configuration error with the content - * message. - * - * @param message A String describing what's wrong; it cannot - * be null - */ - public ConfigError(final String message) { - super(message); - - Assert.exists(message, String.class); - } - - /** - * Constructs a new configuration error with a default message. - */ - public ConfigError() { - super("Configuration is invalid"); - } - -} diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java b/ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java deleted file mode 100644 index aa702e279..000000000 --- a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.runtime; - -import com.arsdigita.util.Classes; -import com.arsdigita.util.JavaPropertyReader; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.util.parameter.ErrorList; -import com.arsdigita.util.parameter.ParameterContext; -import com.arsdigita.util.parameter.ParameterReader; -import com.arsdigita.xml.XML; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.DefaultHandler; - -import org.apache.log4j.Logger; - -/** - * The ConfigRegistry class maps between config classes (subclasses of - * {@link com.arsdigita.runtime.AbstractConfig}), and a location used - * for persisting the values in a config class. - * - * The ConfigRegistry also stores the set of configured packages for a - * particular CCMResourceManager instance. - * Additionally it stores a list of URLs for parent configurations that are - * used for defaulting values not present in the local configuration. - * This mapping is maintained and extended by CCMResourceManager developers through - * the use of an XML configuration file placed in the src tree for a - * particular package. If a particular package is configured, the - * ConfigRegistry class will look in the classpath for a registry - * configuration file named package-key.config, and parse the - * file according to the following specification: - * - *
- * <?xml version="1.0" encoding="utf-8"?>
- * <registry>
- *   ...
- *   <config class="CLASSNAME"
- *           storage="FILENAME"/>
- *   ...
- * </registry>
- * 
- * - * The mappings stored by this ConfigRegistry will then be extended to include - * the classes and storage locations specified in the configuration file. These - * mappings are then used by the ConfigRegistry instance to load config objects. - * - * @author Rafael H. Schloming <rhs@mit.edu> - * @version $Revision$ $Date$ - * @version $Id$ - **/ -public class ConfigRegistry { - - private static final Logger s_log = Logger.getLogger(ConfigRegistry.class); - /** - * Base url for registry location(s). - * (i.e. $CATALINA_HOME/webapps/$context/WEB-INF/conf/registry in a - * standard installation) - */ - private URL m_url; - private ClassLoader m_loader; - private List m_packages = new ArrayList(); - private List m_contexts = new ArrayList(); - private Map m_storage = new HashMap(); - private List m_loaders = new ArrayList(); - - /** - * Constructs a new config registry that will resolve all - * locations relative to url, and use - * loader when searching the classpath for registry - * configuration files. - * - * @param url The base url for registry locations. - * @param loader The ClassLoader to use for retrieving registry - * configuration files. - **/ - public ConfigRegistry(URL url, ClassLoader loader) { - m_url = url; - m_loader = loader; - addContext(RegistryConfig.class, "registry.properties"); - initialize(m_url, new ErrorList()); - } - - /** - * Convenience class which invokes {@link #ConfigRegistry(URL, ClassLoader)} - * defaulting the loader to the current context class loader. - * - * @see Thread#getContextClassLoader() - * - * @param url The base url for registry locations. - */ - public ConfigRegistry(URL url) { - this(url, Thread.currentThread().getContextClassLoader()); - } - - /** - * Convenience class which invokes {@link #ConfigRegistry(URL, ClassLoader)} - * defaulting the URL to - * new File(System.getProperty("ccm.conf")).toURL(). The value - * of the ccm.conf system property may or may not include a trailing slash. - * - * @param loader The ClassLoader to use when searching for - * registry configuration files. - */ - public ConfigRegistry(ClassLoader loader) { - this(CCMResourceManager.getConfigURL(), loader); - } - - /** - * Invokes {@link #ConfigRegistry(URL)} defaulting the URL to new - * File(System.getProperty("ccm.conf")).toURL(). The value of the - * ccm.conf system property may or may not include a trailing slash. - */ - public ConfigRegistry() { - this(CCMResourceManager.getConfigURL()); - } - - /** - * - * @param url Base url for registry location(s). - * @param errs Errorlist - */ - private void initialize(URL url, ErrorList errs) { - - ClassLoader ldr = new URLClassLoader(new URL[]{url}, null); - - RegistryConfig rc = new RegistryConfig(); - load(rc, errs, ldr); - - String[] packages = rc.getPackages(); - URL[] parents = rc.getParents(); - - for (int i = 0; i < packages.length; i++) { - if (!m_packages.contains(packages[i])) { - initialize(packages[i]); - } - } - - for (int i = parents.length - 1; i >= 0; i--) { - initialize(parents[i], errs); - } - - m_loaders.add(ldr); - } - - /** - * This method is not supported API. - */ - public final void initialize(String key) { - s_log.debug(String.format("Initalizing for key '%s'", key)); - if (m_packages.contains(key)) { - throw new IllegalArgumentException("already loaded: " + key); - } - - InputStream is = m_loader.getResourceAsStream(key + ".config"); - if (is == null) { - throw new UncheckedWrapperException(String.format("No .config for key '%s' found", key)); - } - if (is != null) { - try { - XML.parse(is, new ConfigRegistryParser()); - m_packages.add(key); - } finally { - try { - is.close(); - } catch (IOException e) { - throw new UncheckedWrapperException(e); - } - } - } - } - - /** - * Returns the list of configured packages for this ConfigRegistry. - * - * @return A list of package keys represented as Strings. - **/ - public List getPackages() { - return m_packages; - } - - /** - * Returns a list of config classes for this ConfigRegistry. - * - * @return A list of Class objects. - **/ - public List getContexts() { - return m_contexts; - } - - /** - * Returns the relative location used to store values for the - * given config class. - * - * @param context a subclass of {@link - * com.arsdigita.runtime.AbstractConfig} - * - * @return the relative storage location for context - * - * @throws IllegalArgumentException if this ConfigRegistry does - * not contain a mapping for context - **/ - public String getStorage(Class context) { - if (!m_contexts.contains(context)) { - throw new IllegalArgumentException("no such context: " + context - + "; available contexts=" - + m_contexts - + "; context->storage map: " - + m_storage); - } - return (String) m_storage.get(context); - } - - private void addContext(Class context, String storage) { - s_log.debug(String.format("Adding context '%s', storage '%s'...", - context.getName(), storage)); - m_contexts.add(context); - m_storage.put(context, storage); - } - - /** - * Returns true if this ConfigRegistry contains a mapping for - * context - * - * @param context a subclass of {@link - * com.arsdigita.runtime.AbstractConfig} - * - * @return true if this ConfigRegistry contains a mapping for - * context - **/ - public boolean isConfigured(Class context) { - return m_contexts.contains(context); - } - - /** - * Loads the given config object from the correct location based - * on its class. Defaults all values based on the value of the - * waf.config.parents parameter. Any errors - * encountered during loading are reported in the given ErrorList. - * - * @param ctx the config object to load - * @param errs used to accumulate errors during loading - * - * @throws IllegalArgumentException if this ConfigRegistry does - * not contain a mapping for ctx.getClass() - **/ - public void load(ParameterContext ctx, ErrorList errs) { - for (Iterator it = m_loaders.iterator(); it.hasNext();) { - ClassLoader ldr = (ClassLoader) it.next(); - load(ctx, errs, ldr); - } - } - - /** - * Searches through this ConfigRegistry and its parents for the - * given resource. If it is not found it is also searched for in - * the classpath specified by the loader passed to this - * ConfigRegistry on construction. This may be used to load - * configuration information that is not stored in a config - * object. - * - * @param resource the path to the resource - * - * @return an input stream containing the contents of the resource - * or null if the resource is not found - */ - public InputStream load(String resource) { - for (int i = m_loaders.size() - 1; i >= 0; i--) { - ClassLoader ldr = (ClassLoader) m_loaders.get(i); - InputStream is = ldr.getResourceAsStream(resource); - if (is != null) { - return is; - } - } - - return m_loader.getResourceAsStream(resource); - } - - private void load(ParameterContext ctx, ErrorList errs, ClassLoader ldr) { - Properties props = getProperties(ldr, getStorage(ctx.getClass())); - ParameterReader reader = new JavaPropertyReader(props); - ctx.load(reader, errs); - } - - private Properties getProperties(ClassLoader ldr, String resource) { - Properties props = new Properties(); - InputStream is = ldr.getResourceAsStream(resource); - if (is != null) { - try { - props.load(is); - } catch (IOException e) { - throw new UncheckedWrapperException(e); - } finally { - try { - is.close(); - } catch (IOException e) { - throw new UncheckedWrapperException(e); - } - } - } - return props; - } - - private class ConfigRegistryParser extends DefaultHandler { - - @Override - public void startElement(String uri, String localName, String qn, - Attributes attrs) { - if (localName.equals("config")) { - String klass = attrs.getValue(uri, "class"); - String storage = attrs.getValue(uri, "storage"); - // XXX: Is there a better way to handle errors that - // includes line number information? - if ((klass == null) || (storage == null)) { - throw new IllegalArgumentException( - "class and storage attributes are required"); - } - - Class context = Classes.loadClass(klass); - addContext(context, storage); - } - } - } -} diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java b/ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java deleted file mode 100644 index 2b6c14236..000000000 --- a/ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.runtime; - -// import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.StringUtils; -import com.arsdigita.util.parameter.ErrorList; -import com.arsdigita.util.parameter.Parameter; -import com.arsdigita.util.parameter.ParameterError; -import com.arsdigita.util.parameter.StringParameter; -import java.net.MalformedURLException; -import java.net.URL; - - -/** - * A config class used by the registry itself. - * - * Contains the parameters: - * waf.config.packages: comma separated package-key list of installed packages - * waf.config.parents : - * - * @author Rafael H. Schloming <rhs@mit.edu> - * @version $Id$ - */ -public class RegistryConfig extends AbstractConfig { - - /** - * Helper method to unmarshal parameter values. - * @param str A String of comma separated values - * @return StringArray of the values - */ - private static String[] array(String str) { - if (str == null) { - return null; - } else { - return StringUtils.split(str, ','); - } - } - - /** - * List of installed packages. - * - * Provided as a comma separated package-key list of installed packages. - * The parameter overwrites the default marshal and unmarshal methods to - * allow the String parameter to hold a list of values. - * - * TODO: Replace the type String parameter by StringArray parameter which - * provides exactly the required functionality (doesn't it?). - */ - private Parameter m_packages = new StringParameter - ("waf.config.packages", Parameter.OPTIONAL, new String[0]) { - @Override - protected Object unmarshal(String value, ErrorList errs) { - return array(value); - } - - @Override - protected String marshal(Object obj) { - return StringUtils.join((String[]) obj, ','); - } - }; - - /** - * List of parameter values, purpose currently unkown. - * - * The parameter overwrites the default marshal and unmarshal methods to - * allow the String parameter to hold a list of values. - */ - private Parameter m_parents = new StringParameter - ("waf.config.parents", Parameter.OPTIONAL, new URL[0]) { - @Override - protected Object unmarshal(String value, ErrorList errs) { - String[] strs = array(value); - URL[] result = new URL[strs.length]; - for (int i = 0; i < result.length; i++) { - try { - result[i] = new URL(strs[i]); - } catch (MalformedURLException e) { - errs.add(new ParameterError(this, e)); - } - } - if (!errs.isEmpty()) { - return null; - } - return result; - } - - protected String marshal(Object obj) { - URL[] urls = (URL[]) obj; - String[] strs = new String[urls.length]; - for (int i = 0; i < strs.length; i++) { - strs[i] = urls[i].toExternalForm(); - } - return StringUtils.join(strs, ','); - } - }; - - /** - * Constructs a new and empty config object. - */ - public RegistryConfig() { - register(m_packages); - register(m_parents); - } - - /** - * Returns the value of the waf.config.packages parameter. - * - * @return the value of the waf.config.packages parameter - */ - public String[] getPackages() { - return (String[]) get(m_packages); - } - - /** - * Returns the value of the waf.config.parents parameter. - * - * @return the value of the waf.config.parents parameter - */ - public URL[] getParents() { - return (URL[]) get(m_parents); - } - -} diff --git a/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java b/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java index aed3c1114..ab25c9d93 100755 --- a/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java +++ b/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java @@ -20,48 +20,53 @@ package com.arsdigita.templating; import com.arsdigita.util.servlet.HttpHost; import com.arsdigita.web.Web; +import com.arsdigita.web.WebConfig; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; - /** - * Generates a set of patterns corresponding to the current - * host name. (actually just retrieves the current hostname from configuration - * file, StringArray returned is for sake of methods consistency) + * Generates a set of patterns corresponding to the current host name. (actually + * just retrieves the current hostname from configuration file, StringArray + * returned is for sake of methods consistency) */ public class HostPatternGenerator implements PatternGenerator { - /** Internal logger instance to faciliate debugging. Enable logging output - * by editing /WEB-INF/conf/log4j.properties int the runtime environment - * and set com.arsdigita.templating.HostPatternGenerator=DEBUG - * by uncommenting or adding the line. */ - private static final Logger s_log = - Logger.getLogger(HostPatternGenerator.class); + /** + * Internal logger instance to faciliate debugging. Enable logging output by + * editing /WEB-INF/conf/log4j.properties int the runtime environment and + * set com.arsdigita.templating.HostPatternGenerator=DEBUG by uncommenting + * or adding the line. + */ + private static final Logger s_log = Logger.getLogger( + HostPatternGenerator.class); /** - * Looks up the hostname from configuration and returns it as String. - * The Return type is (unneccessarily) String[] due to the current API, but + * Looks up the hostname from configuration and returns it as String. The + * Return type is (unneccessarily) String[] due to the current API, but * currently never returns more than just one value (one hostname:port). - * - * @param key placeholder from the pattern string, without surrounding - * colons, constantly "host" here. - * @param req current HttpServletRequest - * @return Hostname (including port if any), retrieved from CCM - * configuration + * + * @param key placeholder from the pattern string, without surrounding + * colons, constantly "host" here. + * @param req current HttpServletRequest + * + * @return Hostname (including port if any), retrieved from CCM + * configuration */ @Override public String[] generateValues(String key, HttpServletRequest req) { - HttpHost host = Web.getConfig().getHost(); - String hostName = host.toString(); + final HttpHost host = new HttpHost(WebConfig.getConfig().getHostName(), + WebConfig.getConfig().getHostPort()); + final String hostName = host.toString(); if (s_log.isDebugEnabled()) { - s_log.debug("Generating Values for key: " + key + " [" + - "Hostname retrieved: >>" + hostName + "<<]"); + s_log.debug("Generating Values for key: " + key + " [" + + "Hostname retrieved: >>" + hostName + "<<]"); } - return new String[] { host.toString() }; + return new String[]{host.toString()}; } + } diff --git a/ccm-core/src/main/java/com/arsdigita/templating/Templating.java b/ccm-core/src/main/java/com/arsdigita/templating/Templating.java index ca5473502..75f7109c0 100755 --- a/ccm-core/src/main/java/com/arsdigita/templating/Templating.java +++ b/ccm-core/src/main/java/com/arsdigita/templating/Templating.java @@ -25,6 +25,7 @@ import com.arsdigita.util.Exceptions; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.servlet.HttpHost; import com.arsdigita.web.Web; +import com.arsdigita.web.WebConfig; import com.arsdigita.xml.Document; import com.arsdigita.xml.Element; @@ -346,7 +347,9 @@ public class Templating { * to a servlet which manages database retrieval. */ static URL transformURL(URL url) { - HttpHost self = Web.getConfig().getHost(); + final WebConfig webConfig = WebConfig.getConfig(); + final HttpHost self = new HttpHost(webConfig.getHostName(), + webConfig.getHostPort()); /** * Indicates whether url refers to a local resource inside the running @@ -427,11 +430,9 @@ public class Templating { } } else // url is not the (local) running CCM host, no transformation // is done - { - if (s_log.isDebugEnabled()) { + if (s_log.isDebugEnabled()) { s_log.debug("URL " + url + " is not local"); } - } return url; // returns the original, unmodified url here } diff --git a/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java b/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java index 8597c3a5e..a2eb2fad5 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java @@ -20,8 +20,8 @@ package com.arsdigita.web; import org.apache.log4j.Logger; import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.web.CcmApplication; import org.libreccm.web.ApplicationRepository; +import org.libreccm.web.CcmApplication; import java.io.IOException; diff --git a/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java b/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java index 042b586b3..9941daccd 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java +++ b/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java @@ -18,13 +18,13 @@ */ package com.arsdigita.web; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.RequestDispatcher; - import org.apache.log4j.Logger; import org.libreccm.web.CcmApplication; +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + /** * The default implementation deals with templates files belonging to a specific diff --git a/ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java b/ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java deleted file mode 100644 index 40a48b876..000000000 --- a/ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2015 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.web; - -import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.parameter.BooleanParameter; -import com.arsdigita.util.parameter.EnumerationParameter; -import com.arsdigita.util.parameter.ErrorList; -import com.arsdigita.util.parameter.Parameter; -import com.arsdigita.util.parameter.ParameterError; -import com.arsdigita.util.parameter.SingletonParameter; -import com.arsdigita.util.parameter.StringArrayParameter; -import com.arsdigita.util.parameter.StringParameter; -import com.arsdigita.util.servlet.HttpHost; -import com.arsdigita.util.servlet.HttpHostParameter; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * A record containing server-session scoped configuration properties. - * - * Accessors of this class may return null. Developers should take care to trap - * null return values in their code. - * - * @see com.arsdigita.web.Web - * @author Justin Ross <jross@redhat.com> - * @author Jens Pelzetter - */ -public class LegacyWebConfig extends AbstractConfig { - - private static final Logger LOGGER = LogManager.getLogger(LegacyWebConfig.class); - - private static LegacyWebConfig config; - - /** - * Returns the singleton configuration record for the content section - * environment. - * - * @return The CMSConfig record; it cannot be null - */ - public static synchronized LegacyWebConfig getInstanceOf() { - if (config == null) { - config = new LegacyWebConfig(); - config.load(); - } - return config; - } - - // ///////////////////////////////////////////////////////////////////////// - // Configuration parameter section - // ///////////////////////////////////////////////////////////////////////// - /** - * Determines what HTTP scheme prefix is used by default to generate URLs - * (either http od https) - */ - private final Parameter m_scheme = new DefaultSchemeParameter( - "waf.web.default_scheme", - Parameter.REQUIRED, "http"); - /** - * Sets the name and port that users of a site will see in URLs generated by - * CCM for the site. This is a required parameter during installation, e.g. - * example.com:80 - */ - private final Parameter m_server = new HttpHostParameter("waf.web.server"); - /** - * Name and port that users of a site will see in secure URLs generated by - * CCM for the site. As an example: example.com:443 - */ - private final Parameter m_secureServer = new HttpHostParameter( - "waf.web.secure_server", - Parameter.OPTIONAL, null); - /** - * The name of your website, for use in page footers for example. It's not - * necessarily the URL but rather a title, e.g. "House of HTML". If not - * specified set to the server's URL. - */ - private final Parameter m_site = new StringParameter("waf.web.site_name", - Parameter.OPTIONAL, - null) { - - @Override - public final Object getDefaultValue() { - final HttpHost host = getServer(); - if (host == null) { - return null; - } else { - return host.toString(); - } - } - - }; - /** - * Sets the name and port of the machine on which the CCM instance is - * running. Used to fetch some resources by a local URL avoiding external - * internet traffic (and delay). If not specified set to the servers's name - * redirecting all traffic to external internet address. - */ - private final Parameter m_host = new HttpHostParameter("waf.web.host", - Parameter.OPTIONAL, - null) { - - @Override - public final Object getDefaultValue() { - return getServer(); - } - - }; - - /** - * List of URLs which accessed by insecure (normal HTTP) connection produce - * a redirect to a HTTPS equivalent. List is comma separated. - */ - private final Parameter m_secureRequired = new StringArrayParameter( - "waf.web.secure_required", Parameter.OPTIONAL, null); - /** - * List of URLs which accessed by secure (HTTPS) connection produce a - * redirect to a HTTP equivalent. List is comma separated. - */ - private final Parameter m_secureSwitchBack = new StringArrayParameter( - "waf.web.secure_switchback", Parameter.OPTIONAL, null); - - /** - * Dispatcher servlet path. It's the prefix to the main entry point for any - * application request (CCMDispatcherServlet). By default /ccm - */ - private final Parameter m_servlet = new StringParameter( - "waf.web.dispatcher_servlet_path", Parameter.REQUIRED, "/ccm"); - - /** - * Specifies by name which implementation of ApplicationFileResolver is used - * to dynamically resolve static files. By default - * DefaultApplicationFileResolver() is used. - */ - private final Parameter m_resolver = new SingletonParameter( - "waf.web.application_file_resolver", - Parameter.OPTIONAL, - new DefaultApplicationFileResolver()); - - private final Parameter m_deactivate_cache_host_notifications - = new BooleanParameter( - "waf.web.deactivate_cache_host_notifications", - Parameter.OPTIONAL, Boolean.FALSE); - - private final Parameter m_dynamic_host_provider = new StringParameter( - "waf.web.dynamic_host_provider", - Parameter.OPTIONAL, ""); - - /** - * Constructor, but do NOT instantiate this class directly, use - * getInstanceOf() instead. (Singleton pattern!) - * - */ - public LegacyWebConfig() { - - register(m_scheme); - register(m_server); - register(m_secureServer); - register(m_site); - register(m_host); - register(m_secureRequired); - register(m_secureSwitchBack); - register(m_servlet); - register(m_resolver); - register(m_deactivate_cache_host_notifications); - register(m_dynamic_host_provider); - - loadInfo(); - } - - public final String getDefaultScheme() { - return (String) get(m_scheme); - } - - public final HttpHost getServer() { - return (HttpHost) get(m_server); - } - - public final HttpHost getSecureServer() { - return (HttpHost) get(m_secureServer); - } - - public final boolean isSecureRequired(String uri) { - String[] secured = (String[]) get(m_secureRequired); - if (secured != null) { - for (int i = 0, n = secured.length; i < n; i++) { - if (uri.startsWith(secured[i])) { - return true; - } - } - } - return false; - } - - public final boolean isNonSecureSwitchRequired(String uri) { - String[] switchBack = (String[]) get(m_secureSwitchBack); - if (switchBack != null) { - for (int i = 0, n = switchBack.length; i < n; i++) { - if (uri.startsWith(switchBack[i])) { - return true; - } - } - } - return false; - } - - public final String getDispatcherServletPath() { - return (String) get(m_servlet); - } - - public final ApplicationFileResolver getApplicationFileResolver() { - return (ApplicationFileResolver) get(m_resolver); - } - - public final HttpHost getHost() { - return (HttpHost) get(m_host); - } - - final void setHost(final HttpHost host) { - set(m_host, host); - } - - public final String getSiteName() { - return (String) get(m_site); - } - - /** - * - * @return - * @deprecated use Web.getContextPath() instead. The installation context - * must no longer manually configured - */ - // NO LONGER configured by configuration option but determined at runtime - // by CCMDispatcherServlet itself. - // // dispatcherContextPath option in old Initializer, set to "" - // m_context = new StringParameter - // ("waf.web.dispatcher_context_path", Parameter.REQUIRED, ""); - public final String getDispatcherContextPath() { - // return (String) get(m_context); - return CCMDispatcherServlet.getContextPath(); - } - - - private static class DispatcherServletPathParameter - extends StringParameter { - - DispatcherServletPathParameter(final String name) { - super(name); - } - - @Override - protected void doValidate(final Object value, final ErrorList errors) { - final String string = (String) value; - - if (string.endsWith("/")) { - final ParameterError error = new ParameterError(this, - "The value must not end in a '/'"); - errors.add(error); - } - } - - } - - private static class DefaultSchemeParameter extends EnumerationParameter { - - DefaultSchemeParameter(final String name, - final int multiplicity, - final Object defaalt) { - super(name, multiplicity, defaalt); - - put("http", "http"); - put("https", "https"); - } - - } - - protected DynamicHostProvider dhProvider = null; - protected boolean dhProviderInited = false; - - public final DynamicHostProvider getDynamicHostProvider() { - if (dhProviderInited == false) { - String classname = (String) get(m_dynamic_host_provider); - if (classname != null) { - try { - Class klass = Class.forName(classname); - dhProvider = (DynamicHostProvider) klass.newInstance(); - } catch (Exception e) { - LOGGER.error( - "Could not instantiate DynamicHostProvider using classname : " - + classname, e); - } - } - dhProviderInited = true; - } - return dhProvider; - } - - public final boolean getDeactivateCacheHostNotifications() { - return ((Boolean) get(m_deactivate_cache_host_notifications)) - .booleanValue(); - } - -} diff --git a/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java b/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java index cf716bc05..c1f5998ad 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java +++ b/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java @@ -19,7 +19,6 @@ package com.arsdigita.web; import javax.servlet.http.HttpServletRequest; -import org.apache.log4j.Logger; /** *

diff --git a/ccm-core/src/main/java/com/arsdigita/web/URL.java b/ccm-core/src/main/java/com/arsdigita/web/URL.java index f982fdc66..c0c92b1bc 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/URL.java +++ b/ccm-core/src/main/java/com/arsdigita/web/URL.java @@ -612,11 +612,11 @@ public class URL { * @return a URL to your server's root path */ public static final URL root() { - final LegacyWebConfig config = Web.getConfig(); + final WebConfig config = Web.getConfig(); URL url = new URL(config.getDefaultScheme(), - config.getServer().getName(), - config.getServer().getPort(), + config.getServerName(), + config.getServerPort(), "", "/", null, @@ -679,7 +679,7 @@ public class URL { public static final URL there(final HttpServletRequest sreq, final String path, final ParameterMap params) { - final LegacyWebConfig config = Web.getConfig(); + final WebConfig config = Web.getConfig(); Assert.exists(sreq, "HttpServletRequest sreq"); Assert.exists(config, "WebConfig config"); @@ -693,7 +693,7 @@ public class URL { return new URL(sreq.getScheme(), host.getName(), host.getPort(), - config.getDispatcherContextPath(), + CCMDispatcherServlet.getContextPath(), config.getDispatcherServletPath(), path, params); @@ -715,9 +715,8 @@ public class URL { public static final URL dynamicHostThere(final HttpServletRequest sreq, final String path, final ParameterMap params) { - final LegacyWebConfig config = Web.getConfig(); + final WebConfig config = Web.getConfig(); DynamicHostProvider provider = Web.getConfig().getDynamicHostProvider(); - if (provider == null) { return there(sreq, path, params); } @@ -734,7 +733,7 @@ public class URL { return new URL(sreq.getScheme(), provider.getName(), provider.getPort(), - config.getDispatcherContextPath(), + CCMDispatcherServlet.getContextPath(), config.getDispatcherServletPath(), path, params); @@ -755,7 +754,7 @@ public class URL { */ public static final URL there(final HttpServletRequest sreq, final String path) { - final LegacyWebConfig config = Web.getConfig(); + final WebConfig config = Web.getConfig(); Assert.exists(sreq, "HttpServletRequest sreq"); Assert.exists(config, "WebConfig config"); @@ -765,7 +764,7 @@ public class URL { return new URL(sreq.getScheme(), host.getName(), host.getPort(), - config.getDispatcherContextPath(), + CCMDispatcherServlet.getContextPath(), config.getDispatcherServletPath(), path, (ParameterMap) s_empty.get()); @@ -847,11 +846,11 @@ public class URL { */ public static final URL there(final String path, final ParameterMap params) { - final LegacyWebConfig config = Web.getConfig(); + final WebConfig config = Web.getConfig(); return new URL(config.getDefaultScheme(), - config.getServer().getName(), - config.getServer().getPort(), + config.getServerName(), + config.getServerPort(), "", config.getDispatcherServletPath(), path, @@ -949,10 +948,10 @@ public class URL { * @return */ public static String getDispatcherPath() { - final LegacyWebConfig config = Web.getConfig(); + final WebConfig config = Web.getConfig(); final HttpServletRequest req = Web.getRequest(); - final String context = config.getDispatcherContextPath(); + final String context = CCMDispatcherServlet.getContextPath(); final String servlet = config.getDispatcherServletPath(); if (req == null) { diff --git a/ccm-core/src/main/java/com/arsdigita/web/Web.java b/ccm-core/src/main/java/com/arsdigita/web/Web.java index 5055ebaf9..7a54453ea 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/Web.java +++ b/ccm-core/src/main/java/com/arsdigita/web/Web.java @@ -47,7 +47,7 @@ public class Web { */ private static final Logger s_log = Logger.getLogger(Web.class); - private static final LegacyWebConfig s_config = LegacyWebConfig.getInstanceOf(); + private static final WebConfig s_config = WebConfig.getConfig(); private static final ThreadLocal s_request = new InternalRequestLocal(); private static final ThreadLocal s_servletContext @@ -90,9 +90,9 @@ public class Web { /** * Provide the configuration record for code in the web package. * - * @return A LegacyWebConfig configuration record; it cannot be null + * @return A WebConfig configuration record; it cannot be null */ - public static LegacyWebConfig getConfig() { + public static WebConfig getConfig() { return s_config; } diff --git a/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java b/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java index 415bc453f..a1235c60d 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java +++ b/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java @@ -29,8 +29,6 @@ import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; import java.util.StringJoiner; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.validation.ConstraintViolation; import javax.validation.Validation; @@ -74,7 +72,7 @@ public final class WebConfig { private Boolean deactiveCacheHostNotifications = false; @Setting - private String dynamicHostProvider; + private String dynamicHostProviderClass; public static WebConfig getConfig() { final CdiUtil cdiUtil = new CdiUtil(); @@ -95,6 +93,14 @@ public final class WebConfig { return server; } + public String getServerName() { + return server.split(":")[0]; + } + + public Integer getServerPort() { + return Integer.parseInt(server.split(":")[1]); + } + public void setServer( @Pattern(regexp = "[\\w-.]*:[0-9]{1,5}") final String server) { final Method method; @@ -122,6 +128,14 @@ public final class WebConfig { return secureServer; } + public String getSecureServerName() { + return secureServer.split(":")[0]; + } + + public Integer getSecureServerPort() { + return Integer.parseInt(secureServer.split(":")[1]); + } + public void setSecureServer( @Pattern(regexp = "[\\w-.]*:[0-9]{1,5}") final String secureServer) { final Method method; @@ -157,9 +171,17 @@ public final class WebConfig { return host; } + public String getHostName() { + return host.split(":")[0]; + } + + public Integer getHostPort() { + return Integer.parseInt(host.split(":")[1]); + } + public void setHost( @Pattern(regexp = "[\\w-.]*:[0-9]{1,5}") final String host) { - + final Method method; try { method = getClass().getMethod("setHost", String.class); @@ -243,12 +265,46 @@ public final class WebConfig { this.deactiveCacheHostNotifications = deactiveCacheHostNotifications; } - public String getDynamicHostProvider() { - return dynamicHostProvider; + public String getDynamicHostProviderClass() { + return dynamicHostProviderClass; } - public void setDynamicHostProvider(final String dynamicHostProvider) { - this.dynamicHostProvider = dynamicHostProvider; + public DynamicHostProvider getDynamicHostProvider() { + try { + @SuppressWarnings("unchecked") + final Class clazz + = (Class) Class + .forName(dynamicHostProviderClass); + return clazz.newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { + throw new UncheckedWrapperException( + String.format("Failed to create instance of DynamicHostProvider" + + "implenentation \"%s\".", + dynamicHostProviderClass), + ex); + } + } + + public void setDynamicHostProviderClass( + final String dynamicHostProviderClass) { + + try { + final Class clazz = Class.forName(dynamicHostProviderClass); + if (!DynamicHostProvider.class.isAssignableFrom(clazz)) { + throw new IllegalArgumentException( + String.format("Provided class \"%s\" is not an" + + "implementation of the interface \"%s\".", + dynamicHostProviderClass, + DynamicHostProvider.class.getName())); + } + } catch (ClassNotFoundException ex) { + throw new IllegalArgumentException( + String.format("Unable to retrieve class \"%s\".", + dynamicHostProviderClass), + ex); + } + + this.dynamicHostProviderClass = dynamicHostProviderClass; } private Set> validateHostParameter( diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java b/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java index 3f3cfb1da..83ce367f7 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java @@ -18,25 +18,23 @@ */ package org.libreccm.categorization; +import static org.libreccm.core.CoreConstants.*; + +import org.libreccm.core.CcmObject; + import java.io.Serializable; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import org.libreccm.core.CcmObject; - -import static org.libreccm.core.CoreConstants.*; - -import java.util.Objects; - import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.Table; /** * Association class describing the association between a category and an diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Category.java b/ccm-core/src/main/java/org/libreccm/categorization/Category.java index a525e6e0a..78ea37175 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Category.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Category.java @@ -18,33 +18,29 @@ */ package org.libreccm.categorization; +import static org.libreccm.core.CoreConstants.*; + import org.hibernate.validator.constraints.NotBlank; import org.libreccm.core.CcmObject; - -import static org.libreccm.core.CoreConstants.*; +import org.libreccm.l10n.LocalizedString; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Objects; import javax.persistence.AssociationOverride; import javax.persistence.Column; import javax.persistence.Embedded; - import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; -import javax.persistence.Table; - -import org.libreccm.l10n.LocalizedString; - -import java.util.Collections; -import java.util.Objects; - import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; +import javax.persistence.Table; import javax.validation.constraints.Pattern; /** diff --git a/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java b/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java index c423fc3d4..ca63c2434 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java @@ -18,9 +18,12 @@ */ package org.libreccm.categorization; -import java.util.List; - +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.libreccm.core.CcmObject; +import org.libreccm.core.CcmObjectRepository; + +import java.util.List; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; @@ -28,10 +31,6 @@ import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.TypedQuery; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.core.CcmObjectRepository; - /** * The {@code CategoryManager} provides several helper methods for managing * categories, their sub categories and the objects assigned to a categories. diff --git a/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java b/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java index 759c7c094..b0cf9f3ad 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java @@ -18,6 +18,9 @@ */ package org.libreccm.categorization; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.FormattedMessage; import org.libreccm.core.AbstractEntityRepository; import java.util.List; @@ -28,10 +31,6 @@ import javax.inject.Inject; import javax.persistence.NoResultException; import javax.persistence.TypedQuery; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.FormattedMessage; - /** * * @author Jens Pelzetter diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Domain.java b/ccm-core/src/main/java/org/libreccm/categorization/Domain.java index cdf44bb5b..d05f9c714 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Domain.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Domain.java @@ -18,18 +18,16 @@ */ package org.libreccm.categorization; -import org.hibernate.validator.constraints.NotBlank; -import org.hibernate.validator.constraints.URL; - import static org.libreccm.categorization.CategorizationConstants.*; - -import org.libreccm.core.CcmObject; - import static org.libreccm.core.CoreConstants.*; +import org.hibernate.validator.constraints.NotBlank; +import org.hibernate.validator.constraints.URL; +import org.libreccm.core.CcmObject; import org.libreccm.jpa.utils.UriConverter; import org.libreccm.l10n.LocalizedString; import org.libreccm.web.CcmApplication; +import org.omg.CORBA.DomainManager; import java.io.Serializable; import java.net.URI; @@ -54,9 +52,6 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.Pattern; - -import org.omg.CORBA.DomainManager; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; diff --git a/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java b/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java index 619cdcc1b..3172a94ed 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java @@ -18,12 +18,12 @@ */ package org.libreccm.categorization; +import org.libreccm.web.ApplicationRepository; import org.libreccm.web.CcmApplication; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.persistence.EntityManager; -import org.libreccm.web.ApplicationRepository; /** * Provides several methods when managing the relations between {@link Domain}s diff --git a/ccm-core/src/main/java/org/libreccm/categorization/DomainOwnership.java b/ccm-core/src/main/java/org/libreccm/categorization/DomainOwnership.java index 50ff29455..5d5c6bb82 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/DomainOwnership.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/DomainOwnership.java @@ -18,6 +18,11 @@ */ package org.libreccm.categorization; +import static org.libreccm.core.CoreConstants.*; + +import org.libreccm.core.CcmObject; +import org.libreccm.web.CcmApplication; + import java.io.Serializable; import java.util.Objects; @@ -29,12 +34,6 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Table; -import org.libreccm.core.CcmObject; - -import static org.libreccm.core.CoreConstants.*; - -import org.libreccm.web.CcmApplication; - /** * Association class for the association between a {@link Domain} and a diff --git a/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java index 5849c16bc..050a77cdd 100644 --- a/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java +++ b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java @@ -18,21 +18,17 @@ */ package org.libreccm.configuration; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; - -import org.libreccm.categorization.CategoryManager; -import org.libreccm.categorization.Domain; -import org.libreccm.categorization.DomainRepository; - import static org.libreccm.configuration.ConfigurationConstants.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.FormattedMessage; import org.libreccm.categorization.Categorization; import org.libreccm.categorization.Category; +import org.libreccm.categorization.CategoryManager; import org.libreccm.categorization.CategoryRepository; +import org.libreccm.categorization.Domain; +import org.libreccm.categorization.DomainRepository; import org.libreccm.core.CcmObject; import org.libreccm.l10n.LocalizedString; import org.libreccm.web.CcmApplication; @@ -42,12 +38,13 @@ import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import java.util.Optional; - -import org.apache.logging.log4j.message.FormattedMessage; - import java.util.Set; import java.util.StringJoiner; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; + /** * Maps between configuration classes and the values stored in the registry. * diff --git a/ccm-core/src/main/java/org/libreccm/web/ServletPath.java b/ccm-core/src/main/java/org/libreccm/web/ServletPath.java index 4ec333661..ccb928fa7 100644 --- a/ccm-core/src/main/java/org/libreccm/web/ServletPath.java +++ b/ccm-core/src/main/java/org/libreccm/web/ServletPath.java @@ -47,6 +47,6 @@ import javax.servlet.annotation.WebServlet; @Target({ElementType.TYPE}) public @interface ServletPath { - String value() default URL.SERVLET_DIR + "/legacy-adapter"; + String value() default "/templates/servlet/legacy-adapter"; } diff --git a/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java b/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java index 5112ce365..d2a7ce433 100644 --- a/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java +++ b/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java @@ -18,7 +18,6 @@ */ package com.arsdigita.kernel.security; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.JavaPropertyReader; import com.arsdigita.util.parameter.AbstractParameter; import com.arsdigita.web.CCMApplicationContextListener; @@ -111,7 +110,6 @@ public class SecurityConfigTest { .addPackage(ApplicationRepository.class.getPackage()) .addPackage(EntityManagerProducer.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameter.class.getPackage()) .addPackage(JavaPropertyReader.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) diff --git a/ccm-core/src/test/java/com/arsdigita/web/WebConfigTest.java b/ccm-core/src/test/java/com/arsdigita/web/WebConfigTest.java index 5814a3c91..aad370776 100644 --- a/ccm-core/src/test/java/com/arsdigita/web/WebConfigTest.java +++ b/ccm-core/src/test/java/com/arsdigita/web/WebConfigTest.java @@ -91,6 +91,10 @@ public class WebConfigTest { assertThat(webConfig.getHost(), is(equalTo("zeus.example.org:8080"))); + assertThat(webConfig.getHostName(), + is(equalTo("zeus.example.org"))); + assertThat(webConfig.getHostPort(), + is(equalTo(8080))); } @Test(expected = IllegalArgumentException.class) @@ -129,6 +133,10 @@ public class WebConfigTest { assertThat(webConfig.getServer(), is(equalTo("zeus.example.org:8080"))); + assertThat(webConfig.getServerName(), + is(equalTo("zeus.example.org"))); + assertThat(webConfig.getServerPort(), + is(equalTo(8080))); } @Test(expected = IllegalArgumentException.class) @@ -167,6 +175,10 @@ public class WebConfigTest { assertThat(webConfig.getSecureServer(), is(equalTo("zeus.example.org:8080"))); + assertThat(webConfig.getSecureServerName(), + is(equalTo("zeus.example.org"))); + assertThat(webConfig.getSecureServerPort(), + is(equalTo(8080))); } @Test(expected = IllegalArgumentException.class) diff --git a/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java b/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java index fa6884e1b..9e5baf6cd 100644 --- a/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -136,7 +135,6 @@ public class AuthorizationInterceptorTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java b/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java index 55d83ec64..56349744e 100644 --- a/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -146,7 +145,6 @@ public class PermissionCheckerTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java index 4cf1566ab..d43e11fcd 100644 --- a/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -137,7 +136,6 @@ public class PermissionManagerTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java index 5ca411149..49a584043 100644 --- a/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -132,7 +131,6 @@ public class RoleManagerTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java b/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java index 1c2c66bc6..250a26fc8 100644 --- a/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -163,7 +162,6 @@ public class SecuredCollectionTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java b/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java index 51d116faa..a282dbe3e 100644 --- a/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -163,7 +162,6 @@ public class SecuredIteratorTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java b/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java index b6be7563f..144d5a8b2 100644 --- a/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java @@ -18,14 +18,6 @@ */ package org.libreccm.security; -import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.util.parameter.AbstractParameterContext; -import com.arsdigita.web.CCMApplicationContextListener; -import com.arsdigita.xml.XML; -import com.arsdigita.xml.formatters.DateTimeFormatter; - import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.UsernamePasswordToken; @@ -58,15 +50,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import org.libreccm.categorization.Categorization; -import org.libreccm.core.CcmObject; -import org.libreccm.jpa.EntityManagerProducer; -import org.libreccm.jpa.utils.MimeTypeConverter; -import org.libreccm.l10n.LocalizedString; import org.libreccm.tests.categories.IntegrationTest; -import org.libreccm.testutils.EqualsVerifier; -import org.libreccm.web.CcmApplication; -import org.libreccm.workflow.Workflow; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -121,53 +105,54 @@ public class ShiroTest { return ShrinkWrap .create(WebArchive.class, "LibreCCM-org.libreccm.security.ShiroTest.war") - .addPackage(User.class.getPackage()) - .addPackage(CcmObject.class.getPackage()) - .addPackage(Categorization.class.getPackage()) - .addPackage(LocalizedString.class.getPackage()) - .addPackage(CcmApplication.class.getPackage()) - .addPackage(Workflow.class.getPackage()) - .addPackage(EntityManagerProducer.class.getPackage()) - .addPackage(MimeTypeConverter.class.getPackage()) - .addPackage(EqualsVerifier.class.getPackage()) - .addPackage(IntegrationTest.class.getPackage()) - .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) - .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(CCMApplicationContextListener.class.getPackage()) - .addPackage(XML.class.getPackage()) - .addPackage(DateTimeFormatter.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) + .addPackage("org.libreccm.cdi.utils") //Checked + .addPackage("org.libreccm.categorization") //Checked + .addPackage("org.libreccm.configuration") //Checked + .addPackage("org.libreccm.core") //Checked + .addPackage("org.libreccm.jpa") //Checked + .addPackage("org.libreccm.jpa.utils") //Checked + .addPackage("org.libreccm.l10n") //Checked + .addPackage("org.libreccm.modules") //Checked + .addPackage("org.libreccm.security") //Checked + .addPackage("org.libreccm.tests.categories") //Checked + .addPackage("org.libreccm.testutils") //Checked + .addPackage("org.libreccm.web") //Checked + .addPackage("org.libreccm.workflow") //Checked + .addPackage("com.arsdigita.kernel") //Checked + .addPackage("com.arsdigita.kernel.security") //Checked + .addPackage("com.arsdigita.util") //Checked + .addPackage("com.arsdigita.util.parameter") //Checked + // .addPackage(CcmCore.class.getPackage()) + // .addPackage(CcmModule.class.getPackage()) + // .addPackage(CcmObject.class.getPackage()) + // .addPackage(CdiUtil.class.getPackage()) + // .addPackage(Categorization.class.getPackage()) + // .addPackage(Configuration.class.getPackage()) + // .addPackage(LocalizedString.class.getPackage()) + // .addPackage(CcmApplication.class.getPackage()) + // .addPackage(Workflow.class.getPackage()) + // .addPackage(EntityManagerProducer.class.getPackage()) + // .addPackage(MimeTypeConverter.class.getPackage()) + // .addPackage(EqualsVerifier.class.getPackage()) + // .addPackage(IntegrationTest.class.getPackage()) + // .addPackage(SecurityConfig.class.getPackage()) + // .addPackage(CCMApplicationContextListener.class.getPackage()) + // .addPackage(XML.class.getPackage()) + // .addPackage(DateTimeFormatter.class.getPackage()) + // .addPackage(AbstractParameterContext.class.getPackage()) + // .addPackage(UncheckedWrapperException.class.getPackage()) + // .addPackage(CCMResourceManager.class.getPackage()) + // .addPackage(DispatcherHelper.class.getPackage()) + // .addPackage(UI.class.getPackage()) + // .addPackage(KernelConfig.class.getPackage()) + // .addPackage(BasePage.class.getPackage()) .addAsLibraries(libs) .addAsResource("test-persistence.xml", "META-INF/persistence.xml") - .addAsResource("com/arsdigita/kernel/" - + "KernelConfig_parameter.properties", - "com/arsdigita/kernel/" - + "KernelConfig_parameter.properties") - .addAsResource("com/arsdigita/kernel/security/" - + "SecurityConfig_parameter.properties", - "com/arsdigita/kernel/security/" - + "SecurityConfig_parameter.properties") - .addAsWebInfResource( - "configs/org/libreccm/security/UserManagerTest/" - + "registry.properties", - "conf/registry/registry.properties") - .addAsResource( - "configs/org/libreccm/security/UserManagerTest/ccm-core.config", - "ccm-core.config") .addAsResource("configs/shiro.ini", "shiro.ini") .addAsResource( "configs/org/libreccm/security/ShiroTest/log4j2.xml", "log4j2.xml") - .addAsWebInfResource( - "configs/org/libreccm/security/ShiroTest/" - + "kernel.properties", - "conf/registry/ccm-core/kernel.properties") - .addAsWebInfResource( - "configs/org/libreccm//security/ShiroTest/" - + "security.properties", - "conf/registry/ccm-core/security.properties") .addAsWebInfResource("test-web.xml", "web.xml") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } diff --git a/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java index 7b31380e8..e5eb567ec 100644 --- a/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java @@ -19,7 +19,6 @@ package org.libreccm.security; import com.arsdigita.kernel.security.SecurityConfig; -import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; @@ -133,7 +132,6 @@ public class UserManagerTest { .addPackage(EqualsVerifier.class.getPackage()) .addPackage(IntegrationTest.class.getPackage()) .addPackage(SecurityConfig.class.getPackage()) - .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) diff --git a/ccm-core/src/test/resources/configs/org/libreccm/configuration/ConfigurationManagerTest/log4j2.xml b/ccm-core/src/test/resources/configs/org/libreccm/configuration/ConfigurationManagerTest/log4j2.xml new file mode 100644 index 000000000..89c887851 --- /dev/null +++ b/ccm-core/src/test/resources/configs/org/libreccm/configuration/ConfigurationManagerTest/log4j2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/ccm-core/src/test/resources/configs/org/libreccm/security/ShiroTest/log4j2.xml b/ccm-core/src/test/resources/configs/org/libreccm/security/ShiroTest/log4j2.xml new file mode 100644 index 000000000..53880abe3 --- /dev/null +++ b/ccm-core/src/test/resources/configs/org/libreccm/security/ShiroTest/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + diff --git a/ccm-core/src/test/resources/configs/shiro.ini b/ccm-core/src/test/resources/configs/shiro.ini new file mode 100644 index 000000000..f313a39e8 --- /dev/null +++ b/ccm-core/src/test/resources/configs/shiro.ini @@ -0,0 +1,10 @@ +[main] + +passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcher +passwordService = org.apache.shiro.authc.credential.DefaultPasswordService +passwordMatcher.passwordService = $passwordService + +ccmRealm = org.libreccm.security.CcmShiroRealm +ccmRealm.credentialsMatcher = $passwordMatcher + +securityManager.realms = $ccmRealm \ No newline at end of file