2 * Copyright [2007] [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.profile;
19 import javax.servlet.ServletRequest;
20 import javax.servlet.ServletResponse;
21 import javax.servlet.http.HttpServletRequest;
23 import org.apache.log4j.Logger;
24 import org.opensaml.common.IdentifierGenerator;
25 import org.opensaml.common.SAMLObject;
26 import org.opensaml.common.binding.decoding.MessageDecoderFactory;
27 import org.opensaml.common.binding.encoding.MessageEncoderFactory;
28 import org.opensaml.saml2.metadata.Endpoint;
29 import org.opensaml.saml2.metadata.EntityDescriptor;
30 import org.opensaml.saml2.metadata.RoleDescriptor;
31 import org.opensaml.saml2.metadata.provider.MetadataProvider;
33 import edu.internet2.middleware.shibboleth.common.log.AuditLogEntry;
34 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
35 import edu.internet2.middleware.shibboleth.common.profile.ProfileResponse;
36 import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractShibbolethProfileHandler;
37 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
38 import edu.internet2.middleware.shibboleth.idp.session.Session;
41 * Base class for SAML profile handlers.
43 public abstract class AbstractSAMLProfileHandler extends
44 AbstractShibbolethProfileHandler<SAMLMDRelyingPartyConfigurationManager, Session> {
46 /** SAML message audit log. */
47 private final Logger auditLog = Logger.getLogger(AuditLogEntry.AUDIT_LOGGER_NAME);
49 /** Generator of IDs which may be used for SAML assertions, requests, etc. */
50 private IdentifierGenerator idGenerator;
52 /** Factory of message decoders. */
53 private MessageDecoderFactory decoderFactory;
55 /** Factory of message encoders. */
56 private MessageEncoderFactory encoderFactory;
59 protected AbstractSAMLProfileHandler() {
64 * Gets an ID generator which may be used for SAML assertions, requests, etc.
66 * @return ID generator
68 public IdentifierGenerator getIdGenerator() {
73 * Gets an ID generator which may be used for SAML assertions, requests, etc.
75 * @param generator an ID generator which may be used for SAML assertions, requests, etc
77 public void setIdGenerator(IdentifierGenerator generator) {
78 idGenerator = generator;
82 * Gets the factory used to build new message decoders.
84 * @return factory used to build new message decoders
86 public MessageDecoderFactory getMessageDecoderFactory() {
87 return decoderFactory;
91 * Sets the factory used to build new message decoders.
93 * @param factory factory used to build new message decoders
95 public void setMessageDecoderFactory(MessageDecoderFactory factory) {
96 decoderFactory = factory;
100 * Gets the factory used to build message encoders.
102 * @return factory used to build message encoders
104 public MessageEncoderFactory getMessageEncoderFactory() {
105 return encoderFactory;
109 * Sets the factory used to build message encoders.
111 * @param factory factory used to build message encoders
113 public void setMessageEncoderFactory(MessageEncoderFactory factory) {
114 encoderFactory = factory;
118 * A convenience method for retrieving the SAML metadata provider from the relying party manager.
120 * @return the metadata provider or null
122 public MetadataProvider getMetadataProvider() {
123 SAMLMDRelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
124 if (rpcManager != null) {
125 return rpcManager.getMetadataProvider();
132 * Gets the audit log for this handler.
134 * @return audit log for this handler
136 protected Logger getAduitLog() {
141 * Gets the user's session ID from the current request.
143 * @param request current request
145 * @return user's session ID
147 protected String getUserSessionId(ProfileRequest<ServletRequest> request) {
148 HttpServletRequest rawRequest = (HttpServletRequest) request.getRawRequest();
149 if (rawRequest != null) {
150 return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
157 * Contextual object used to accumlate information as profile requests are being processed.
159 * @param <StatusType> type of Status object
161 protected class SAMLProfileRequestContext<StatusType extends SAMLObject> extends ShibbolethProfileRequestContext {
163 /** Entity descriptor for the asserting party. */
164 private EntityDescriptor assertingPartyMetadata;
166 /** Role descriptor meatadata for the asserting party. */
167 private RoleDescriptor assertingPartyRoleMetadata;
169 /** Message decoder URI. */
170 private String messageDecoder;
172 /** Message encoder URI. */
173 private String messageEncoder;
175 /** Request relay state. */
176 private String relayState;
178 /** Endpoint of relying party. */
179 private Endpoint relyingPartyEndpoint;
181 /** Entity descriptor for the relying party. */
182 private EntityDescriptor relyingPartyMetadata;
184 /** Role descriptor meatadata for the relying party. */
185 private RoleDescriptor relyingPartyRoleMetadata;
190 * @param request current profile request
191 * @param response current profile response
193 public SAMLProfileRequestContext(ProfileRequest<ServletRequest> request,
194 ProfileResponse<ServletResponse> response) {
195 super(request, response);
199 * Gets the metadata for the asserting party.
201 * @return metadata for the asserting party
203 public EntityDescriptor getAssertingPartyMetadata() {
204 return assertingPartyMetadata;
208 * Sets the metadata for the asserting party.
210 * @param metadata metadata for the asserting party
212 public void setAssertingPartyMetadata(EntityDescriptor metadata) {
213 assertingPartyMetadata = metadata;
217 * Gets the role descriptor for the asserting party.
219 * @return role descriptor for the asserting party
221 public RoleDescriptor getAssertingPartyRoleMetadata() {
222 return assertingPartyRoleMetadata;
226 * Sets the role descriptor for the asserting party.
228 * @param descriptor role descriptor for the asserting party
230 public void setAssertingPartyRoleMetadata(RoleDescriptor descriptor) {
231 assertingPartyRoleMetadata = descriptor;
235 * Gets the URI of the message decoder used to decode the incoming request.
237 * @return URI of the message decoder used to decode the incoming request
239 public String getMessageDecoder(){
240 return messageDecoder;
244 * Sets the URI of the message decoder used to decode the incoming request.
246 * @param decoderURI URI of the message decoder used to decode the incoming request
248 public void setMessageDecoder(String decoderURI){
249 messageDecoder = decoderURI;
253 * Gets the URI of the message encoder used to encode the outgoing response.
255 * @return URI of the message encoder used to encode the outgoing response
257 public String getMessageEncoder(){
258 return messageEncoder;
262 * Sets the URI of the message encoder used to encode the outgoing response.
264 * @param encoderURI URI of the message encoder used to encode the outgoing response
266 public void setMessageEncoder(String encoderURI){
267 messageEncoder = encoderURI;
271 * Gets the relay state of the current request.
273 * @return relay state of the current request
275 public String getRelayState(){
280 * Sets the relay state of the current request.
282 * @param state relay state of the current request
284 public void setRelayState(String state){
289 * Gets the endpoint for the relying party.
291 * @return endpoint for the relying party
293 public Endpoint getRelyingPartyEndpoint(){
294 return relyingPartyEndpoint;
298 * Sets the endpoint for the relying party.
300 * @param endpoint endpoint for the relying party
302 public void setRelyingPartyEndpoint(Endpoint endpoint){
303 relyingPartyEndpoint = endpoint;
307 * Gets the metadata for the relying party.
309 * @return metadata for the relying party
311 public EntityDescriptor getRelyingPartyMetadata() {
312 return relyingPartyMetadata;
316 * Sets the metadata for the relying party.
318 * @param metadata metadata for the relying party
320 public void setRelyingPartyMetadata(EntityDescriptor metadata) {
321 relyingPartyMetadata = metadata;
325 * Gets the role descriptor for the relying party.
327 * @return role descriptor for the relying party
329 public RoleDescriptor getRelyingPartyRoleMetadata() {
330 return relyingPartyRoleMetadata;
334 * Sets the role descriptor for the relying party.
336 * @param descriptor role descriptor for the relying party
338 public void setRelyingPartyRoleMetadata(RoleDescriptor descriptor) {
339 relyingPartyRoleMetadata = descriptor;