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.http.HttpServletRequest;
22 import org.apache.log4j.Logger;
23 import org.opensaml.common.IdentifierGenerator;
24 import org.opensaml.common.binding.decoding.MessageDecoderFactory;
25 import org.opensaml.common.binding.encoding.MessageEncoderFactory;
26 import org.opensaml.common.impl.SecureRandomIdentifierGenerator;
27 import org.opensaml.saml2.metadata.provider.MetadataProvider;
29 import edu.internet2.middleware.shibboleth.common.log.AuditLogEntry;
30 import edu.internet2.middleware.shibboleth.common.profile.AbstractProfileHandler;
31 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
32 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
33 import edu.internet2.middleware.shibboleth.idp.session.Session;
36 * Base class for SAML profile handlers.
38 public abstract class AbstractSAMLProfileHandler extends
39 AbstractProfileHandler<SAMLMDRelyingPartyConfigurationManager, Session> {
41 /** SAML message audit log. */
42 private final Logger auditLog = Logger.getLogger(AuditLogEntry.AUDIT_LOGGER_NAME);
44 /** Generator of IDs which may be used for SAML assertions, requests, etc. */
45 private IdentifierGenerator idGenerator;
47 /** Factory of message decoders. */
48 private MessageDecoderFactory decoderFactory;
50 /** Factory of message encoders. */
51 private MessageEncoderFactory encoderFactory;
54 protected AbstractSAMLProfileHandler() {
56 idGenerator = new SecureRandomIdentifierGenerator();
60 * Gets an ID generator which may be used for SAML assertions, requests, etc.
62 * @return ID generator
64 public IdentifierGenerator getIdGenerator() {
69 * Gets the factory used to build new message decoders.
71 * @return factory used to build new message decoders
73 public MessageDecoderFactory getMessageDecoderFactory() {
74 return decoderFactory;
78 * Sets the factory used to build new message decoders.
80 * @param factory factory used to build new message decoders
82 public void setMessageDecoderFactory(MessageDecoderFactory factory) {
83 decoderFactory = factory;
87 * Gets the factory used to build message encoders.
89 * @return factory used to build message encoders
91 public MessageEncoderFactory getMessageEncoderFactory() {
92 return encoderFactory;
96 * Sets the factory used to build message encoders.
98 * @param factory factory used to build message encoders
100 public void setMessageEncoderFactory(MessageEncoderFactory factory) {
101 encoderFactory = factory;
105 * A convenience method for retrieving the SAML metadata provider from the relying party manager.
107 * @return the metadata provider or null
109 public MetadataProvider getMetadataProvider() {
110 SAMLMDRelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
111 if (rpcManager != null) {
112 return rpcManager.getMetadataProvider();
119 * Gets the audit log for this handler.
121 * @return audit log for this handler
123 protected Logger getAduitLog() {
128 * Gets the user's session ID from the current request.
130 * @param request current request
132 * @return user's session ID
134 protected String getUserSessionId(ProfileRequest<ServletRequest> request) {
135 HttpServletRequest rawRequest = (HttpServletRequest) request.getRawRequest();
136 if (rawRequest != null) {
137 return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);