Initial work on new Status handler - SIDP-324
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 1 Jul 2009 05:24:20 +0000 (05:24 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 1 Jul 2009 05:24:20 +0000 (05:24 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@2853 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/main/java/edu/internet2/middleware/shibboleth/idp/StatusServlet.java [new file with mode: 0644]
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/StatusProfileHandler.java
src/main/webapp/WEB-INF/web.xml

diff --git a/src/main/java/edu/internet2/middleware/shibboleth/idp/StatusServlet.java b/src/main/java/edu/internet2/middleware/shibboleth/idp/StatusServlet.java
new file mode 100644 (file)
index 0000000..b757a80
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2009 University Corporation for Advanced Internet Development, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package edu.internet2.middleware.shibboleth.idp;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.joda.time.DateTime;
+import org.joda.time.chrono.ISOChronology;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+import org.opensaml.xml.util.DatatypeHelper;
+
+import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
+import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolver;
+import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration;
+import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfigurationManager;
+
+/** A servlet for displaying the status of the IdP. */
+public class StatusServlet extends HttpServlet {
+
+    /** Formatter used when print date/times. */
+    private DateTimeFormatter dateFormat;
+
+    /** Time the IdP started up. */
+    private DateTime startTime;
+
+    /** Attribute resolver used by the IdP. */
+    private AttributeResolver<?> attributeResolver;
+
+    /** Relying party configuration manager used by the IdP. */
+    private RelyingPartyConfigurationManager rpConfigManager;
+
+    /** {@inheritDoc} */
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+
+        dateFormat = ISODateTimeFormat.dateTimeNoMillis();
+
+        startTime = new DateTime(ISOChronology.getInstanceUTC());
+
+        String attributeResolverId = config.getInitParameter("attributeResolverId");
+        if (DatatypeHelper.isEmpty(attributeResolverId)) {
+            attributeResolverId = "shibboleth.AttributeResolver";
+        }
+        attributeResolver = (AttributeResolver<?>) getServletContext().getAttribute(attributeResolverId);
+
+        String rpConfigManagerId = config.getInitParameter("rpConfigManagerId");
+        if (DatatypeHelper.isEmpty(rpConfigManagerId)) {
+            rpConfigManagerId = "shibboleth.RelyingPartyConfigurationManager";
+        }
+        rpConfigManager = (RelyingPartyConfigurationManager) getServletContext().getAttribute(rpConfigManagerId);
+    }
+
+    /** {@inheritDoc} */
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        PrintWriter output = resp.getWriter();
+
+        printOperatingEnvironmentInformation(output);
+        output.println();
+        printIdPInformation(output);
+        output.println();
+        printRelyingPartyConfigurationsInformation(output, req.getParameter("relyingParty"));
+
+        output.flush();
+    }
+
+    /**
+     * Prints out information about the operating environment. This includes the operating system name, version and
+     * architecture, the JDK version, available CPU cores, memory currently used by the JVM process, the maximum amount
+     * of memory that may be used by the JVM, and the current time in UTC.
+     * 
+     * @param out output writer to which information will be written
+     */
+    protected void printOperatingEnvironmentInformation(PrintWriter out) {
+        Runtime runtime = Runtime.getRuntime();
+
+        out.println("Operating Environment Information");
+        out.println("operating_system: " + System.getProperty("os.name"));
+        out.println("operating_system_version: " + System.getProperty("os.version"));
+        out.println("operating_system_architecture: " + System.getProperty("os.arch"));
+        out.println("jdk_version: " + System.getProperty("java.version"));
+        out.println("available_cores: " + runtime.availableProcessors());
+        out.println("used_memory: " + runtime.totalMemory() / 1048576 + "MB");
+        out.println("maximum_memory: " + runtime.maxMemory() / 1048576 + "MB");
+        out.println("current_time: " + new DateTime(ISOChronology.getInstanceUTC()).toString(dateFormat));
+    }
+
+    /**
+     * Prints out general IdP information. This includes IdP version, start up time, and whether the attribute resolver
+     * is currently operational.
+     * 
+     * @param out output writer to which information will be written
+     */
+    protected void printIdPInformation(PrintWriter out) {
+        Package pkg = Version.class.getPackage();
+
+        out.println("Identity Provider Information");
+        out.println("idp_version: " + pkg.getImplementationVersion());
+        out.println("idp_start_time: " + startTime.toString(dateFormat));
+        try {
+            attributeResolver.validate();
+            out.println("attribute_resolver_valid: " + Boolean.TRUE);
+        } catch (AttributeResolutionException e) {
+            out.println("attribute_resolver_valid: " + Boolean.FALSE);
+        }
+    }
+
+    /**
+     * Prints information about relying party configurations. If the given relying party is null then the configuration
+     * for all relying parties is printed. If the relying party ID is not null then the relying party configurations for
+     * that entity is printed.
+     * 
+     * @param out output writer to which information will be written
+     * @param relyingPartyId entity ID of the relying party whose configuration should be printed
+     */
+    protected void printRelyingPartyConfigurationsInformation(PrintWriter out, String relyingPartyId) {
+        out.println("Relying Party Configurations");
+
+        if (relyingPartyId == null) {
+            for (RelyingPartyConfiguration config : rpConfigManager.getRelyingPartyConfigurations().values()) {
+                printRelyingPartyConfigurationInformation(out, config);
+                out.println();
+            }
+        } else {
+            RelyingPartyConfiguration config = rpConfigManager.getRelyingPartyConfiguration(relyingPartyId);
+            printRelyingPartyConfigurationInformation(out, config);
+            out.println();
+        }
+    }
+
+    /**
+     * Prints out the information for a specific relying party configuration. This information includes the relying
+     * party or relying party group ID, the entity ID of the IdP when it responds when using this configuration, the
+     * default authentication method used for this config, and configured communication profiles.
+     * 
+     * @param out output writer to which information will be written
+     * @param config the relying party configuration
+     */
+    protected void printRelyingPartyConfigurationInformation(PrintWriter out, RelyingPartyConfiguration config) {
+        out.println("relying_party_id: " + config.getRelyingPartyId());
+        out.println("idp_entity_id: " + config.getProviderId());
+
+        if (config.getDefaultAuthenticationMethod() != null) {
+            out.println("default_authentication_method: " + config.getDefaultAuthenticationMethod());
+        } else {
+            out.println("default_authentication_method: none");
+        }
+
+        for (String profileId : config.getProfileConfigurations().keySet()) {
+            out.println("configured_communication_profile: " + profileId);
+        }
+    }
+}
\ No newline at end of file
index ee103fa..2af3fbf 100644 (file)
@@ -37,6 +37,7 @@ public class StatusProfileHandler extends AbstractRequestURIMappedProfileHandler
 
     /** {@inheritDoc} */
     public void processRequest(InTransport in, OutTransport out) {
+        log.warn("This profile handler has been deprecated, use the Status servlet usually located at '/idp/status'");
         try {
             OutputStreamWriter writer = new OutputStreamWriter(out.getOutgoingStream());
             writer.write("ok");
index f397fd6..c7ace13 100644 (file)
         <url-pattern>/profile/*</url-pattern>
     </servlet-mapping>
     
+    <servlet>
+        <servlet-name>Status</servlet-name>
+        <servlet-class>edu.internet2.middleware.shibboleth.idp.StatusServlet</servlet-class>
+        <load-on-startup>2</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>Status</servlet-name>
+        <url-pattern>/status</url-pattern>
+    </servlet-mapping>
+    
     <!-- Send request to the EntityID to the SAML metadata handler. -->
     <servlet>
         <servlet-name>shibboleth_jsp</servlet-name>