2 * Copyright 2001-2007 Internet2
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.
18 * BrowserSSOProfile20Validator.cpp
20 * SAML 2.0 Browser SSO Profile Assertion Validator
24 #include "saml2/core/Assertions.h"
25 #include "binding/HTTPRequest.h"
26 #include "saml2/profile/BrowserSSOProfileValidator.h"
28 #include <log4cpp/Category.hh>
29 #include <xmltooling/util/NDC.h>
31 using namespace opensaml::saml2;
32 using namespace xmltooling;
33 using namespace log4cpp;
36 void BrowserSSOProfileValidator::validateAssertion(const Assertion& assertion) const
39 xmltooling::NDC ndc("validate");
41 Category& log = Category::getInstance(SAML_LOGCAT".AssertionValidator");
43 // The assertion MUST have proper confirmation requirements.
44 const Subject* subject = assertion.getSubject();
46 const vector<SubjectConfirmation*>& confs = subject->getSubjectConfirmations();
47 for (vector<SubjectConfirmation*>::const_iterator sc = confs.begin(); sc!=confs.end(); ++sc) {
48 if (XMLString::equals((*sc)->getMethod(), SubjectConfirmation::BEARER)) {
49 const SubjectConfirmationDataType* data = dynamic_cast<const SubjectConfirmationDataType*>((*sc)->getSubjectConfirmationData());
51 if (m_destination.get()) {
52 if (!XMLString::equals(m_destination.get(), data ? data->getRecipient() : NULL)) {
53 log.error("bearer confirmation failed with recipient mismatch");
58 if (m_requestID.get()) {
59 if (!XMLString::equals(m_requestID.get(), data ? data->getInResponseTo() : NULL)) {
60 log.error("bearer confirmation failed with request correlation mismatch");
66 if (!data || !data->getNotOnOrAfter()) {
67 log.error("bearer confirmation missing NotOnOrAfter attribute");
70 else if (data->getNotOnOrAfterEpoch() <= m_ts - XMLToolingConfig::getConfig().clock_skew_secs) {
71 log.error("bearer confirmation has expired");
76 // Save off client address.
78 auto_ptr_char ip(data->getAddress());
83 // Pass up for additional checking.
84 return AssertionValidator::validateAssertion(assertion);
89 throw ValidationException("Unable to satisfy assertion's SubjectConfirmation.");