/*\r
- * Copyright 2001-2005 Internet2\r
+ * Copyright 2001-2007 Internet2\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
using namespace opensaml::saml1p;\r
using namespace opensaml::saml1;\r
\r
-namespace {\r
- class SAML_DLLLOCAL _addcert : public binary_function<X509Data*,XSECCryptoX509*,void> {\r
- public:\r
- void operator()(X509Data* bag, XSECCryptoX509* cert) const {\r
- safeBuffer& buf=cert->getDEREncodingSB();\r
- X509Certificate* x=X509CertificateBuilder::buildX509Certificate();\r
- x->setValue(buf.sbStrToXMLCh());\r
- bag->getX509Certificates().push_back(x);\r
- }\r
- };\r
-};\r
-\r
class SAML1ArtifactTest : public CxxTest::TestSuite,\r
public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {\r
public:\r
void testSAML1Artifact() {\r
try {\r
QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);\r
- SecurityPolicy policy(m_rules1, m_metadata, &idprole, m_trust);\r
+ SecurityPolicy policy(m_rules1, m_metadata, &idprole, m_trust, false);\r
\r
// Read message to use from file.\r
string path = data_path + "saml1/binding/SAML1Assertion.xml";\r
ifstream in(path.c_str());\r
DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
XercesJanitor<DOMDocument> janitor(doc);\r
- auto_ptr<Assertion> toSend(\r
- dynamic_cast<Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
+ auto_ptr<saml1::Assertion> toSend(\r
+ dynamic_cast<saml1::Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
);\r
janitor.release();\r
\r
+ CredentialCriteria cc;\r
+ cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL);\r
+ Locker clocker(m_creds);\r
+ const Credential* cred = m_creds->resolve(&cc);\r
+ TSM_ASSERT("Retrieved credential was null", cred!=NULL);\r
+\r
// Encode message.\r
auto_ptr<MessageEncoder> encoder(\r
SAMLConfig::getConfig().MessageEncoderManager.newPlugin(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)\r
);\r
encoder->setArtifactGenerator(this);\r
- encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/SSO","https://sp.example.org/","state",m_creds);\r
+ encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/SSO","https://sp.example.org/","state",cred);\r
toSend.release();\r
\r
// Decode message.\r
// Test the results.\r
TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");\r
TSM_ASSERT("SAML Response not decoded successfully.", response.get());\r
- TSM_ASSERT("Message was not verified.", policy.getIssuer()!=NULL);\r
+ TSM_ASSERT("Message was not verified.", policy.isSecure());\r
auto_ptr_char entityID(policy.getIssuer()->getName());\r
TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));\r
TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);\r
throw BindingException("Not implemented.");\r
}\r
\r
- Signature* buildSignature(const CredentialResolver* credResolver) const\r
- {\r
- // Build a Signature.\r
- Signature* sig = SignatureBuilder::buildSignature();\r
- sig->setSigningKey(credResolver->getKey());\r
-\r
- // Build KeyInfo.\r
- const vector<XSECCryptoX509*>& certs = credResolver->getCertificates();\r
- if (!certs.empty()) {\r
- KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo();\r
- X509Data* x509Data=X509DataBuilder::buildX509Data();\r
- keyInfo->getX509Datas().push_back(x509Data);\r
- for_each(certs.begin(),certs.end(),bind1st(_addcert(),x509Data));\r
- sig->setKeyInfo(keyInfo);\r
- }\r
- \r
- return sig;\r
- }\r
-\r
Response* resolve(\r
const vector<SAMLArtifact*>& artifacts,\r
const IDPSSODescriptor& idpDescriptor,\r
TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);\r
XMLObject* xmlObject =\r
SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");\r
- Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);\r
+ saml1::Assertion* assertion = dynamic_cast<saml1::Assertion*>(xmlObject);\r
TSM_ASSERT("Not an assertion.", assertion!=NULL);\r
auto_ptr<Response> response(ResponseBuilder::buildResponse());\r
response->getAssertions().push_back(assertion);\r
StatusCode* sc = StatusCodeBuilder::buildStatusCode();\r
status->setStatusCode(sc);\r
sc->setValue(&StatusCode::SUCCESS);\r
- response->setSignature(buildSignature(m_creds));\r
+ response->setSignature(SignatureBuilder::buildSignature());\r
vector<Signature*> sigs(1,response->getSignature());\r
- response->marshall((DOMDocument*)NULL,&sigs);\r
+ CredentialCriteria cc;\r
+ cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL);\r
+ Locker clocker(m_creds);\r
+ const Credential* cred = m_creds->resolve(&cc);\r
+ TSM_ASSERT("Retrieved credential was null", cred!=NULL);\r
+ response->marshall((DOMDocument*)NULL,&sigs,cred);\r
SchemaValidators.validate(response.get());\r
+ policy.evaluate(*(response.get()), this);\r
return response.release();\r
}\r
\r