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.util.DatatypeHelper;
34 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
35 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolver;
36 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration;
37 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfigurationManager;
39 /** A servlet for displaying the status of the IdP. */
40 public class StatusServlet extends HttpServlet {
42 /** Formatter used when print date/times. */
43 private DateTimeFormatter dateFormat;
45 /** Time the IdP started up. */
46 private DateTime startTime;
48 /** Attribute resolver used by the IdP. */
49 private AttributeResolver<?> attributeResolver;
51 /** Relying party configuration manager used by the IdP. */
52 private RelyingPartyConfigurationManager rpConfigManager;
55 public void init(ServletConfig config) throws ServletException {
58 dateFormat = ISODateTimeFormat.dateTimeNoMillis();
60 startTime = new DateTime(ISOChronology.getInstanceUTC());
62 String attributeResolverId = config.getInitParameter("attributeResolverId");
63 if (DatatypeHelper.isEmpty(attributeResolverId)) {
64 attributeResolverId = "shibboleth.AttributeResolver";
66 attributeResolver = (AttributeResolver<?>) getServletContext().getAttribute(attributeResolverId);
68 String rpConfigManagerId = config.getInitParameter("rpConfigManagerId");
69 if (DatatypeHelper.isEmpty(rpConfigManagerId)) {
70 rpConfigManagerId = "shibboleth.RelyingPartyConfigurationManager";
72 rpConfigManager = (RelyingPartyConfigurationManager) getServletContext().getAttribute(rpConfigManagerId);
76 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
77 PrintWriter output = resp.getWriter();
79 printOperatingEnvironmentInformation(output);
81 printIdPInformation(output);
83 printRelyingPartyConfigurationsInformation(output, req.getParameter("relyingParty"));
89 * Prints out information about the operating environment. This includes the operating system name, version and
90 * architecture, the JDK version, available CPU cores, memory currently used by the JVM process, the maximum amount
91 * of memory that may be used by the JVM, and the current time in UTC.
93 * @param out output writer to which information will be written
95 protected void printOperatingEnvironmentInformation(PrintWriter out) {
96 Runtime runtime = Runtime.getRuntime();
98 out.println("Operating Environment Information");
99 out.println("operating_system: " + System.getProperty("os.name"));
100 out.println("operating_system_version: " + System.getProperty("os.version"));
101 out.println("operating_system_architecture: " + System.getProperty("os.arch"));
102 out.println("jdk_version: " + System.getProperty("java.version"));
103 out.println("available_cores: " + runtime.availableProcessors());
104 out.println("used_memory: " + runtime.totalMemory() / 1048576 + "MB");
105 out.println("maximum_memory: " + runtime.maxMemory() / 1048576 + "MB");
106 out.println("current_time: " + new DateTime(ISOChronology.getInstanceUTC()).toString(dateFormat));
110 * Prints out general IdP information. This includes IdP version, start up time, and whether the attribute resolver
111 * is currently operational.
113 * @param out output writer to which information will be written
115 protected void printIdPInformation(PrintWriter out) {
116 Package pkg = Version.class.getPackage();
118 out.println("Identity Provider Information");
119 out.println("idp_version: " + pkg.getImplementationVersion());
120 out.println("idp_start_time: " + startTime.toString(dateFormat));
122 attributeResolver.validate();
123 out.println("attribute_resolver_valid: " + Boolean.TRUE);
124 } catch (AttributeResolutionException e) {
125 out.println("attribute_resolver_valid: " + Boolean.FALSE);
130 * Prints information about relying party configurations. If the given relying party is null then the configuration
131 * for all relying parties is printed. If the relying party ID is not null then the relying party configurations for
132 * that entity is printed.
134 * @param out output writer to which information will be written
135 * @param relyingPartyId entity ID of the relying party whose configuration should be printed
137 protected void printRelyingPartyConfigurationsInformation(PrintWriter out, String relyingPartyId) {
138 out.println("Relying Party Configurations");
140 if (relyingPartyId == null) {
141 for (RelyingPartyConfiguration config : rpConfigManager.getRelyingPartyConfigurations().values()) {
142 printRelyingPartyConfigurationInformation(out, config);
146 RelyingPartyConfiguration config = rpConfigManager.getRelyingPartyConfiguration(relyingPartyId);
147 printRelyingPartyConfigurationInformation(out, config);
153 * Prints out the information for a specific relying party configuration. This information includes the relying
154 * party or relying party group ID, the entity ID of the IdP when it responds when using this configuration, the
155 * default authentication method used for this config, and configured communication profiles.
157 * @param out output writer to which information will be written
158 * @param config the relying party configuration
160 protected void printRelyingPartyConfigurationInformation(PrintWriter out, RelyingPartyConfiguration config) {
161 out.println("relying_party_id: " + config.getRelyingPartyId());
162 out.println("idp_entity_id: " + config.getProviderId());
164 if (config.getDefaultAuthenticationMethod() != null) {
165 out.println("default_authentication_method: " + config.getDefaultAuthenticationMethod());
167 out.println("default_authentication_method: none");
170 for (String profileId : config.getProfileConfigurations().keySet()) {
171 out.println("configured_communication_profile: " + profileId);