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.
21 #include "signature/SAMLSignatureTestBase.h"
22 #include <saml/saml1/core/Assertions.h>
26 using namespace opensaml::saml1;
28 class SAML1AssertionTest : public CxxTest::TestSuite, public SAMLSignatureTestBase {
31 childElementsFile = data_path + "signature/SAML1Assertion.xml";
32 SAMLSignatureTestBase::setUp();
36 SAMLSignatureTestBase::tearDown();
39 void testSignature() {
40 auto_ptr_XMLCh issuer("issuer");
41 auto_ptr_XMLCh issueInstant("1970-01-02T01:01:02.100Z");
42 auto_ptr_XMLCh id("ident");
43 auto_ptr_XMLCh method("method");
44 auto_ptr_XMLCh nameid("John Doe");
46 NameIdentifier* n=NameIdentifierBuilder::buildNameIdentifier();
47 n->setName(nameid.get());
48 Subject* subject=SubjectBuilder::buildSubject();
49 subject->setNameIdentifier(n);
51 AuthenticationStatement* statement=AuthenticationStatementBuilder::buildAuthenticationStatement();
52 statement->setAuthenticationInstant(issueInstant.get());
53 statement->setAuthenticationMethod(method.get());
54 statement->setSubject(subject);
56 auto_ptr<Assertion> assertion(AssertionBuilder::buildAssertion());
57 assertion->setAssertionID(id.get());
58 assertion->setIssueInstant(issueInstant.get());
59 assertion->setIssuer(issuer.get());
60 assertion->getAuthenticationStatements().push_back(statement);
62 // Append a Signature.
63 Signature* sig=SignatureBuilder::buildSignature();
64 assertion->setSignature(sig);
66 // Sign while marshalling.
67 vector<Signature*> sigs(1,sig);
68 CredentialCriteria cc;
69 cc.setUsage(Credential::SIGNING_CREDENTIAL);
70 Locker locker(m_resolver);
71 const Credential* cred = m_resolver->resolve(&cc);
72 TSM_ASSERT("Retrieved credential was null", cred!=nullptr);
74 DOMElement* rootElement = nullptr;
76 rootElement=assertion->marshall((DOMDocument*)nullptr,&sigs,cred);
78 catch (XMLToolingException& e) {
84 XMLHelper::serialize(rootElement, buf);
85 istringstream in(buf);
86 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
87 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
89 auto_ptr<XMLObject> assertion2(b->buildFromDocument(doc));
90 assertEquals("Unmarshalled assertion does not match", expectedChildElementsDOM, assertion2.get(), false);
93 opensaml::SignatureProfileValidator spv;
94 SignatureValidator sv(cred);
95 spv.validate(dynamic_cast<Assertion*>(assertion2.get())->getSignature());
96 sv.validate(dynamic_cast<Assertion*>(assertion2.get())->getSignature());
98 catch (XMLToolingException& e) {