2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * BrowserSSOProfileValidator.cpp
24 * SAML 1.x Browser SSO Profile Assertion Validator.
28 #include "saml1/core/Assertions.h"
29 #include "saml1/profile/BrowserSSOProfileValidator.h"
31 #include <xmltooling/logging.h>
32 #include <xmltooling/util/NDC.h>
34 using namespace opensaml::saml1;
35 using namespace xmltooling::logging;
36 using namespace xmltooling;
40 class SAML_DLLLOCAL _checkMethod : public unary_function<const SubjectStatement*,void>,
41 public unary_function<const ConfirmationMethod*,bool>
44 void operator()(const SubjectStatement* s) const {
45 const Subject* sub = s->getSubject();
47 const SubjectConfirmation* sc = sub->getSubjectConfirmation();
49 const vector<ConfirmationMethod*>& methods = sc->getConfirmationMethods();
50 if (find_if(methods.begin(), methods.end(), _checkMethod())!=methods.end())
51 return; // methods checked out
54 throw ValidationException("Assertion contained a statement without a supported ConfirmationMethod.");
57 bool operator()(const ConfirmationMethod* cm) const {
58 const XMLCh* m = cm->getMethod();
59 return (XMLString::equals(m,SubjectConfirmation::BEARER) ||
60 XMLString::equals(m,SubjectConfirmation::ARTIFACT) ||
61 XMLString::equals(m,SubjectConfirmation::ARTIFACT01));
66 BrowserSSOProfileValidator::BrowserSSOProfileValidator(const XMLCh* recipient, const std::vector<const XMLCh*>* audiences, time_t ts)
67 : AssertionValidator(recipient, audiences, ts)
71 BrowserSSOProfileValidator::~BrowserSSOProfileValidator()
75 void BrowserSSOProfileValidator::validateAssertion(const Assertion& assertion) const
78 xmltooling::NDC ndc("validate");
81 // Make sure the assertion is bounded.
82 const Conditions* conds = assertion.getConditions();
83 if (!conds || !conds->getNotBefore() || !conds->getNotOnOrAfter())
84 throw ValidationException("SSO assertions MUST contain NotBefore/NotOnOrAfter attributes.");
86 // Each statement MUST have proper confirmation requirements.
87 const vector<AuthenticationStatement*>& authn = assertion.getAuthenticationStatements();
88 for_each(authn.begin(), authn.end(), _checkMethod());
89 const vector<AttributeStatement*>& attr = assertion.getAttributeStatements();
90 for_each(attr.begin(), attr.end(), _checkMethod());
92 // Pass up for additional checking.
93 AssertionValidator::validateAssertion(assertion);