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.saml1;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
24 import javax.xml.namespace.QName;
26 import org.apache.log4j.Logger;
27 import org.joda.time.DateTime;
28 import org.opensaml.common.SAMLObject;
29 import org.opensaml.common.SAMLObjectBuilder;
30 import org.opensaml.common.SAMLVersion;
31 import org.opensaml.common.impl.SAMLObjectContentReference;
32 import org.opensaml.saml1.core.Assertion;
33 import org.opensaml.saml1.core.AttributeQuery;
34 import org.opensaml.saml1.core.AttributeStatement;
35 import org.opensaml.saml1.core.Audience;
36 import org.opensaml.saml1.core.AudienceRestrictionCondition;
37 import org.opensaml.saml1.core.Conditions;
38 import org.opensaml.saml1.core.ConfirmationMethod;
39 import org.opensaml.saml1.core.NameIdentifier;
40 import org.opensaml.saml1.core.RequestAbstractType;
41 import org.opensaml.saml1.core.Response;
42 import org.opensaml.saml1.core.ResponseAbstractType;
43 import org.opensaml.saml1.core.Statement;
44 import org.opensaml.saml1.core.Status;
45 import org.opensaml.saml1.core.StatusCode;
46 import org.opensaml.saml1.core.StatusMessage;
47 import org.opensaml.saml1.core.Subject;
48 import org.opensaml.saml1.core.SubjectConfirmation;
49 import org.opensaml.saml2.metadata.AttributeAuthorityDescriptor;
50 import org.opensaml.saml2.metadata.AuthnAuthorityDescriptor;
51 import org.opensaml.saml2.metadata.NameIDFormat;
52 import org.opensaml.saml2.metadata.PDPDescriptor;
53 import org.opensaml.saml2.metadata.RoleDescriptor;
54 import org.opensaml.saml2.metadata.SPSSODescriptor;
55 import org.opensaml.saml2.metadata.SSODescriptor;
56 import org.opensaml.xml.XMLObjectBuilder;
57 import org.opensaml.xml.security.credential.Credential;
58 import org.opensaml.xml.signature.Signature;
59 import org.opensaml.xml.signature.Signer;
61 import edu.internet2.middleware.shibboleth.common.attribute.AttributeRequestException;
62 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
63 import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
64 import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncodingException;
65 import edu.internet2.middleware.shibboleth.common.attribute.encoding.SAML1NameIdentifierEncoder;
66 import edu.internet2.middleware.shibboleth.common.attribute.provider.SAML1AttributeAuthority;
67 import edu.internet2.middleware.shibboleth.common.profile.ProfileException;
68 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.saml1.AbstractSAML1ProfileConfiguration;
69 import edu.internet2.middleware.shibboleth.idp.profile.AbstractSAMLProfileHandler;
71 /** Common implementation details for profile handlers. */
72 public abstract class AbstractSAML1ProfileHandler extends AbstractSAMLProfileHandler {
74 /** SAML Version for this profile handler. */
75 public static final SAMLVersion SAML_VERSION = SAMLVersion.VERSION_11;
78 private static Logger log = Logger.getLogger(AbstractSAML1ProfileHandler.class);
80 /** Builder of Response objects. */
81 private SAMLObjectBuilder<Response> responseBuilder;
83 /** Builder of Assertion objects. */
84 private SAMLObjectBuilder<Assertion> assertionBuilder;
86 /** Builder of Conditions objects. */
87 private SAMLObjectBuilder<Conditions> conditionsBuilder;
89 /** Builder of AudienceRestrictionCondition objects. */
90 private SAMLObjectBuilder<AudienceRestrictionCondition> audienceRestrictionConditionBuilder;
92 /** Builder of AudienceRestrictionCondition objects. */
93 private SAMLObjectBuilder<Audience> audienceBuilder;
95 /** Builder of SubjectConfirmation objects. */
96 private SAMLObjectBuilder<SubjectConfirmation> subjectConfirmationBuilder;
98 /** Builder of ConfirmationMethod objects. */
99 private SAMLObjectBuilder<ConfirmationMethod> confirmationMethodBuilder;
101 /** Builder of Subject objects. */
102 private SAMLObjectBuilder<Subject> subjectBuilder;
104 /** Builder for Status objects. */
105 private SAMLObjectBuilder<Status> statusBuilder;
107 /** Builder for StatusCode objects. */
108 private SAMLObjectBuilder<StatusCode> statusCodeBuilder;
110 /** Builder for StatusMessage objects. */
111 private SAMLObjectBuilder<StatusMessage> statusMessageBuilder;
113 /** For building signature. */
114 private XMLObjectBuilder<Signature> signatureBuilder;
117 * Default constructor.
119 @SuppressWarnings("unchecked")
120 public AbstractSAML1ProfileHandler() {
122 responseBuilder = (SAMLObjectBuilder<Response>) getBuilderFactory().getBuilder(Response.DEFAULT_ELEMENT_NAME);
123 assertionBuilder = (SAMLObjectBuilder<Assertion>) getBuilderFactory()
124 .getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
125 conditionsBuilder = (SAMLObjectBuilder<Conditions>) getBuilderFactory().getBuilder(
126 Conditions.DEFAULT_ELEMENT_NAME);
127 audienceRestrictionConditionBuilder = (SAMLObjectBuilder<AudienceRestrictionCondition>) getBuilderFactory()
128 .getBuilder(AudienceRestrictionCondition.DEFAULT_ELEMENT_NAME);
129 audienceBuilder = (SAMLObjectBuilder<Audience>) getBuilderFactory().getBuilder(Audience.DEFAULT_ELEMENT_NAME);
130 subjectConfirmationBuilder = (SAMLObjectBuilder<SubjectConfirmation>) getBuilderFactory().getBuilder(
131 SubjectConfirmation.DEFAULT_ELEMENT_NAME);
132 confirmationMethodBuilder = (SAMLObjectBuilder<ConfirmationMethod>) getBuilderFactory().getBuilder(
133 ConfirmationMethod.DEFAULT_ELEMENT_NAME);
134 subjectBuilder = (SAMLObjectBuilder<Subject>) getBuilderFactory().getBuilder(Subject.DEFAULT_ELEMENT_NAME);
135 statusBuilder = (SAMLObjectBuilder<Status>) getBuilderFactory().getBuilder(Status.DEFAULT_ELEMENT_NAME);
136 statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) getBuilderFactory().getBuilder(
137 StatusCode.DEFAULT_ELEMENT_NAME);
138 statusMessageBuilder = (SAMLObjectBuilder<StatusMessage>) getBuilderFactory().getBuilder(
139 StatusMessage.DEFAULT_ELEMENT_NAME);
140 signatureBuilder = (XMLObjectBuilder<Signature>) getBuilderFactory().getBuilder(Signature.DEFAULT_ELEMENT_NAME);
144 * Checks that the SAML major version for a request is 1.
146 * @param requestContext current request context containing the SAML message
148 * @throws ProfileException thrown if the major version of the SAML request is not 1
150 protected void checkSamlVersion(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext) throws ProfileException {
151 SAMLObject samlObject = requestContext.getInboundSAMLMessage();
153 if (samlObject instanceof RequestAbstractType) {
154 RequestAbstractType request = (RequestAbstractType) samlObject;
155 if (request.getMajorVersion() < 1) {
156 requestContext.setFailureStatus(buildStatus(StatusCode.REQUESTER, StatusCode.REQUEST_VERSION_TOO_LOW,
158 throw new ProfileException("SAML request major version too low");
159 } else if (request.getMajorVersion() > 1) {
160 requestContext.setFailureStatus(buildStatus(StatusCode.REQUESTER, StatusCode.REQUEST_VERSION_TOO_HIGH,
162 throw new ProfileException("SAML request major version too low");
168 * Builds a response to the attribute query within the request context.
170 * @param requestContext current request context
171 * @param statements the statements to include in the response
173 * @return the built response
175 * @throws ProfileException thrown if there is a problem creating the SAML response
177 protected Response buildResponse(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext, List<Statement> statements)
178 throws ProfileException {
180 DateTime issueInstant = new DateTime();
182 // create the assertion and add the attribute statement
183 Assertion assertion = buildAssertion(requestContext, issueInstant);
184 if (statements != null) {
185 assertion.getStatements().addAll(statements);
188 // create the SAML response and add the assertion
189 Response samlResponse = responseBuilder.buildObject();
190 samlResponse.setIssueInstant(issueInstant);
191 populateStatusResponse(requestContext, samlResponse);
193 samlResponse.getAssertions().add(assertion);
195 // sign the assertion if it should be signed
196 signAssertion(requestContext, assertion);
198 Status status = buildStatus(StatusCode.SUCCESS, null, null);
199 samlResponse.setStatus(status);
205 * Builds a basic assertion with its id, issue instant, SAML version, issuer, subject, and conditions populated.
207 * @param requestContext current request context
208 * @param issueInstant time to use as assertion issue instant
210 * @return the built assertion
212 protected Assertion buildAssertion(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext, DateTime issueInstant) {
213 Assertion assertion = assertionBuilder.buildObject();
214 assertion.setID(getIdGenerator().generateIdentifier());
215 assertion.setIssueInstant(issueInstant);
216 assertion.setVersion(SAMLVersion.VERSION_11);
217 assertion.setIssuer(requestContext.getLocalEntityId());
219 Conditions conditions = buildConditions(requestContext, issueInstant);
220 assertion.setConditions(conditions);
226 * Builds a SAML assertion condition set. The following fields are set; not before, not on or after, audience
227 * restrictions, and proxy restrictions.
229 * @param requestContext current request context
230 * @param issueInstant timestamp the assertion was created
232 * @return constructed conditions
234 protected Conditions buildConditions(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext, DateTime issueInstant) {
235 AbstractSAML1ProfileConfiguration profileConfig = requestContext.getProfileConfiguration();
237 Conditions conditions = conditionsBuilder.buildObject();
238 conditions.setNotBefore(issueInstant);
239 conditions.setNotOnOrAfter(issueInstant.plus(profileConfig.getAssertionLifetime()));
241 Collection<String> audiences;
243 // add audience restrictions
244 audiences = profileConfig.getAssertionAudiences();
245 if (audiences != null && audiences.size() > 0) {
246 AudienceRestrictionCondition audienceRestriction = audienceRestrictionConditionBuilder.buildObject();
247 for (String audienceUri : audiences) {
248 Audience audience = audienceBuilder.buildObject();
249 audience.setUri(audienceUri);
250 audienceRestriction.getAudiences().add(audience);
252 conditions.getAudienceRestrictionConditions().add(audienceRestriction);
259 * Builds the SAML subject for the user for the service provider.
261 * @param requestContext current request context
262 * @param confirmationMethod subject confirmation method used for the subject
264 * @return SAML subject for the user for the service provider
266 * @throws ProfileException thrown if a NameID can not be created either because there was a problem encoding the
267 * name ID attribute or because there are no supported name formats
269 protected Subject buildSubject(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext, String confirmationMethod)
270 throws ProfileException {
271 NameIdentifier nameID = buildNameId(requestContext);
272 requestContext.setSubjectNameIdentifier(nameID);
274 ConfirmationMethod method = confirmationMethodBuilder.buildObject();
275 method.setConfirmationMethod(confirmationMethod);
277 SubjectConfirmation subjectConfirmation = subjectConfirmationBuilder.buildObject();
278 subjectConfirmation.getConfirmationMethods().add(method);
280 Subject subject = subjectBuilder.buildObject();
281 subject.setNameIdentifier(nameID);
282 subject.setSubjectConfirmation(subjectConfirmation);
288 * Builds a NameIdentifier appropriate for this request. NameIdentifier are built by inspecting the SAML request and
289 * metadata, picking a name format that was requested by the relying party or is mutually supported by both the
290 * relying party and asserting party as described in their metadata entries. Once a set of supported name formats is
291 * determined the principals attributes are inspected for an attribute supported an attribute encoder whose category
292 * is one of the supported name formats.
294 * @param requestContext current request context
296 * @return the NameIdentifier appropriate for this request
298 * @throws ProfileException thrown if a NameIdentifier can not be created either because there was a problem
299 * encoding the name ID attribute or because there are no supported name formats
301 protected NameIdentifier buildNameId(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext)
302 throws ProfileException {
303 if (log.isDebugEnabled()) {
304 log.debug("Building assertion NameIdentifier to relying party " + requestContext.getPeerEntityId()
305 + " for principal " + requestContext.getPrincipalName());
307 Map<String, BaseAttribute> principalAttributes = requestContext.getPrincipalAttributes();
308 List<String> supportedNameFormats = getNameFormats(requestContext);
310 if (log.isDebugEnabled()) {
311 log.debug("Supported name formats: " + supportedNameFormats);
314 if (principalAttributes == null || supportedNameFormats == null) {
315 log.error("No attributes for principal " + requestContext.getPrincipalName()
316 + " support constructions of NameIdentifier");
317 requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER, null,
318 "Unable to construct NameIdentifier"));
319 throw new ProfileException("No principal attributes support NameIdentifier construction");
323 SAML1NameIdentifierEncoder nameIdEncoder;
325 for (BaseAttribute<?> attribute : principalAttributes.values()) {
326 for (AttributeEncoder encoder : attribute.getEncoders()) {
327 if (encoder instanceof SAML1NameIdentifierEncoder) {
328 nameIdEncoder = (SAML1NameIdentifierEncoder) encoder;
329 if (supportedNameFormats.contains(nameIdEncoder.getNameFormat())) {
330 if (log.isDebugEnabled()) {
331 log.debug("Using attribute " + attribute.getId() + " suppoting name format "
332 + nameIdEncoder.getNameFormat()
333 + " to create the NameIdentifier for principal "
334 + requestContext.getPrincipalName());
336 return nameIdEncoder.encode(attribute);
341 requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER, null,
342 "Unable to construct NameIdentifier"));
343 throw new ProfileException("No principal attribute supported encoding into the a supported name ID format.");
344 } catch (AttributeEncodingException e) {
345 log.error("Unable to construct NameIdentifier", e);
346 requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER, null,
347 "Unable to construct NameIdentifier"));
348 throw new ProfileException("Unable to encode NameIdentifier attribute", e);
354 * Gets the NameIdentifier format to use when creating NameIdentifiers for the relying party.
356 * @param requestContext current request context
358 * @return list of formats that may be used with the relying party
360 * @throws ProfileException thrown if there is a problem determing the NameIdentifier format to use
362 protected List<String> getNameFormats(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext)
363 throws ProfileException {
364 ArrayList<String> nameFormats = new ArrayList<String>();
366 RoleDescriptor assertingPartyRole = requestContext.getLocalEntityRoleMetadata();
367 List<String> assertingPartySupportedFormats = getEntitySupportedFormats(assertingPartyRole);
369 if (nameFormats.isEmpty()) {
370 RoleDescriptor relyingPartyRole = requestContext.getPeerEntityRoleMetadata();
371 List<String> relyingPartySupportedFormats = getEntitySupportedFormats(relyingPartyRole);
373 assertingPartySupportedFormats.retainAll(relyingPartySupportedFormats);
374 nameFormats.addAll(assertingPartySupportedFormats);
376 if (nameFormats.isEmpty()) {
377 nameFormats.add("urn:oasis:names:tc:SAML:1.0:nameid-format:unspecified");
384 * Gets the list of NameIdentifier formats supported for a given role.
386 * @param role the role to get the list of supported NameIdentifier formats
388 * @return list of supported NameIdentifier formats
390 protected List<String> getEntitySupportedFormats(RoleDescriptor role) {
391 List<NameIDFormat> nameIDFormats = null;
393 if (role instanceof SSODescriptor) {
394 nameIDFormats = ((SSODescriptor) role).getNameIDFormats();
395 } else if (role instanceof AuthnAuthorityDescriptor) {
396 nameIDFormats = ((AuthnAuthorityDescriptor) role).getNameIDFormats();
397 } else if (role instanceof PDPDescriptor) {
398 nameIDFormats = ((PDPDescriptor) role).getNameIDFormats();
399 } else if (role instanceof AttributeAuthorityDescriptor) {
400 nameIDFormats = ((AttributeAuthorityDescriptor) role).getNameIDFormats();
403 ArrayList<String> supportedFormats = new ArrayList<String>();
404 if (nameIDFormats != null) {
405 for (NameIDFormat format : nameIDFormats) {
406 supportedFormats.add(format.getFormat());
410 return supportedFormats;
414 * Constructs an SAML response message carrying a request error.
416 * @param requestContext current request context containing the failure status
418 * @return the constructed error response
420 protected Response buildErrorResponse(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext) {
421 Response samlResponse = responseBuilder.buildObject();
422 samlResponse.setIssueInstant(new DateTime());
423 populateStatusResponse(requestContext, samlResponse);
425 samlResponse.setStatus(requestContext.getFailureStatus());
431 * Populates the response's id, in response to, issue instant, version, and issuer properties.
433 * @param requestContext current request context
434 * @param response the response to populate
436 protected void populateStatusResponse(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext,
437 ResponseAbstractType response) {
438 response.setID(getIdGenerator().generateIdentifier());
440 SAMLObject samlMessage = requestContext.getInboundSAMLMessage();
441 if (samlMessage != null && samlMessage instanceof RequestAbstractType) {
442 response.setInResponseTo(((RequestAbstractType) samlMessage).getID());
444 response.setVersion(SAMLVersion.VERSION_11);
448 * Build a status message, with an optional second-level failure message.
450 * @param topLevelCode top-level status code
451 * @param secondLevelCode second-level status code
452 * @param failureMessage An optional second-level failure message
454 * @return a Status object.
456 protected Status buildStatus(QName topLevelCode, QName secondLevelCode, String failureMessage) {
457 Status status = statusBuilder.buildObject();
459 StatusCode statusCode = statusCodeBuilder.buildObject();
460 statusCode.setValue(topLevelCode);
461 status.setStatusCode(statusCode);
463 if (secondLevelCode != null) {
464 StatusCode secondLevelStatusCode = statusCodeBuilder.buildObject();
465 secondLevelStatusCode.setValue(secondLevelCode);
466 statusCode.setStatusCode(secondLevelStatusCode);
469 if (failureMessage != null) {
470 StatusMessage msg = statusMessageBuilder.buildObject();
471 msg.setMessage(failureMessage);
472 status.setStatusMessage(msg);
479 * Resolved the attributes for the principal.
481 * @param requestContext current request context
483 * @throws ProfileException thrown if attributes can not be resolved
485 protected void resolveAttributes(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext) throws ProfileException {
486 AbstractSAML1ProfileConfiguration profileConfiguration = requestContext.getProfileConfiguration();
487 SAML1AttributeAuthority attributeAuthority = profileConfiguration.getAttributeAuthority();
490 if (log.isDebugEnabled()) {
491 log.debug("Resolving attributes for principal " + requestContext.getPrincipalName()
492 + " of SAML request from relying party " + requestContext.getPeerEntityId());
494 Map<String, BaseAttribute> principalAttributes = attributeAuthority.getAttributes(requestContext);
496 requestContext.setAttributes(principalAttributes);
497 } catch (AttributeRequestException e) {
498 log.error("Error resolving attributes for SAML request from relying party "
499 + requestContext.getPeerEntityId(), e);
500 requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER, null, "Error resolving attributes"));
501 throw new ProfileException("Error resolving attributes for SAML request from relying party "
502 + requestContext.getPeerEntityId(), e);
507 * Executes a query for attributes and builds a SAML attribute statement from the results.
509 * @param requestContext current request context
510 * @param subjectConfMethod subject confirmation method
512 * @return attribute statement resulting from the query
514 * @throws ProfileException thrown if there is a problem making the query
516 protected AttributeStatement buildAttributeStatement(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext,
517 String subjectConfMethod) throws ProfileException {
519 if (log.isDebugEnabled()) {
520 log.debug("Creating attribute statement in response to SAML request from relying party "
521 + requestContext.getPeerEntityId());
524 AbstractSAML1ProfileConfiguration profileConfiguration = requestContext.getProfileConfiguration();
525 SAML1AttributeAuthority attributeAuthority = profileConfiguration.getAttributeAuthority();
528 AttributeStatement statment;
529 if (requestContext.getInboundSAMLMessage() instanceof AttributeQuery) {
530 statment = attributeAuthority.buildAttributeStatement((AttributeQuery) requestContext
531 .getInboundSAMLMessage(), requestContext.getPrincipalAttributes().values());
533 statment = attributeAuthority.buildAttributeStatement(null, requestContext.getPrincipalAttributes()
537 Subject statementSubject = buildSubject(requestContext, subjectConfMethod);
538 statment.setSubject(statementSubject);
541 } catch (AttributeRequestException e) {
542 log.error("Error encoding attributes for principal " + requestContext.getPrincipalName(), e);
543 requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER, null, "Error resolving attributes"));
544 throw new ProfileException("Error encoding attributes for principal " + requestContext.getPrincipalName(),
550 * Resolves the principal name of the subject of the request.
552 * @param requestContext current request context
554 * @throws ProfileException thrown if the principal name can not be resolved
556 protected void resolvePrincipal(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext) throws ProfileException {
557 AbstractSAML1ProfileConfiguration profileConfiguration = requestContext.getProfileConfiguration();
558 SAML1AttributeAuthority attributeAuthority = profileConfiguration.getAttributeAuthority();
560 if (log.isDebugEnabled()) {
561 log.debug("Resolving principal name for subject of SAML request from relying party "
562 + requestContext.getPeerEntityId());
566 String principal = attributeAuthority.getPrincipal(requestContext);
567 requestContext.setPrincipalName(principal);
568 } catch (AttributeRequestException e) {
569 log.error("Error resolving attributes for SAML request from relying party "
570 + requestContext.getPeerEntityId(), e);
571 requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER, StatusCode.REQUEST_DENIED,
572 "Error resolving principal"));
573 throw new ProfileException("Error resolving attributes for SAML request from relying party "
574 + requestContext.getPeerEntityId(), e);
579 * Signs the given assertion if either the current profile configuration or the relying party configuration contains
580 * signing credentials.
582 * @param requestContext current request context
583 * @param assertion assertion to sign
585 * @throws ProfileException thrown if the metadata can not be located for the relying party or, if signing is
586 * required, if a signing credential is not configured
588 protected void signAssertion(BaseSAML1ProfileRequestContext<?, ?, ?> requestContext, Assertion assertion)
589 throws ProfileException {
590 if (log.isDebugEnabled()) {
591 log.debug("Determining if SAML assertion to relying party " + requestContext.getPeerEntityId()
592 + " should be signed");
595 boolean signAssertion = false;
597 RoleDescriptor relyingPartyRole = requestContext.getPeerEntityRoleMetadata();
598 AbstractSAML1ProfileConfiguration profileConfig = requestContext.getProfileConfiguration();
600 if (relyingPartyRole instanceof SPSSODescriptor) {
601 SPSSODescriptor ssoDescriptor = (SPSSODescriptor) relyingPartyRole;
602 if (ssoDescriptor.getWantAssertionsSigned() != null) {
603 signAssertion = ssoDescriptor.getWantAssertionsSigned().booleanValue();
604 if (log.isDebugEnabled()) {
605 log.debug("Entity metadata for relying party " + requestContext.getPeerEntityId()
606 + " indicates to sign assertions: " + signAssertion);
609 } else if (profileConfig.getSignAssertions()) {
610 signAssertion = true;
611 log.debug("IdP relying party configuration "
612 + requestContext.getRelyingPartyConfiguration().getRelyingPartyId()
613 + " indicates to sign assertions: " + signAssertion);
616 if (!signAssertion) {
620 if (log.isDebugEnabled()) {
621 log.debug("Determining signing credntial for assertion to relying party "
622 + requestContext.getPeerEntityId());
624 Credential signatureCredential = profileConfig.getSigningCredential();
625 if (signatureCredential == null) {
626 signatureCredential = requestContext.getRelyingPartyConfiguration().getDefaultSigningCredential();
629 if (signatureCredential == null) {
630 throw new ProfileException("No signing credential is specified for relying party configuration "
631 + requestContext.getRelyingPartyConfiguration().getProviderId()
632 + " or it's SAML2 attribute query profile configuration");
635 if (log.isDebugEnabled()) {
636 log.debug("Signing assertion to relying party " + requestContext.getPeerEntityId());
638 SAMLObjectContentReference contentRef = new SAMLObjectContentReference(assertion);
639 Signature signature = signatureBuilder.buildObject(Signature.DEFAULT_ELEMENT_NAME);
640 signature.getContentReferences().add(contentRef);
641 assertion.setSignature(signature);
643 Signer.signObject(signature);