Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-opensaml.git] / saml / saml2 / core / impl / Protocols20Impl.cpp
index fa407d8..800400b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
 #include "saml2/core/Protocols.h"
 
 #include <xmltooling/AbstractComplexElement.h>
-#include <xmltooling/AbstractElementProxy.h>
 #include <xmltooling/AbstractSimpleElement.h>
 #include <xmltooling/encryption/Decrypter.h>
 #include <xmltooling/impl/AnyElement.h>
@@ -39,7 +38,6 @@
 
 using namespace opensaml::saml2p;
 using namespace opensaml::saml2;
-using namespace opensaml;
 using namespace xmlsignature;
 using namespace xmlencryption;
 using namespace xmltooling;
@@ -69,7 +67,7 @@ namespace opensaml {
 
         //TODO need unit test for this, using objects from another namespace
         class SAML_DLLLOCAL ExtensionsImpl : public virtual Extensions,
-             public AbstractElementProxy,
+             public AbstractComplexElement,
              public AbstractDOMCachingXMLObject,
              public AbstractXMLObjectMarshaller,
              public AbstractXMLObjectUnmarshaller
@@ -82,22 +80,21 @@ namespace opensaml {
             }
                 
             ExtensionsImpl(const ExtensionsImpl& src)
-                    : AbstractXMLObject(src), AbstractElementProxy(src), AbstractDOMCachingXMLObject(src) {
-                for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
-                    if (*i) {
-                        getXMLObjects().push_back((*i)->clone());
-                    }
-                }
+                    : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
+                VectorOf(XMLObject) v=getUnknownXMLObjects();
+                for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i)
+                    v.push_back((*i)->clone());
             }
             
             IMPL_XMLOBJECT_CLONE(Extensions);
+            IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject,m_children.end());
     
         protected:
             void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
                 // Unknown child.
                 const XMLCh* nsURI=root->getNamespaceURI();
                 if (!XMLString::equals(nsURI,SAML20P_NS) && nsURI && *nsURI) {
-                    getXMLObjects().push_back(childXMLObject);
+                    getUnknownXMLObjects().push_back(childXMLObject);
                     return;
                 }
                 
@@ -169,21 +166,17 @@ namespace opensaml {
 
                 StatusDetailImpl(const StatusDetailImpl& src)
                         : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
-                    VectorOf(XMLObject) v=getDetails();
-                    for (vector<XMLObject*>::const_iterator i=src.m_Details.begin(); i!=src.m_Details.end(); i++) {
-                        if (*i) {
-                            v.push_back((*i)->clone());
-                        }
-                    }
+                    VectorOf(XMLObject) v=getUnknownXMLObjects();
+                    for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i)
+                        v.push_back((*i)->clone());
                 }
 
                 IMPL_XMLOBJECT_CLONE(StatusDetail);
-                IMPL_XMLOBJECT_CHILDREN(Detail,m_children.end());
+                IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject,m_children.end());
 
             protected:
                 void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-                    getDetails().push_back(childXMLObject);
-                    AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
+                    getUnknownXMLObjects().push_back(childXMLObject);
                 }
         };
 
@@ -1137,7 +1130,7 @@ namespace opensaml {
             ResponseImpl(const ResponseImpl& src) : AbstractXMLObject(src), StatusResponseTypeImpl(src) {
                 for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
                     if (*i) {
-                        Assertion* assertion=dynamic_cast<Assertion*>(*i);
+                        saml2::Assertion* assertion=dynamic_cast<saml2::Assertion*>(*i);
                         if (assertion) {
                             getAssertions().push_back(assertion->cloneAssertion());
                             continue;
@@ -1295,12 +1288,13 @@ namespace opensaml {
                 }
             }
     
-            XMLObject* decrypt(KeyResolver* KEKresolver, const XMLCh* recipient) const
+            XMLObject* decrypt(const CredentialResolver& credResolver, const XMLCh* recipient, CredentialCriteria* criteria) const
             {
                 if (!m_EncryptedData)
                     throw DecryptionException("No encrypted data present.");
-                Decrypter decrypter(KEKresolver, new EncryptedKeyResolver(*this, recipient));
-                DOMDocumentFragment* frag = decrypter.decryptData(m_EncryptedData);
+                EncryptedKeyResolver ekr(*this);
+                Decrypter decrypter(&credResolver, criteria, &ekr);
+                DOMDocumentFragment* frag = decrypter.decryptData(*m_EncryptedData, recipient);
                 if (frag->hasChildNodes() && frag->getFirstChild()==frag->getLastChild()) {
                     DOMNode* plaintext=frag->getFirstChild();
                     if (plaintext->getNodeType()==DOMNode::ELEMENT_NODE) {