Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / saml / saml1 / profile / impl / BrowserSSOProfileValidator.cpp
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * BrowserSSOProfileValidator.cpp
23  *
24  * SAML 1.x Browser SSO Profile Assertion Validator.
25  */
26
27 #include "internal.h"
28 #include "saml1/core/Assertions.h"
29 #include "saml1/profile/BrowserSSOProfileValidator.h"
30
31 #include <xmltooling/logging.h>
32 #include <xmltooling/util/NDC.h>
33
34 using namespace opensaml::saml1;
35 using namespace xmltooling::logging;
36 using namespace xmltooling;
37 using namespace std;
38
39 namespace {
40     class SAML_DLLLOCAL _checkMethod : public unary_function<const SubjectStatement*,void>,
41         public unary_function<const ConfirmationMethod*,bool>
42     {
43     public:
44         void operator()(const SubjectStatement* s) const {
45             const Subject* sub = s->getSubject();
46             if (s) {
47                 const SubjectConfirmation* sc = sub->getSubjectConfirmation();
48                 if (sc) {
49                     const vector<ConfirmationMethod*>& methods = sc->getConfirmationMethods();
50                     if (find_if(methods.begin(), methods.end(), _checkMethod())!=methods.end())
51                         return;     // methods checked out
52                 }
53             }
54             throw ValidationException("Assertion contained a statement without a supported ConfirmationMethod.");
55         }
56
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));
62         }
63     };
64 };
65
66 BrowserSSOProfileValidator::BrowserSSOProfileValidator(const XMLCh* recipient, const std::vector<const XMLCh*>* audiences, time_t ts)
67     : AssertionValidator(recipient, audiences, ts)
68 {
69 }
70
71 BrowserSSOProfileValidator::~BrowserSSOProfileValidator()
72 {
73 }
74
75 void BrowserSSOProfileValidator::validateAssertion(const Assertion& assertion) const
76 {
77 #ifdef _DEBUG
78     xmltooling::NDC ndc("validate");
79 #endif
80
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.");
85
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());
91
92     // Pass up for additional checking.
93     AssertionValidator::validateAssertion(assertion);
94 }