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.EntityDescriptor;
29 import org.opensaml.saml2.metadata.RoleDescriptor;
30 import org.opensaml.saml2.metadata.provider.MetadataProvider;
32 import edu.internet2.middleware.shibboleth.common.log.AuditLogEntry;
33 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
34 import edu.internet2.middleware.shibboleth.common.profile.ProfileResponse;
35 import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractShibbolethProfileHandler;
36 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager;
37 import edu.internet2.middleware.shibboleth.idp.session.Session;
40 * Base class for SAML profile handlers.
42 public abstract class AbstractSAMLProfileHandler extends
43 AbstractShibbolethProfileHandler<SAMLMDRelyingPartyConfigurationManager, Session> {
45 /** SAML message audit log. */
46 private final Logger auditLog = Logger.getLogger(AuditLogEntry.AUDIT_LOGGER_NAME);
48 /** Generator of IDs which may be used for SAML assertions, requests, etc. */
49 private IdentifierGenerator idGenerator;
51 /** Factory of message decoders. */
52 private MessageDecoderFactory decoderFactory;
54 /** Factory of message encoders. */
55 private MessageEncoderFactory encoderFactory;
58 protected AbstractSAMLProfileHandler() {
63 * Gets an ID generator which may be used for SAML assertions, requests, etc.
65 * @return ID generator
67 public IdentifierGenerator getIdGenerator() {
72 * Gets an ID generator which may be used for SAML assertions, requests, etc.
74 * @param generator an ID generator which may be used for SAML assertions, requests, etc
76 public void setIdGenerator(IdentifierGenerator generator) {
77 idGenerator = generator;
81 * Gets the factory used to build new message decoders.
83 * @return factory used to build new message decoders
85 public MessageDecoderFactory getMessageDecoderFactory() {
86 return decoderFactory;
90 * Sets the factory used to build new message decoders.
92 * @param factory factory used to build new message decoders
94 public void setMessageDecoderFactory(MessageDecoderFactory factory) {
95 decoderFactory = factory;
99 * Gets the factory used to build message encoders.
101 * @return factory used to build message encoders
103 public MessageEncoderFactory getMessageEncoderFactory() {
104 return encoderFactory;
108 * Sets the factory used to build message encoders.
110 * @param factory factory used to build message encoders
112 public void setMessageEncoderFactory(MessageEncoderFactory factory) {
113 encoderFactory = factory;
117 * A convenience method for retrieving the SAML metadata provider from the relying party manager.
119 * @return the metadata provider or null
121 public MetadataProvider getMetadataProvider() {
122 SAMLMDRelyingPartyConfigurationManager rpcManager = getRelyingPartyConfigurationManager();
123 if (rpcManager != null) {
124 return rpcManager.getMetadataProvider();
131 * Gets the audit log for this handler.
133 * @return audit log for this handler
135 protected Logger getAduitLog() {
140 * Gets the user's session ID from the current request.
142 * @param request current request
144 * @return user's session ID
146 protected String getUserSessionId(ProfileRequest<ServletRequest> request) {
147 HttpServletRequest rawRequest = (HttpServletRequest) request.getRawRequest();
148 if (rawRequest != null) {
149 return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
156 * Contextual object used to accumlate information as profile requests are being processed.
158 * @param <StatusType> type of Status object
160 protected class SAMLProfileRequestContext<StatusType extends SAMLObject> extends ShibbolethProfileRequestContext {
162 /** Entity descriptor for the asserting party. */
163 private EntityDescriptor assertingPartyMetadata;
165 /** Role descriptor meatadata for the asserting party. */
166 private RoleDescriptor assertingPartyRoleMetadata;
168 /** Entity descriptor for the relying party. */
169 private EntityDescriptor relyingPartyMetadata;
171 /** Role descriptor meatadata for the relying party. */
172 private RoleDescriptor relyingPartyRoleMetadata;
177 * @param request current profile request
178 * @param response current profile response
180 public SAMLProfileRequestContext(ProfileRequest<ServletRequest> request,
181 ProfileResponse<ServletResponse> response) {
182 super(request, response);
186 * Gets the metadata for the asserting party.
188 * @return metadata for the asserting party
190 public EntityDescriptor getAssertingPartyMetadata() {
191 return assertingPartyMetadata;
195 * Sets the metadata for the asserting party.
197 * @param metadata metadata for the asserting party
199 public void setAssertingPartyMetadata(EntityDescriptor metadata) {
200 assertingPartyMetadata = metadata;
204 * Gets the role descriptor for the asserting party.
206 * @return role descriptor for the asserting party
208 public RoleDescriptor getAssertingPartyRoleMetadata() {
209 return assertingPartyRoleMetadata;
213 * Sets the role descriptor for the asserting party.
215 * @param descriptor role descriptor for the asserting party
217 public void setAssertingPartyRoleMetadata(RoleDescriptor descriptor) {
218 assertingPartyRoleMetadata = descriptor;
222 * Gets the metadata for the relying party.
224 * @return metadata for the relying party
226 public EntityDescriptor getRelyingPartyMetadata() {
227 return relyingPartyMetadata;
231 * Sets the metadata for the relying party.
233 * @param metadata metadata for the relying party
235 public void setRelyingPartyMetadata(EntityDescriptor metadata) {
236 relyingPartyMetadata = metadata;
240 * Gets the role descriptor for the relying party.
242 * @return role descriptor for the relying party
244 public RoleDescriptor getRelyingPartyRoleMetadata() {
245 return relyingPartyRoleMetadata;
249 * Sets the role descriptor for the relying party.
251 * @param descriptor role descriptor for the relying party
253 public void setRelyingPartyRoleMetadata(RoleDescriptor descriptor) {
254 relyingPartyRoleMetadata = descriptor;