View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
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
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
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.
15   */
16  
17  package edu.internet2.middleware.shibboleth.common.profile.provider;
18  
19  import org.opensaml.Configuration;
20  import org.opensaml.ws.transport.http.HTTPInTransport;
21  import org.opensaml.ws.transport.http.HTTPOutTransport;
22  import org.opensaml.xml.XMLObjectBuilderFactory;
23  import org.opensaml.xml.parse.ParserPool;
24  
25  import edu.internet2.middleware.shibboleth.common.relyingparty.ProfileConfiguration;
26  import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration;
27  import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfigurationManager;
28  import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
29  import edu.internet2.middleware.shibboleth.common.session.Session;
30  import edu.internet2.middleware.shibboleth.common.session.SessionManager;
31  
32  /**
33   * A processor for a communication profile supported by Shibboleth.
34   * 
35   * Profile handlers must be stateless and thread-safe as a single instance may be used to service every incoming
36   * request.
37   * 
38   * @param <RPManagerType> type of relying party configuration manager used by this profile handler
39   * @param <SessionType> type of sessions managed by the session manager used by this profile handler
40   */
41  public abstract class AbstractShibbolethProfileHandler<RPManagerType extends SAMLMDRelyingPartyConfigurationManager, SessionType extends Session>
42          extends AbstractRequestURIMappedProfileHandler<HTTPInTransport, HTTPOutTransport> {
43  
44      /** Pool of XML parsers. */
45      private ParserPool parserPool;
46      
47      /** Relying party configuration manager for the profile handler. */
48      private RPManagerType rpManager;
49  
50      /** Session manager for the profile handler. */
51      private SessionManager<SessionType> sessionManager;
52  
53      /** For building XML. */
54      private XMLObjectBuilderFactory builderFactory;
55  
56      /** Constructor. */
57      protected AbstractShibbolethProfileHandler() {
58          super();
59          builderFactory = Configuration.getBuilderFactory();
60      }
61  
62      /**
63       * Gets the ID of the profile supported by this handler.
64       * 
65       * @return ID of the profile supported by this handler
66       */
67      public abstract String getProfileId();
68      
69      /**
70       * Gets the pool of XML parsers.
71       * 
72       * @return pool of XML parsers.
73       */
74      public ParserPool getParserPool() {
75          return parserPool;
76      }
77      
78      /**
79       * Sets the pool of XML parsers.
80       * 
81       * @param pool pool of XML parsers
82       */
83      public void setParserPool(ParserPool pool) {
84          parserPool = pool;
85      }
86  
87      /**
88       * Gets the relying party manager for this profile handler.
89       * 
90       * @return relying party manager for this profile handler
91       */
92      public RPManagerType getRelyingPartyConfigurationManager() {
93          return rpManager;
94      }
95  
96      /**
97       * Sets the relying party manager for this profile handler.
98       * 
99       * @param manager relying party manager for this profile handler
100      */
101     public void setRelyingPartyConfigurationManager(RPManagerType manager) {
102         rpManager = manager;
103     }
104 
105     /**
106      * Gets the relying party configuration for the given entity. This is only a convenience method and is equivalent to
107      * retrieving the relying party configuration by invoking {@link #getRelyingPartyConfigurationManager()} and then
108      * invoking {@link RelyingPartyConfigurationManager#getRelyingPartyConfiguration(String)}.
109      * 
110      * @param relyingPartyId ID of the relying party
111      * 
112      * @return the relying party configuration or null
113      */
114     public RelyingPartyConfiguration getRelyingPartyConfiguration(String relyingPartyId) {
115         RelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
116         if (rpcManager != null) {
117             return rpcManager.getRelyingPartyConfiguration(relyingPartyId);
118         }
119         
120         return null;
121     }
122 
123     /**
124      * Gets the profile configuration for the given entity and profile Id. This is only a convenience method and is
125      * equivalent to retrieving the relying party configuration by invoking
126      * {@link #getRelyingPartyConfiguration(String)} following by
127      * {@link RelyingPartyConfiguration#getProfileConfiguration(String)}
128      * 
129      * @param relyingPartyId ID of the relying party
130      * @param profileId unique ID of the profile
131      * 
132      * @return the profile configuration or null
133      */
134     public ProfileConfiguration getProfileConfiguration(String relyingPartyId, String profileId) {
135         RelyingPartyConfiguration rpConfig = getRelyingPartyConfiguration(relyingPartyId);
136         if (rpConfig != null) {
137             return rpConfig.getProfileConfigurations().get(profileId);
138         }
139 
140         return null;
141     }
142 
143     /**
144      * Gets the session manager for this profile handler.
145      * 
146      * @return session manager for this profile handler
147      */
148     public SessionManager<SessionType> getSessionManager() {
149         return sessionManager;
150     }
151 
152     /**
153      * Sets the session manager for this profile handler.
154      * 
155      * @param manager session manager for this profile handler
156      */
157     public void setSessionManager(SessionManager<SessionType> manager) {
158         sessionManager = manager;
159     }
160 
161     /**
162      * Convenience method for getting the XML object builder factory.
163      * 
164      * @return XML object builder factory
165      */
166     public XMLObjectBuilderFactory getBuilderFactory() {
167         return builderFactory;
168     }
169 }