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.http.HttpServletRequest;
21 import org.apache.log4j.Logger;
22 import org.opensaml.common.IdentifierGenerator;
23 import org.opensaml.common.binding.decoding.SAMLMessageDecoder;
24 import org.opensaml.common.binding.encoding.SAMLMessageEncoder;
25 import org.opensaml.saml2.metadata.provider.MetadataProvider;
26 import org.opensaml.ws.transport.InTransport;
27 import org.opensaml.ws.transport.http.HttpServletRequestAdapter;
29 import edu.internet2.middleware.shibboleth.common.log.AuditLogEntry;
30 import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractShibbolethProfileHandler;
31 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
32 import edu.internet2.middleware.shibboleth.idp.session.Session;
35 * Base class for SAML profile handlers.
37 public abstract class AbstractSAMLProfileHandler extends
38 AbstractShibbolethProfileHandler<SAMLMDRelyingPartyConfigurationManager, Session> {
40 /** SAML message audit log. */
41 private final Logger auditLog = Logger.getLogger(AuditLogEntry.AUDIT_LOGGER_NAME);
43 /** Generator of IDs which may be used for SAML assertions, requests, etc. */
44 private IdentifierGenerator idGenerator;
46 /** Decoder used to extract message information from the inbound transport. */
47 private SAMLMessageDecoder messageDecoder;
49 /** Encoder used to bind information to the outbound message transport. */
50 private SAMLMessageEncoder messageEncoder;
53 protected AbstractSAMLProfileHandler() {
58 * Gets the audit log for this handler.
60 * @return audit log for this handler
62 protected Logger getAduitLog() {
67 * Gets an ID generator which may be used for SAML assertions, requests, etc.
69 * @return ID generator
71 public IdentifierGenerator getIdGenerator() {
76 * Gets the decoder used to extract message information from the inbound transport.
78 * @return decoder used to extract message information from the inbound transport
80 public SAMLMessageDecoder getMessageDecoder() {
81 return messageDecoder;
85 * Gets the encoder used to bind information to the outbound message transport.
87 * @return encoder used to bind information to the outbound message transport
89 public SAMLMessageEncoder getMessageEncoder() {
90 return messageEncoder;
94 * A convenience method for retrieving the SAML metadata provider from the relying party manager.
96 * @return the metadata provider or null
98 public MetadataProvider getMetadataProvider() {
99 SAMLMDRelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
100 if (rpcManager != null) {
101 return rpcManager.getMetadataProvider();
108 * Gets the user's session ID from the current request.
110 * @param inTransport current inbound transport
112 * @return user's session ID
114 protected String getUserSessionId(InTransport inTransport) {
115 HttpServletRequest rawRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
117 if (rawRequest != null) {
118 return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
125 * Gets the user's session, if there is one.
127 * @param inTransport current inbound transport
129 * @return user's session
131 protected Session getUserSession(InTransport inTransport){
132 String sessionId = getUserSessionId(inTransport);
133 return getSessionManager().getSession(sessionId);
137 * Gets an ID generator which may be used for SAML assertions, requests, etc.
139 * @param generator an ID generator which may be used for SAML assertions, requests, etc
141 public void setIdGenerator(IdentifierGenerator generator) {
142 idGenerator = generator;
146 * Sets the decoder used to extract message information from the inbound transport.
148 * @param decoder decoder used to extract message information from the inbound transport
150 public void setMessageDecoder(SAMLMessageDecoder decoder) {
151 messageDecoder = decoder;
155 * Sets the encoder used to bind information to the outbound message transport.
157 * @param encoder encoder used to bind information to the outbound message transport
159 public void setMessageEncoder(SAMLMessageEncoder encoder) {
160 messageEncoder = encoder;