2 * Copyright 2009 University Corporation for Advanced Internet Development, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package edu.internet2.middleware.shibboleth.idp;
19 import java.io.IOException;
20 import java.io.PrintWriter;
22 import javax.servlet.ServletConfig;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
28 import org.joda.time.DateTime;
29 import org.joda.time.chrono.ISOChronology;
30 import org.joda.time.format.DateTimeFormatter;
31 import org.joda.time.format.ISODateTimeFormat;
32 import org.opensaml.xml.security.x509.X509Credential;
33 import org.opensaml.xml.util.Base64;
35 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
36 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolver;
37 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration;
38 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfigurationManager;
39 import edu.internet2.middleware.shibboleth.idp.util.HttpServletHelper;
41 /** A Servlet for displaying the status of the IdP. */
42 public class StatusServlet extends HttpServlet {
44 /** Serial version UID. */
45 private static final long serialVersionUID = 7917509317276109266L;
47 /** Formatter used when print date/times. */
48 private DateTimeFormatter dateFormat;
50 /** Time the IdP started up. */
51 private DateTime startTime;
53 /** Attribute resolver used by the IdP. */
54 private AttributeResolver<?> attributeResolver;
56 /** Relying party configuration manager used by the IdP. */
57 private RelyingPartyConfigurationManager rpConfigManager;
60 public void init(ServletConfig config) throws ServletException {
63 dateFormat = ISODateTimeFormat.dateTimeNoMillis();
64 startTime = new DateTime(ISOChronology.getInstanceUTC());
65 attributeResolver = HttpServletHelper.getAttributeResolver(config.getServletContext());
66 rpConfigManager = HttpServletHelper.getRelyingPartyConfirmationManager(config.getServletContext());
70 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
71 resp.setContentType("text/plain");
72 PrintWriter output = resp.getWriter();
74 printOperatingEnvironmentInformation(output);
76 printIdPInformation(output);
78 printRelyingPartyConfigurationsInformation(output, req.getParameter("relyingParty"));
84 * Prints out information about the operating environment. This includes the operating system name, version and
85 * architecture, the JDK version, available CPU cores, memory currently used by the JVM process, the maximum amount
86 * of memory that may be used by the JVM, and the current time in UTC.
88 * @param out output writer to which information will be written
90 protected void printOperatingEnvironmentInformation(PrintWriter out) {
91 Runtime runtime = Runtime.getRuntime();
93 out.println("### Operating Environment Information");
94 out.println("operating_system: " + System.getProperty("os.name"));
95 out.println("operating_system_version: " + System.getProperty("os.version"));
96 out.println("operating_system_architecture: " + System.getProperty("os.arch"));
97 out.println("jdk_version: " + System.getProperty("java.version"));
98 out.println("available_cores: " + runtime.availableProcessors());
99 out.println("used_memory: " + runtime.totalMemory() / 1048576 + "MB");
100 out.println("maximum_memory: " + runtime.maxMemory() / 1048576 + "MB");
101 out.println("current_time: " + new DateTime(ISOChronology.getInstanceUTC()).toString(dateFormat));
105 * Prints out general IdP information. This includes IdP version, start up time, and whether the attribute resolver
106 * is currently operational.
108 * @param out output writer to which information will be written
110 protected void printIdPInformation(PrintWriter out) {
111 Package pkg = Version.class.getPackage();
113 out.println("### Identity Provider Information");
114 out.println("idp_version: " + pkg.getImplementationVersion());
115 out.println("idp_start_time: " + startTime.toString(dateFormat));
117 attributeResolver.validate();
118 out.println("attribute_resolver_valid: " + Boolean.TRUE);
119 } catch (AttributeResolutionException e) {
120 out.println("attribute_resolver_valid: " + Boolean.FALSE);
125 * Prints information about relying party configurations. If the given relying party is null then the configuration
126 * for all relying parties is printed. If the relying party ID is not null then the relying party configurations for
127 * that entity is printed.
129 * @param out output writer to which information will be written
130 * @param relyingPartyId entity ID of the relying party whose configuration should be printed
132 protected void printRelyingPartyConfigurationsInformation(PrintWriter out, String relyingPartyId) {
133 out.println("### Relying Party Configurations");
135 if (relyingPartyId == null) {
136 for (RelyingPartyConfiguration config : rpConfigManager.getRelyingPartyConfigurations().values()) {
137 printRelyingPartyConfigurationInformation(out, config);
141 RelyingPartyConfiguration config = rpConfigManager.getRelyingPartyConfiguration(relyingPartyId);
142 printRelyingPartyConfigurationInformation(out, config);
148 * Prints out the information for a specific relying party configuration. This information includes the relying
149 * party or relying party group ID, the entity ID of the IdP when it responds when using this configuration, the
150 * default authentication method used for this config, and configured communication profiles.
152 * @param out output writer to which information will be written
153 * @param config the relying party configuration
155 protected void printRelyingPartyConfigurationInformation(PrintWriter out, RelyingPartyConfiguration config) {
156 out.println("relying_party_id: " + config.getRelyingPartyId());
157 out.println("idp_entity_id: " + config.getProviderId());
159 if (config.getDefaultAuthenticationMethod() != null) {
160 out.println("default_authentication_method: " + config.getDefaultAuthenticationMethod());
162 out.println("default_authentication_method: none");
166 X509Credential signingCredential = (X509Credential) config.getDefaultSigningCredential();
167 out.println("default_signing_tls_key: " + Base64.encodeBytes(signingCredential.getEntityCertificate().getEncoded(), Base64.DONT_BREAK_LINES));
172 for (String profileId : config.getProfileConfigurations().keySet()) {
173 out.println("configured_communication_profile: " + profileId);