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.binding.decoding.MessageDecoderFactory;
27 import org.opensaml.common.binding.encoding.MessageEncoderFactory;
28 import org.opensaml.saml2.metadata.provider.MetadataProvider;
30 import edu.internet2.middleware.shibboleth.common.log.AuditLogEntry;
31 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
32 import edu.internet2.middleware.shibboleth.common.profile.ProfileResponse;
33 import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractShibbolethProfileHandler;
34 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
35 import edu.internet2.middleware.shibboleth.idp.session.Session;
38 * Base class for SAML profile handlers.
40 public abstract class AbstractSAMLProfileHandler extends
41 AbstractShibbolethProfileHandler<SAMLMDRelyingPartyConfigurationManager, Session> {
43 /** SAML message audit log. */
44 private final Logger auditLog = Logger.getLogger(AuditLogEntry.AUDIT_LOGGER_NAME);
46 /** Generator of IDs which may be used for SAML assertions, requests, etc. */
47 private IdentifierGenerator idGenerator;
49 /** Factory of message decoders. */
50 private MessageDecoderFactory decoderFactory;
52 /** Factory of message encoders. */
53 private MessageEncoderFactory encoderFactory;
56 protected AbstractSAMLProfileHandler() {
61 * Gets an ID generator which may be used for SAML assertions, requests, etc.
63 * @return ID generator
65 public IdentifierGenerator getIdGenerator() {
70 * Gets an ID generator which may be used for SAML assertions, requests, etc.
72 * @param generator an ID generator which may be used for SAML assertions, requests, etc
74 public void setIdGenerator(IdentifierGenerator generator){
75 idGenerator = generator;
79 * Gets the factory used to build new message decoders.
81 * @return factory used to build new message decoders
83 public MessageDecoderFactory getMessageDecoderFactory() {
84 return decoderFactory;
88 * Sets the factory used to build new message decoders.
90 * @param factory factory used to build new message decoders
92 public void setMessageDecoderFactory(MessageDecoderFactory factory) {
93 decoderFactory = factory;
97 * Gets the factory used to build message encoders.
99 * @return factory used to build message encoders
101 public MessageEncoderFactory getMessageEncoderFactory() {
102 return encoderFactory;
106 * Sets the factory used to build message encoders.
108 * @param factory factory used to build message encoders
110 public void setMessageEncoderFactory(MessageEncoderFactory factory) {
111 encoderFactory = factory;
115 * A convenience method for retrieving the SAML metadata provider from the relying party manager.
117 * @return the metadata provider or null
119 public MetadataProvider getMetadataProvider() {
120 SAMLMDRelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
121 if (rpcManager != null) {
122 return rpcManager.getMetadataProvider();
129 * Gets the audit log for this handler.
131 * @return audit log for this handler
133 protected Logger getAduitLog() {
138 * Gets the user's session ID from the current request.
140 * @param request current request
142 * @return user's session ID
144 protected String getUserSessionId(ProfileRequest<ServletRequest> request) {
145 HttpServletRequest rawRequest = (HttpServletRequest) request.getRawRequest();
146 if (rawRequest != null) {
147 return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
154 * Contextual object used to accumlate information as profile requests are being processed.
156 protected class SAMLProfileRequestContext extends ShibbolethProfileRequestContext {
158 /** Role descriptor name that the asserting party is operating in. */
159 private QName assertingPartyRole;
161 /** Role descriptor name that the relying party is operating in. */
162 private QName relyingPartyRole;
167 * @param request current profile request
168 * @param response current profile response
170 public SAMLProfileRequestContext(ProfileRequest<ServletRequest> request,
171 ProfileResponse<ServletResponse> response) {
172 super(request, response);
176 * Gets the role descriptor name that the asserting party is operating in.
178 * @return role descriptor name that the asserting party is operating in
180 public QName getAssertingPartyRole() {
181 return assertingPartyRole;
185 * Sets the role descriptor name that the asserting party is operating in.
187 * @param role role descriptor name that the asserting party is operating in
189 public void setAssertingPartyRole(QName role) {
190 assertingPartyRole = role;
194 * Gets the role descriptor name that the relying party is operating in.
196 * @return role descriptor name that the relying party is operating in
198 public QName getRelyingPartyRole() {
199 return relyingPartyRole;
203 * Sets the role descriptor name that the relying party is operating in.
205 * @param role role descriptor name that the relying party is operating in
207 public void setRelyingPartyRole(QName role) {
208 relyingPartyRole = role;