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;
22 import javax.xml.namespace.QName;
24 import org.apache.log4j.Logger;
25 import org.opensaml.common.IdentifierGenerator;
26 import org.opensaml.common.SAMLObject;
27 import org.opensaml.common.binding.decoding.MessageDecoderFactory;
28 import org.opensaml.common.binding.encoding.MessageEncoderFactory;
29 import org.opensaml.saml2.metadata.provider.MetadataProvider;
31 import edu.internet2.middleware.shibboleth.common.log.AuditLogEntry;
32 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
33 import edu.internet2.middleware.shibboleth.common.profile.ProfileResponse;
34 import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractShibbolethProfileHandler;
35 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
36 import edu.internet2.middleware.shibboleth.idp.session.Session;
39 * Base class for SAML profile handlers.
41 public abstract class AbstractSAMLProfileHandler extends
42 AbstractShibbolethProfileHandler<SAMLMDRelyingPartyConfigurationManager, Session> {
44 /** SAML message audit log. */
45 private final Logger auditLog = Logger.getLogger(AuditLogEntry.AUDIT_LOGGER_NAME);
47 /** Generator of IDs which may be used for SAML assertions, requests, etc. */
48 private IdentifierGenerator idGenerator;
50 /** Factory of message decoders. */
51 private MessageDecoderFactory decoderFactory;
53 /** Factory of message encoders. */
54 private MessageEncoderFactory encoderFactory;
57 protected AbstractSAMLProfileHandler() {
62 * Gets an ID generator which may be used for SAML assertions, requests, etc.
64 * @return ID generator
66 public IdentifierGenerator getIdGenerator() {
71 * Gets an ID generator which may be used for SAML assertions, requests, etc.
73 * @param generator an ID generator which may be used for SAML assertions, requests, etc
75 public void setIdGenerator(IdentifierGenerator generator){
76 idGenerator = generator;
80 * Gets the factory used to build new message decoders.
82 * @return factory used to build new message decoders
84 public MessageDecoderFactory getMessageDecoderFactory() {
85 return decoderFactory;
89 * Sets the factory used to build new message decoders.
91 * @param factory factory used to build new message decoders
93 public void setMessageDecoderFactory(MessageDecoderFactory factory) {
94 decoderFactory = factory;
98 * Gets the factory used to build message encoders.
100 * @return factory used to build message encoders
102 public MessageEncoderFactory getMessageEncoderFactory() {
103 return encoderFactory;
107 * Sets the factory used to build message encoders.
109 * @param factory factory used to build message encoders
111 public void setMessageEncoderFactory(MessageEncoderFactory factory) {
112 encoderFactory = factory;
116 * A convenience method for retrieving the SAML metadata provider from the relying party manager.
118 * @return the metadata provider or null
120 public MetadataProvider getMetadataProvider() {
121 SAMLMDRelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
122 if (rpcManager != null) {
123 return rpcManager.getMetadataProvider();
130 * Gets the audit log for this handler.
132 * @return audit log for this handler
134 protected Logger getAduitLog() {
139 * Gets the user's session ID from the current request.
141 * @param request current request
143 * @return user's session ID
145 protected String getUserSessionId(ProfileRequest<ServletRequest> request) {
146 HttpServletRequest rawRequest = (HttpServletRequest) request.getRawRequest();
147 if (rawRequest != null) {
148 return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
155 * Contextual object used to accumlate information as profile requests are being processed.
157 * @param <StatusType> type of Status object
159 protected class SAMLProfileRequestContext<StatusType extends SAMLObject> extends ShibbolethProfileRequestContext {
161 /** Role descriptor name that the asserting party is operating in. */
162 private QName assertingPartyRole;
164 /** Role descriptor name that the relying party is operating in. */
165 private QName relyingPartyRole;
170 * @param request current profile request
171 * @param response current profile response
173 public SAMLProfileRequestContext(ProfileRequest<ServletRequest> request,
174 ProfileResponse<ServletResponse> response) {
175 super(request, response);
179 * Gets the role descriptor name that the asserting party is operating in.
181 * @return role descriptor name that the asserting party is operating in
183 public QName getAssertingPartyRole() {
184 return assertingPartyRole;
188 * Sets the role descriptor name that the asserting party is operating in.
190 * @param role role descriptor name that the asserting party is operating in
192 public void setAssertingPartyRole(QName role) {
193 assertingPartyRole = role;
197 * Gets the role descriptor name that the relying party is operating in.
199 * @return role descriptor name that the relying party is operating in
201 public QName getRelyingPartyRole() {
202 return relyingPartyRole;
206 * Sets the role descriptor name that the relying party is operating in.
208 * @param role role descriptor name that the relying party is operating in
210 public void setRelyingPartyRole(QName role) {
211 relyingPartyRole = role;