1 /* 2 * Licensed to the University Corporation for Advanced Internet Development, 3 * Inc. (UCAID) under one or more contributor license agreements. See the 4 * NOTICE file distributed with this work for additional information regarding 5 * copyright ownership. The UCAID licenses this file to You under the Apache 6 * License, Version 2.0 (the "License"); you may not use this file except in 7 * compliance with the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package edu.internet2.middleware.shibboleth.common.profile.provider; 19 20 import org.opensaml.Configuration; 21 import org.opensaml.util.storage.StorageService; 22 import org.opensaml.ws.transport.http.HTTPInTransport; 23 import org.opensaml.ws.transport.http.HTTPOutTransport; 24 import org.opensaml.xml.XMLObjectBuilderFactory; 25 import org.opensaml.xml.parse.ParserPool; 26 27 import edu.internet2.middleware.shibboleth.common.relyingparty.ProfileConfiguration; 28 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration; 29 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfigurationManager; 30 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager; 31 import edu.internet2.middleware.shibboleth.common.session.Session; 32 import edu.internet2.middleware.shibboleth.common.session.SessionManager; 33 34 /** 35 * A processor for a communication profile supported by Shibboleth. 36 * 37 * Profile handlers must be stateless and thread-safe as a single instance may be used to service every incoming 38 * request. 39 * 40 * @param <RPManagerType> type of relying party configuration manager used by this profile handler 41 * @param <SessionType> type of sessions managed by the session manager used by this profile handler 42 */ 43 public abstract class AbstractShibbolethProfileHandler<RPManagerType extends SAMLMDRelyingPartyConfigurationManager, SessionType extends Session> 44 extends AbstractRequestURIMappedProfileHandler<HTTPInTransport, HTTPOutTransport> { 45 46 /** Pool of XML parsers. */ 47 private ParserPool parserPool; 48 49 /** Profile storage service. */ 50 private StorageService<?, ?> storageService; 51 52 /** Relying party configuration manager for the profile handler. */ 53 private RPManagerType rpManager; 54 55 /** Session manager for the profile handler. */ 56 private SessionManager<SessionType> sessionManager; 57 58 /** For building XML. */ 59 private XMLObjectBuilderFactory builderFactory; 60 61 /** Constructor. */ 62 protected AbstractShibbolethProfileHandler() { 63 super(); 64 builderFactory = Configuration.getBuilderFactory(); 65 } 66 67 /** 68 * Gets the ID of the profile supported by this handler. 69 * 70 * @return ID of the profile supported by this handler 71 */ 72 public abstract String getProfileId(); 73 74 /** 75 * Gets the pool of XML parsers. 76 * 77 * @return pool of XML parsers. 78 */ 79 public ParserPool getParserPool() { 80 return parserPool; 81 } 82 83 /** 84 * Sets the pool of XML parsers. 85 * 86 * @param pool pool of XML parsers 87 */ 88 public void setParserPool(ParserPool pool) { 89 parserPool = pool; 90 } 91 92 /** 93 * Gets the storage service used to store profile data. 94 * 95 * @return storage service used to store profile data 96 */ 97 public StorageService<?, ?> getStorageService() { 98 return storageService; 99 } 100 101 /** 102 * Sets the storage service used to store profile data. 103 * 104 * @param service storage service used to store profile data 105 */ 106 public void setStorageService(StorageService<?, ?> service) { 107 storageService = service; 108 } 109 110 /** 111 * Gets the relying party manager for this profile handler. 112 * 113 * @return relying party manager for this profile handler 114 */ 115 public RPManagerType getRelyingPartyConfigurationManager() { 116 return rpManager; 117 } 118 119 /** 120 * Sets the relying party manager for this profile handler. 121 * 122 * @param manager relying party manager for this profile handler 123 */ 124 public void setRelyingPartyConfigurationManager(RPManagerType manager) { 125 rpManager = manager; 126 } 127 128 /** 129 * Gets the relying party configuration for the given entity. This is only a convenience method and is equivalent to 130 * retrieving the relying party configuration by invoking {@link #getRelyingPartyConfigurationManager()} and then 131 * invoking {@link RelyingPartyConfigurationManager#getRelyingPartyConfiguration(String)}. 132 * 133 * @param relyingPartyId ID of the relying party 134 * 135 * @return the relying party configuration or null 136 */ 137 public RelyingPartyConfiguration getRelyingPartyConfiguration(String relyingPartyId) { 138 RelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager(); 139 if (rpcManager != null) { 140 return rpcManager.getRelyingPartyConfiguration(relyingPartyId); 141 } 142 143 return null; 144 } 145 146 /** 147 * Gets the profile configuration for the given entity and profile Id. This is only a convenience method and is 148 * equivalent to retrieving the relying party configuration by invoking 149 * {@link #getRelyingPartyConfiguration(String)} following by 150 * {@link RelyingPartyConfiguration#getProfileConfiguration(String)} 151 * 152 * @param relyingPartyId ID of the relying party 153 * @param profileId unique ID of the profile 154 * 155 * @return the profile configuration or null 156 */ 157 public ProfileConfiguration getProfileConfiguration(String relyingPartyId, String profileId) { 158 RelyingPartyConfiguration rpConfig = getRelyingPartyConfiguration(relyingPartyId); 159 if (rpConfig != null) { 160 return rpConfig.getProfileConfigurations().get(profileId); 161 } 162 163 return null; 164 } 165 166 /** 167 * Gets the session manager for this profile handler. 168 * 169 * @return session manager for this profile handler 170 */ 171 public SessionManager<SessionType> getSessionManager() { 172 return sessionManager; 173 } 174 175 /** 176 * Sets the session manager for this profile handler. 177 * 178 * @param manager session manager for this profile handler 179 */ 180 public void setSessionManager(SessionManager<SessionType> manager) { 181 sessionManager = manager; 182 } 183 184 /** 185 * Convenience method for getting the XML object builder factory. 186 * 187 * @return XML object builder factory 188 */ 189 public XMLObjectBuilderFactory getBuilderFactory() { 190 return builderFactory; 191 } 192 }