2 * ServiceProviderConfig.java
4 * A ServiceProviderConfig object holds an instance of the Shibboleth
5 * configuration data from the main configuration file and from all
6 * secondary files referenced by the main file.
8 * The configuration file is typically processed during Context
9 * initialization. In a Servlet environment, this is done from
10 * the ServletContextInitializer, while in JUnit testing it is
11 * done during test setup (unless you are testing configuration
12 * in which case it is part of the test itself). This occurs
13 * during init() processing and is inheritly synchronized.
15 * Initialization is a two step process. First create an
16 * instance of this class, then find a path to the configuration
17 * file and call loadConfigObjects().
19 * In addition to the option of loading external classes that
20 * implement one of the Plugin service interfaces by providing
21 * the name of the class in the type= attribute of the Plugin
22 * configuration XML, there is also a manual wiring interface.
23 * Create an implimenting object yourself, then add it to the
24 * configuration by passing an identifying URI and the object
25 * to a addOrReplaceXXXImplementation() method.
27 * These wiring calls are agressive, while the XML is passive.
28 * If the wiring call is made before loadConfigObject(), then
29 * XML referencing this same URI will find that it has already
30 * been loaded and use it. Alternately, if the call is made
31 * after loadConfigObject() then the XML will have processed
32 * the URI, loaded the file, and built an implimenting object.
33 * However, the wiring call will replace that object with the
34 * one provided in the call. Obviously making these calls
35 * first will be slightly more efficient, and is necessary if
36 * the XML configuration specifies URIs that will be provided
37 * by the wiring call and are not represented by any actual file.
39 * After initialization completes, this object and its arrays
40 * and collections should be structurally immutable. A map or
41 * array should not be changed by adding or removing members.
42 * Thus iteration over the collections can be unsynchronized.
43 * The reference to a value in the map can be swapped for a
44 * new object, because this doesn't effect iteration.
46 * Any method may obtain a copy of the current ServiceProviderConfig
47 * object by calling ServiceProviderContext.getServiceProviderConfig().
48 * This reference should only be held locally (for the duration
49 * of the request). Should the entire Shibboleth configuration file
50 * be reparsed (because of a dynamic update), then a new reference will
51 * be stored in the SPContext. Picking up a new reference for each
52 * request ensures that a program uses the latest configuration.
54 * When a secondary file (Metadata, Trust, AAP, etc.) is reloaded,
55 * a new object is constructed for that interface and the entry in
56 * the corresponding Map of providers of that interface is replaced.
57 * Therefore, non-local variables must only store the URI for such
58 * objects. A method can pass the URI to the Map lookup method and
59 * obtain a local variable reference to the current implementing
60 * object which can be used during the processing of the current
63 * Note: The URI for a secondary file cannot change just by
64 * reloading the file, but it can change if this main configuration
65 * file object is rebuilt. Therefore, if an external object stores
66 * a URI for a plugin object, it must be prepared for the Map lookup
67 * to return null. This would indicate that the main configuration
68 * file has been reloaded and the previously valid URI now no longer
69 * points to any implementing object.
71 * XML configuration data is parsed into two formats. First, it
72 * is processed by an ordinary JAXP XML parser into a W3C DOM format.
73 * The parser may validate the XML against an XSD schema, but the
74 * resulting DOM is "untyped". The XML becomes a tree of Element,
75 * Attribute, and Text nodes. The program must still convert an
76 * attribute or text string to a number, date, boolean, or any other
77 * data type even through the XSD declares that it must be of that
78 * type. The program must also search through the elements of the tree
79 * to find specific names for expected contents.
81 * This module then subjects the DOM to a secondary parse through
82 * some classes generated by compiling the XSD file with tools
83 * provided by the Apache XML Bean project. This turns the valid
84 * XML into strongly typed Java objects. A class is generated to
85 * represent every data type defined in the XSD schemas. Attribute
86 * values and child elements become properties of the objects of
87 * these classes. The XMLBean objects simplify the configuration
90 * If the configuration file directly reflected the program logic,
91 * the XML Bean classes would probably be enough. However, there
92 * are two important considerations:
94 * First, the Metadata is in transition. Currently we support an
95 * ad-hoc format defined by Shibboleth. However, it is expected
96 * that this will change in the next release to support a new
97 * standard accompanying SAML 2.0. The program logic anticipates
98 * this change, and is largely designed around concepts and
99 * structures of the new SAML standard. The actual configuration
100 * file and XML Beans support the old format, which must be mapped
101 * into this new structure.
103 * Second, secondary configuration elements (Credentials, Trust,
104 * Metadata, AAP, etc.) are "Pluggable" components. There is a
105 * built-in implementation of these services based on the XML
106 * configuration described in the Shibboleth documentation.
107 * However, the administrator can provide other classes that
108 * implement the required interfaces by simply coding the class
109 * name in the type= parameter of the XML element referencing the
110 * plugin. In this case we don't know the format of the opaque
111 * XML and simply pass it to the plugin.
114 * Dependencies: Requires XML Beans and the generated classes.
115 * Requires access to XSD schema files for configuration file formats.
116 * Logic depends on the order of enums in the XSD files.
118 * Error Strategy: A failure parsing the main configuration file
119 * prevents further processing. However, a problem parsing a plug-in
120 * configuration file should be noted while processing continues.
121 * This strategy reports all the errors in all the files to the log
122 * rather than stopping at the first error.
124 * --------------------
125 * Copyright 2002, 2004
126 * University Corporation for Advanced Internet Development, Inc.
127 * All rights reserved
128 * [Thats all we have to say to protect ourselves]
129 * Your permission to use this code is governed by "The Shibboleth License".
130 * A copy may be found at http://shibboleth.internet2.edu/license.html
131 * [Nothing in copyright law requires license text in every file.]
134 package edu.internet2.middleware.shibboleth.serviceprovider;
136 import java.net.MalformedURLException;
138 import java.security.cert.X509Certificate;
139 import java.util.ArrayList;
140 import java.util.Collection;
141 import java.util.Iterator;
142 import java.util.Map;
143 import java.util.TreeMap;
145 import org.apache.log4j.Logger;
146 import org.apache.xmlbeans.XmlException;
147 import org.apache.xmlbeans.XmlOptions;
148 import org.opensaml.SAMLAssertion;
149 import org.opensaml.SAMLAttribute;
150 import org.opensaml.SAMLAttributeStatement;
151 import org.opensaml.SAMLException;
152 import org.opensaml.SAMLSignedObject;
153 import org.opensaml.artifact.Artifact;
154 import org.w3c.dom.Document;
155 import org.w3c.dom.Element;
156 import org.w3c.dom.Node;
158 import x0.maceShibboleth1.AttributeAcceptancePolicyDocument;
159 import x0.maceShibbolethTargetConfig1.ApplicationDocument;
160 import x0.maceShibbolethTargetConfig1.LocalConfigurationType;
161 import x0.maceShibbolethTargetConfig1.PluggableType;
162 import x0.maceShibbolethTargetConfig1.RequestMapDocument;
163 import x0.maceShibbolethTargetConfig1.SPConfigType;
164 import x0.maceShibbolethTargetConfig1.ShibbolethTargetConfigDocument;
165 import x0.maceShibbolethTargetConfig1.ApplicationDocument.Application;
166 import x0.maceShibbolethTargetConfig1.ApplicationsDocument.Applications;
167 import x0.maceShibbolethTargetConfig1.HostDocument.Host;
168 import x0.maceShibbolethTargetConfig1.PathDocument.Path;
169 import edu.internet2.middleware.shibboleth.aap.AAP;
170 import edu.internet2.middleware.shibboleth.aap.AttributeRule;
171 import edu.internet2.middleware.shibboleth.common.Credentials;
172 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
173 import edu.internet2.middleware.shibboleth.common.Trust;
174 import edu.internet2.middleware.shibboleth.common.provider.ShibbolethTrust;
175 import edu.internet2.middleware.shibboleth.metadata.EntityDescriptor;
176 import edu.internet2.middleware.shibboleth.metadata.Metadata;
177 import edu.internet2.middleware.shibboleth.metadata.RoleDescriptor;
178 import edu.internet2.middleware.shibboleth.xml.Parser;
181 * Load the configuration files into objects, index them, and return them on request.
183 * <p>A new instance of the ServiceProviderConfig object can be created to
184 * parse a new version of the configuration file. It can then be swapped
185 * into the ServiceProviderContext reference and will be picked up by
186 * subsequent requests.</p>
188 * @author Howard Gilbert
190 public class ServiceProviderConfig {
193 private static final String INLINEURN = "urn:inlineBS:ID";
194 private static Logger log = Logger.getLogger(ServiceProviderConfig.class);
196 private SPConfigType // The XMLBean from the main config file
197 config = null; // (i.e. shibboleth.xml)
201 * The following Maps reference objects that implement a plugin
202 * interface indexed by their URI. There are builtin objects
203 * created from inline or external XML files, but external
204 * objects implementing the interfaces may be injected by
205 * calling the addOrReplaceXXX method. Public access to these
206 * Maps is indirect, through methods the ApplicationInfo object
207 * for a given configured or default application.
210 private Map/*<String, Metadata>*/ entityLocators =
211 new TreeMap/*<String, Metadata>*/();
213 public void addOrReplaceMetadataImplementor(String uri, Metadata m) {
214 entityLocators.put(uri, m);
217 public Metadata getMetadataImplementor(String uri) {
218 return (Metadata)entityLocators.get(uri);
221 private Map/*<String, AAP>*/ attributePolicies =
222 new TreeMap/*<String, AAP>*/();
224 public void addOrReplaceAAPImplementor(String uri, AAP a) {
225 attributePolicies.put(uri,a);
228 public AAP getAAPImplementor(String uri) {
229 return (AAP) attributePolicies.get(uri);
232 private Map/*<String, ITrust>*/ certificateValidators =
233 new TreeMap/*<String, ITrust>*/();
235 public void addOrReplaceTrustImplementor(String uri, Trust t) {
236 certificateValidators.put(uri,t);
239 public Trust getTrustImplementor(String uri) {
240 return (Trust) certificateValidators.get(uri);
245 * Objects created from the <Application(s)> elements.
246 * They manage collections of URI-Strings that index the
247 * previous maps to return Metadata, Trust, and AAP info
248 * applicable to this applicationId.
250 private Map/*<String, ApplicationInfo>*/ applications =
251 new TreeMap/*<String, ApplicationInfo>*/();
253 // Default application info from <Applications> element
254 private ApplicationInfo defaultApplicationInfo = null;
256 public ApplicationInfo getApplication(String applicationId) {
257 ApplicationInfo app=null;
258 app = (ApplicationInfo) applications.get(applicationId);
259 if (app==null) // If no specific match, return default
260 return defaultApplicationInfo;
265 // Objects created from single configuration file elements
266 private Credentials credentials = null;
267 private RequestMapDocument.RequestMap requestMap = null;
274 private static final String XMLTRUSTPROVIDERTYPE =
275 "edu.internet2.middleware.shibboleth.common.provider.XMLTrust";
276 private static final String XMLAAPPROVIDERTYPE =
277 "edu.internet2.middleware.shibboleth.serviceprovider.XMLAAP";
278 private static final String XMLFEDERATIONPROVIDERTYPE =
279 "edu.internet2.middleware.shibboleth.common.provider.XMLMetadata";
280 private static final String XMLREVOCATIONPROVIDERTYPE =
281 "edu.internet2.middleware.shibboleth.common.provider.XMLRevocation";
282 private static final String XMLREQUESTMAPPROVIDERTYPE =
283 "edu.internet2.middleware.shibboleth.serviceprovider.XMLRequestMap";
284 private static final String XMLCREDENTIALSPROVIDERTYPE =
285 "edu.internet2.middleware.shibboleth.common.Credentials";
291 * The constructor prepares for, but does not parse the configuration.
293 * @throws ShibbolethConfigurationException
294 * if XML Parser cannot be initialized (Classpath problem)
296 public ServiceProviderConfig() {
300 * loadConfigObjects must be called once to parse the configuration.
302 * <p>To reload a modified configuration file, create and load a second
303 * object and swap the reference in the context object.</p>
305 * @param configFilePath URL or resource name of file
306 * @return the DOM Document
307 * @throws ShibbolethConfigurationException
308 * if there was an error loading the file
310 public synchronized void loadConfigObjects(String configFilePath)
311 throws ShibbolethConfigurationException {
314 log.error("ServiceProviderConfig.loadConfigObjects may not be called twice for the same object.");
315 throw new ShibbolethConfigurationException("Cannot reload configuration into same object.");
320 configDoc = Parser.loadDom(configFilePath, true);
321 } catch (Exception e) {
322 throw new ShibbolethConfigurationException("XML error in "+configFilePath);
324 loadConfigBean(configDoc);
330 * Given a URL, determine its ApplicationId from the RequestMap config.
332 * <p>Note: This is not a full implementation of all RequestMap
333 * configuration options. Other functions will be added as needed.</p>
335 public String mapRequest(String urlreq) {
336 String applicationId = "default";
340 url = new URL(urlreq);
341 } catch (MalformedURLException e) {
342 return applicationId;
345 String urlscheme = url.getProtocol();
346 String urlhostname = url.getHost();
347 String urlpath = url.getPath();
348 int urlport = url.getPort();
350 if (urlscheme.equals("http"))
352 else if (urlscheme.equals("https"))
356 // find Host entry for this virtual server
357 Host[] hostArray = requestMap.getHostArray();
358 for (int ihost=0;ihost<hostArray.length;ihost++) {
359 Host host = hostArray[ihost];
360 String hostScheme = host.getScheme().toString();
361 String hostName = host.getName();
362 String hostApplicationId = host.getApplicationId();
363 long hostport = host.getPort();
365 if (hostScheme.equals("http"))
367 else if (hostScheme.equals("https"))
371 if (!urlscheme.equals(hostScheme) ||
372 !urlhostname.equals(hostName)||
376 // find Path entry for this subdirectory
377 Path[] pathArray = host.getPathArray();
378 if (hostApplicationId!=null)
379 applicationId=hostApplicationId;
380 for (int i=0;i<pathArray.length;i++) {
381 String dirname = pathArray[i].getName();
382 if (urlpath.equals(dirname)||
383 urlpath.startsWith(dirname+"/")){
384 String pthid= pathArray[i].getApplicationId();
391 return applicationId;
395 * <p>Parse the main configuration file DOM into XML Bean</p>
397 * <p>Automatically load secondary configuration files designated
398 * by URLs in the main configuration file</p>
400 * @throws ShibbolethConfigurationException
402 private void loadConfigBean(Document configDoc)
403 throws ShibbolethConfigurationException {
404 boolean anyError=false;
405 ShibbolethTargetConfigDocument configBeanDoc;
407 // reprocess the already validated DOM to create a bean with typed fields
408 // dump the trash (comments, processing instructions, extra whitespace)
409 configBeanDoc = ShibbolethTargetConfigDocument.Factory.parse(configDoc,
410 new XmlOptions().setLoadStripComments().setLoadStripProcinsts().setLoadStripWhitespace());
411 config=configBeanDoc.getShibbolethTargetConfig();
412 } catch (XmlException e) {
413 // Since the DOM was already validated against the schema, errors will not typically occur here
414 log.error("Error while parsing shibboleth configuration");
415 throw new ShibbolethConfigurationException("Error while parsing shibboleth configuration");
418 // Extract the "root Element" object from the "Document" object
419 SPConfigType config = configBeanDoc.getShibbolethTargetConfig();
421 Applications apps = config.getApplications(); // <Applications>
426 * Create an <Application> id "default" from <Applications>
428 ApplicationDocument defaultAppDoc =
429 // Create a new XMLBeans "Document" level object
430 ApplicationDocument.Factory.newInstance();
431 ApplicationDocument.Application defaultApp =
432 // Add an XMLBeans "root Element" object to the Document
433 defaultAppDoc.addNewApplication();
434 // set or copy over fields from unrelated Applications object
435 defaultApp.setId("default");
436 defaultApp.setAAPProviderArray(apps.getAAPProviderArray());
437 defaultApp.setAttributeDesignatorArray(apps.getAttributeDesignatorArray());
438 defaultApp.setAudienceArray(apps.getAudienceArray());
439 defaultApp.setCredentialUse(apps.getCredentialUse());
440 defaultApp.setErrors(apps.getErrors());
441 defaultApp.setFederationProviderArray(apps.getFederationProviderArray());
442 defaultApp.setProviderId(apps.getProviderId());
443 defaultApp.setRevocationProviderArray(apps.getRevocationProviderArray());
444 defaultApp.setSessions(apps.getSessions());
445 defaultApp.setTrustProviderArray(apps.getTrustProviderArray());
448 * Now process secondary files configured in the applications
450 anyError |= processApplication(defaultApp);
452 Application[] apparray = apps.getApplicationArray();
453 for (int i=0;i<apparray.length;i++){
454 Application tempapp = apparray[i];
455 applications.put(tempapp.getId(),tempapp);
456 anyError |= processApplication(tempapp);
460 * Now process other secondary files
462 anyError |= processCredentials();
463 anyError |= processPluggableRequestMapProvider();
466 throw new ShibbolethConfigurationException("Errors processing configuration file, see log");
471 * Routine to handle CredentialProvider
473 * <p>Note: This only handles in-line XML.
474 * Also, Credentials was an existing Origin class, so it doesn't
475 * implement the new PluggableConfigurationComponent interface and
476 * can't be loaded by generic plugin support.
479 private boolean processCredentials() {
480 boolean anyError=false;
481 PluggableType[] pluggable = config.getCredentialsProviderArray();
482 for (int i=0;i<pluggable.length;i++) {
483 String pluggabletype = pluggable[i].getType();
484 if (!pluggabletype.equals(
485 "edu.internet2.middleware.shibboleth.common.Credentials")) {
486 log.error("Unsupported CredentialsProvider type "+pluggabletype);
490 PluggableType credentialsProvider = pluggable[i];
491 Node fragment = credentialsProvider.newDomNode();
492 // newDomNode returns the current node wrapped in a Fragment
494 Node credentialsProviderNode = fragment.getFirstChild();
495 Node credentialsNode=credentialsProviderNode.getFirstChild();
496 credentials = new Credentials((Element)credentialsNode);
497 } catch(Exception e) {
498 log.error("Cannot process Credentials element of Shibboleth configuration");
508 * Find and load secondary configuration files referenced in an Application(s)
510 * @param app Application object
511 * @throws ShibbolethConfigurationException
513 private boolean processApplication(Application app)
514 throws ShibbolethConfigurationException {
516 boolean anyError=false;
518 String applicationId = app.getId();
520 ApplicationInfo appinfo = new ApplicationInfo(app);
522 anyError |= processPluggableMetadata(appinfo);
523 anyError |= processPluggableAAPs(appinfo);
524 anyError |= processPluggableTrusts(appinfo);
526 applications.put(applicationId, appinfo);
532 * Generic code to create an object of a Pluggable type that implements
533 * a configuration interface.
535 * <p>The configuration schema defines "PluggableType" as a type of
536 * XML element that has opaque contents and attributes "type" and
537 * "uri". If the uri attribute is omitted, then the configuration
538 * data is inline XML content. The XSD files typically define the
539 * format of pluggable configuration elements, but without binding
540 * them to the PluggableType element that may contain them.</p>
542 * <p>The implimentation of pluggable objects is provided by
543 * external classes. There are "builtin" classes provided with
544 * Shibboleth (XMLMetadataImpl, XMLTrustImpl, XMLAAPImpl) that
545 * provide examples of how this is done. By design, others can
546 * provide their own classes just by putting the class name as
547 * the value of the type attribute.</p>
549 * <p>This routine handles the common setup. It creates objects
550 * of one of the builtin types, or it uses Class.forName() to
551 * access a user specified class. It then locates either the
552 * inline XML elements or the external XML file. It passes the
553 * XML to initialize the object. Finally, a reference to the
554 * object is stored in the appropriate Map.</p>
556 * <p>The objects created implement two interfaces. Mostly they
557 * implement a configuration interface (EntityDescriptor, ITrust,
558 * AAP, etc). However, for the purpose of this routine they also
559 * must be declared to implement PluggableConfigurationComponent
560 * and provide an initialize() method that parses a DOM Node
561 * containing their root XML configuration element.</p>
563 * @param pluggable XMLBean for element defined in XSD to be of "PluggableType"
564 * @param implclass java.lang.Class of Builtin implementation class
565 * @param interfaceClass java.lang.Class of Interface
566 * @param builtinName alias type to choose Builtin imlementation
567 * @param uriMap ApplicationInfo Map for this interface
573 PluggableType pluggable,
575 Class interfaceClass,
578 Map /*<String,PluggableConfigurationComponent>*/uriMap
581 String pluggabletype = pluggable.getType();
583 if (!pluggabletype.equals(builtinName)) {
584 // Not the builtin type, try to load user class by name
586 implclass = Class.forName(pluggabletype);
587 } catch (ClassNotFoundException e) {
588 log.error("Type value "+pluggabletype+" not found as supplied Java class");
591 if (!interfaceClass.isAssignableFrom(implclass)||
592 !PluggableConfigurationComponent.class.isAssignableFrom(implclass)) {
593 log.error(pluggabletype+" class does not support required interfaces.");
598 PluggableConfigurationComponent impl;
600 impl = (PluggableConfigurationComponent) implclass.newInstance();
601 } catch (Exception e) {
602 log.error("Unable to instantiate "+pluggabletype);
606 String uri = pluggable.getUri();
607 if (uri==null) { // inline
611 Node fragment = pluggable.newDomNode(); // XML-Fragment node
612 Node pluggableNode = fragment.getFirstChild(); // PluggableType
613 Node contentNode=pluggableNode.getFirstChild();// root element
614 impl.initialize(contentNode);
615 } catch (Exception e) {
616 log.error("XML error " + e);
620 } else { // external file
622 if (uriMap.get(uri)!=null) { // Already parsed this file
627 String tempname = impl.getSchemaPathname();
632 Document extdoc = Parser.loadDom(uri,true);
635 impl.initialize(extdoc);
636 } catch (Exception e) {
637 log.error("XML error " + e);
642 uriMap.put(uri,impl);
649 * Handle a FederationProvider
651 private boolean processPluggableMetadata(ApplicationInfo appinfo) {
652 boolean anyError = false;
653 PluggableType[] pluggable = appinfo.getApplicationConfig().getFederationProviderArray();
654 for (int i = 0;i<pluggable.length;i++) {
655 String uri = processPluggable(pluggable[i],
656 XMLMetadataImpl.class,
658 XMLFEDERATIONPROVIDERTYPE,
663 else if (uri.length()>0) {
664 appinfo.addGroupUri(uri);
671 * Reload XML Metadata configuration after file changed.
672 * @param uri Path to Metadata XML configuration
673 * @return true if file reloaded.
675 public boolean reloadFederation(String uri) {
676 if (getMetadataImplementor(uri)!=null||
677 uri.startsWith(INLINEURN))
680 Document sitedoc = Parser.loadDom(uri,true);
683 XMLMetadataImpl impl = new XMLMetadataImpl();
684 impl.initialize(sitedoc);
685 addOrReplaceMetadataImplementor(uri,impl);
686 } catch (Exception e) {
687 log.error("Error while parsing Metadata file "+uri);
688 log.error("XML error " + e);
695 * Handle an AAPProvider element with
696 * type="edu.internet2.middleware.shibboleth.common.provider.XMLAAP"
697 * @throws InternalConfigurationException
699 private boolean processPluggableAAPs(ApplicationInfo appinfo){
700 boolean anyError=false;
701 PluggableType[] pluggable = appinfo.getApplicationConfig().getAAPProviderArray();
702 for (int i = 0;i<pluggable.length;i++) {
703 String uri = processPluggable(pluggable[i],
711 else if (uri.length()>0) {
712 appinfo.addAapUri(uri);
719 * Reload XML AAP configuration after file changed.
720 * @param uri AAP to Trust XML configuration
721 * @return true if file reloaded.
723 public boolean reloadAAP(String uri) {
724 if (getAAPImplementor(uri)!=null||
725 uri.startsWith(INLINEURN))
728 Document aapdoc = Parser.loadDom(uri,true);
731 AttributeAcceptancePolicyDocument aap = AttributeAcceptancePolicyDocument.Factory.parse(aapdoc);
732 XMLAAPImpl impl = new XMLAAPImpl();
733 impl.initialize(aapdoc);
734 addOrReplaceAAPImplementor(uri,impl);
735 } catch (Exception e) {
736 log.error("Error while parsing AAP file "+uri);
737 log.error("XML error " + e);
745 * Handle a TrustProvider element with
746 * type="edu.internet2.middleware.shibboleth.common.provider.XMLTrust"
748 * Note: This code builds the semantic structure of trust. That is, it knows
749 * about certificates and keys. The actual logic of Trust (signature generation
750 * and validation) is implemented in a peer object defined in the external
751 * class XMLTrustImpl.
753 * @throws ShibbolethConfigurationException if X.509 certificate cannot be processed
754 * @throws InternalConfigurationException
756 private boolean processPluggableTrusts(ApplicationInfo appinfo){
757 boolean anyError=false;
758 PluggableType[] pluggable = appinfo.getApplicationConfig().getTrustProviderArray();
759 for (int i = 0;i<pluggable.length;i++) {
760 String uri = processPluggable(pluggable[i],
761 ShibbolethTrust.class,
763 XMLTRUSTPROVIDERTYPE,
765 certificateValidators);
768 else if (uri.length()>0) {
769 appinfo.addTrustUri(uri);
777 private boolean processPluggableRequestMapProvider(){
778 LocalConfigurationType shire = config.getSHIRE();
779 PluggableType mapProvider = shire.getRequestMapProvider();
781 String pluggabletype = mapProvider.getType();
782 if (!pluggabletype.equals(XMLREQUESTMAPPROVIDERTYPE)) {
783 log.error("Unsupported RequestMapProvider type "+pluggabletype);
787 RequestMapDocument requestMapDoc = null;
788 Document mapdoc = null;
789 Element maproot = null;
790 String uri = mapProvider.getUri();
792 if (uri==null) { // inline
796 Node fragment = mapProvider.newDomNode();
797 Node pluggableNode = fragment.getFirstChild();
798 Node contentNode=pluggableNode.getFirstChild();
800 requestMapDoc = RequestMapDocument.Factory.parse(contentNode);
801 } catch (Exception e) {
802 log.error("Error while parsing inline RequestMap");
803 log.error("XML error " + e);
807 } else { // external file
809 mapdoc = Parser.loadDom(uri,true);
812 requestMapDoc = RequestMapDocument.Factory.parse(mapdoc);
813 } catch (Exception e) {
814 log.error("Error while parsing RequestMap file "+uri);
815 log.error("XML error " + e);
820 requestMap = requestMapDoc.getRequestMap();
826 private int inlinenum = 1;
827 private String genDummyUri() {
828 return INLINEURN+Integer.toString(inlinenum++);
837 * ApplicationInfo represents the <Application(s)> object, its fields,
838 * and the pluggable configuration elements under it.
840 * <p>It can return arrays of Metadata, Trust, or AAP providers, but
841 * it also exposes convenience methods that shop the lookup(),
842 * validate(), and trust() calls to each object in the collection
843 * until success or failure is determined.</p>
845 * <p>For all other parameters, such as Session parameters, you
846 * can fetch the XMLBean by calling getApplicationConf() and
847 * query their value directly.
849 public class ApplicationInfo
850 implements Metadata, Trust {
852 private Application applicationConfig;
853 public Application getApplicationConfig() {
854 return applicationConfig;
858 * Construct this object from the XML Bean.
859 * @param application XMLBean for Application element
861 ApplicationInfo(Application application) {
862 this.applicationConfig=application;
867 * Following the general rule, this object may not keep
868 * direct references to the plugin interface implementors,
869 * but must look them up on every call through their URI keys.
870 * So we keep collections of URI strings instead.
872 ArrayList groupUris = new ArrayList();
873 ArrayList trustUris = new ArrayList();
874 ArrayList aapUris = new ArrayList();
876 void addGroupUri(String uri) {
879 void addTrustUri(String uri) {
882 void addAapUri(String uri) {
887 * Return the current array of objects that implement the
888 * ...metadata.Metadata interface
892 Metadata[] getMetadataProviders() {
893 Iterator iuris = groupUris.iterator();
894 int count = groupUris.size();
895 Metadata[] metadatas = new Metadata[count];
896 for (int i=0;i<count;i++) {
897 String uri =(String) iuris.next();
898 metadatas[i]=getMetadataImplementor(uri);
904 * A convenience function based on the Metadata interface.
906 * <p>Look for an entity ID through each implementor until the
907 * first one finds locates a describing object.</p>
909 * <p>Unfortunately, Metadata.lookup() was originally specified to
910 * return a "Provider". In current SAML 2.0 terms, the object
911 * returned should be an EntityDescriptor. So this is the new
912 * function in the new interface that will use the new term, but
913 * it does the same thing.</p>
915 * @param id ID of the OriginSite entity
916 * @return EntityDescriptor metadata object for that site.
918 public EntityDescriptor lookup(String id) {
919 Iterator iuris = groupUris.iterator();
920 while (iuris.hasNext()) {
921 String uri =(String) iuris.next();
922 Metadata locator=getMetadataImplementor(uri);
923 EntityDescriptor entity = locator.lookup(id);
930 public EntityDescriptor lookup(Artifact artifact) {
931 Iterator iuris = groupUris.iterator();
932 while (iuris.hasNext()) {
933 String uri =(String) iuris.next();
934 Metadata locator=getMetadataImplementor(uri);
935 EntityDescriptor entity = locator.lookup(artifact);
943 * Return the current array of objects that implement the ITrust interface
947 public Trust[] getTrustProviders() {
948 Iterator iuris = groupUris.iterator();
949 int count = groupUris.size();
950 Trust[] trusts = new Trust[count];
951 for (int i=0;i<count;i++) {
952 String uri =(String) iuris.next();
953 trusts[i]=getTrustImplementor(uri);
959 * Return the current array of objects that implement the AAP interface
963 public AAP[] getAAPProviders() {
964 Iterator iuris = aapUris.iterator();
965 int count = aapUris.size();
966 AAP[] aaps = new AAP[count];
967 for (int i=0;i<count;i++) {
968 String uri =(String) iuris.next();
969 aaps[i]=getAAPImplementor(uri);
975 * Convenience function to apply AAP by calling the apply()
976 * method of each AAP implementor.
978 * <p>Any AAP implementor can delete an assertion or value.
979 * Empty SAML elements get removed from the assertion.
980 * This can yield an AttributeAssertion with no attributes.
982 * @param assertion SAML Attribute Assertion
983 * @param role Role that issued the assertion
984 * @throws SAMLException Raised if assertion is mangled beyond repair
986 void applyAAP(SAMLAssertion assertion, RoleDescriptor role) throws SAMLException {
988 // Foreach AAP in the collection
989 AAP[] providers = getAAPProviders();
990 if (providers.length == 0) {
991 log.info("no filters specified, accepting entire assertion");
994 for (int i=0;i<providers.length;i++) {
995 AAP aap = providers[i];
996 if (aap.anyAttribute()) {
997 log.info("any attribute enabled, accepting entire assertion");
1002 // Foreach Statement in the Assertion
1003 Iterator statements = assertion.getStatements();
1005 while (statements.hasNext()) {
1006 Object statement = statements.next();
1007 if (statement instanceof SAMLAttributeStatement) {
1008 SAMLAttributeStatement attributeStatement = (SAMLAttributeStatement) statement;
1010 // Check each attribute, applying any matching rules.
1011 Iterator attributes = attributeStatement.getAttributes();
1013 while (attributes.hasNext()) {
1014 SAMLAttribute attribute = (SAMLAttribute) attributes.next();
1015 boolean ruleFound = false;
1016 for (int i=0;i<providers.length;i++) {
1017 AttributeRule rule = providers[i].lookup(attribute.getName(),attribute.getNamespace());
1021 rule.apply(attribute,role);
1023 catch (SAMLException ex) {
1024 log.info("no values remain, removing attribute");
1025 attributeStatement.removeAttribute(iattribute--);
1031 log.warn("no rule found for attribute (" + attribute.getName() + "), filtering it out");
1032 attributeStatement.removeAttribute(iattribute--);
1038 attributeStatement.checkValidity();
1041 catch (SAMLException ex) {
1042 // The statement is now defunct.
1043 log.info("no attributes remain, removing statement");
1044 assertion.removeStatement(istatement);
1049 // Now see if we trashed it irrevocably.
1050 assertion.checkValidity();
1055 * Returns a collection of attribute names to request from the AA.
1057 * @return Collection of attribute Name values
1059 public Collection getAttributeDesignators() {
1060 // TODO Not sure where this should come from
1061 return new ArrayList();
1066 * Convenience method implementing ITrust.validate() across
1067 * the collection of implementing objects. Returns true if
1068 * any Trust implementor approves the signatures in the object.
1070 * <p>In the interface, validate() is passed several arguments
1071 * that come from this object. In this function, those
1072 * arguments are ignored "this" is used.
1076 SAMLSignedObject token,
1081 Trust[] trustProviders = getTrustProviders();
1082 for (int i=0;i<trustProviders.length;i++) {
1083 Trust trust = trustProviders[i];
1084 if (trust.validate(token,role))
1092 * A method of ITrust that we must declare to claim that
1093 * ApplicationInfo implements ITrust. However, no code in the
1094 * ServiceProvider calls this (probably an Origin thing).
1096 * @param revocations
1098 * @return This dummy always returns false.
1100 public boolean attach(Iterator revocations, RoleDescriptor role) {
1105 public boolean validate(X509Certificate certificateEE, X509Certificate[] certificateChain, RoleDescriptor descriptor) {
1106 Trust[] trustProviders = getTrustProviders();
1107 for (int i=0;i<trustProviders.length;i++) {
1108 Trust trust = trustProviders[i];
1109 if (trust.validate(certificateEE,certificateChain,descriptor))
1115 public boolean validate(X509Certificate certificateEE, X509Certificate[] certificateChain, RoleDescriptor descriptor, boolean checkName) {
1116 Trust[] trustProviders = getTrustProviders();
1117 for (int i=0;i<trustProviders.length;i++) {
1118 Trust trust = trustProviders[i];
1119 if (trust.validate(certificateEE,certificateChain,descriptor,checkName))
1128 private static class InternalConfigurationException extends Exception {
1129 InternalConfigurationException() {