--- /dev/null
+/*
+ * The Shibboleth License, Version 1.
+ * Copyright (c) 2002
+ * University Corporation for Advanced Internet Development, Inc.
+ * All rights reserved
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution, if any, must include
+ * the following acknowledgment: "This product includes software developed by
+ * the University Corporation for Advanced Internet Development
+ * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
+ * may appear in the software itself, if and wherever such third-party
+ * acknowledgments normally appear.
+ *
+ * Neither the name of Shibboleth nor the names of its contributors, nor
+ * Internet2, nor the University Corporation for Advanced Internet Development,
+ * Inc., nor UCAID may be used to endorse or promote products derived from this
+ * software without specific prior written permission. For written permission,
+ * please contact shibboleth@shibboleth.org
+ *
+ * Products derived from this software may not be called Shibboleth, Internet2,
+ * UCAID, or the University Corporation for Advanced Internet Development, nor
+ * may Shibboleth appear in their name, without prior written permission of the
+ * University Corporation for Advanced Internet Development.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
+ * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
+ * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package edu.internet2.middleware.shibboleth.common;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * Manages access to shibboleth file-based resources in a consistent fashion.
+ */
+public class ShibResource {
+
+ private URL resource;
+ private Class requester;
+
+ public ShibResource(String name) throws ResourceNotAvailableException {
+ this(name, Object.class);
+ }
+
+ public ShibResource(String name, Class requester) throws ResourceNotAvailableException {
+ this.requester = requester;
+ try {
+ resource = new URL(name);
+ } catch (MalformedURLException e) {
+ resource = requester.getResource(name);
+ }
+ if (resource == null) {
+ throw new ResourceNotAvailableException("ShibResource could not be found at the specified location.");
+ }
+ System.err.println(resource);
+ }
+
+ /**
+ * Returns an input stream to read the resource contents
+ */
+ public InputStream getInputStream() throws IOException {
+ return resource.openStream();
+ }
+
+ /**
+ * Returns a <code>File</code> representation of the resource
+ */
+ public File getFile() throws IOException {
+ try {
+ File file = new File(new URI(resource.toString()));
+ return file;
+ } catch (URISyntaxException e) {
+ throw new ResourceNotAvailableException("File could not be loaded from specified resource: " + e);
+ }
+ }
+
+ /**
+ * Returns a <code>URL</code> pointer to the resource
+ */
+ public URL getURL() throws IOException {
+ return resource;
+ }
+
+ class ResourceNotAvailableException extends IOException {
+
+ public ResourceNotAvailableException(String message) {
+ super(message);
+ }
+ }
+
+}
package edu.internet2.middleware.shibboleth.log;
+import java.io.IOException;
+
import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.xml.security.Init;
+import edu.internet2.middleware.shibboleth.common.ShibResource;
+
/**
*
* Servlet used to configure logging for other components.
super.init();
//Silliness to get around xmlsec doing its own configuration, ie: we might need to override it
Init.init();
-
String log4jConfigFileLocation = getServletConfig().getInitParameter("log4jConfigFileLocation");
if (log4jConfigFileLocation == null) {
- log4jConfigFileLocation = "/WEB-INF/conf/log4j.properties";
+ log4jConfigFileLocation = "/conf/log4j.properties";
+ }
+ try {
+ PropertyConfigurator.configure(new ShibResource(log4jConfigFileLocation, this.getClass()).getURL());
+ } catch (IOException e) {
+ getServletContext().log("Could not load Logger configuration from supplied location.", e);
+ System.err.println("Could not load Logger configuration from supplied location: " + e);
+ throw new UnavailableException("Could not load Logger configuration from supplied location: " + e);
}
- PropertyConfigurator.configure(getServletContext().getRealPath("/") + log4jConfigFileLocation);
- MDC.put("serviceId", "[Logger] Core");
+ MDC.put("serviceId", "[Logger] Core");
log.info("Logger initialized.");
}
+++ /dev/null
-##
-#
-# Shibboleth Log4J configuration
-#
-##
-
-
-# Default configuration. Sends logging output to STDOUT.
-
-log4j.rootCategory=WARN, stdout
-log4j.logger.org.apache.xml.security=OFF
-log4j.logger.org.opensaml=OFF
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%-5p %-41X{serviceId} %d{ISO8601} - %m%n
-
-
-# The following block represents an example of how to enable very verbose logging.
-
-#log4j.rootCategory=DEBUG, stdout
-#log4j.logger.org.apache.xml.security=OFF
-#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-#log4j.appender.stdout.layout.ConversionPattern=%-5p %-41X{serviceId} %d{ISO8601} (%c:%L) - %m%n
-
-
-# The following block represents an example of how to direct logging output to a file.
-
-#log4j.rootCategory=INFO, file
-#log4j.logger.org.apache.xml.security=OFF
-#log4j.logger.org.opensaml=OFF
-#log4j.appender.file=org.apache.log4j.RollingFileAppender
-#log4j.appender.file.File=/var/log/shib.log
-#log4j.appender.file.MaxFileSize=100KB
-#log4j.appender.file.MaxBackupIndex=1
-#log4j.appender.file.layout=org.apache.log4j.PatternLayout
-#log4j.appender.file.layout.ConversionPattern=%-5p %-41X{serviceId} %d{ISO8601} - %m%n
-
-
-# Uncomment the following line to enable verbose debugging output concerning log4j initialization.
-
-#log4j.debug=TRUE
\ No newline at end of file