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