Back out nil property.
[shibboleth/cpp-opensaml.git] / saml / saml2 / core / impl / Assertions20Impl.cpp
index 7535d78..22874c1 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.
@@ -27,7 +27,6 @@
 
 #include <xmltooling/AbstractComplexElement.h>
 #include <xmltooling/AbstractSimpleElement.h>
-#include <xmltooling/encryption/Decrypter.h>
 #include <xmltooling/impl/AnyElement.h>
 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>
 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace opensaml::saml2;
-using namespace opensaml;
 using namespace xmlencryption;
 using namespace xmlsignature;
 using namespace xmltooling;
 using namespace std;
+using xmlconstants::XSI_NS;
 using xmlconstants::XMLSIG_NS;
 using xmlconstants::XMLENC_NS;
+using xmlconstants::XML_BOOL_NULL;
 using samlconstants::SAML20_NS;
 
+
 #if defined (_MSC_VER)
     #pragma warning( push )
     #pragma warning( disable : 4250 4251 )
@@ -53,7 +54,7 @@ using samlconstants::SAML20_NS;
 
 namespace opensaml {
     namespace saml2 {
-    
+
         DECL_XMLOBJECTIMPL_SIMPLE(SAML_DLLLOCAL,AssertionIDRef);
         DECL_XMLOBJECTIMPL_SIMPLE(SAML_DLLLOCAL,AssertionURIRef);
         DECL_XMLOBJECTIMPL_SIMPLE(SAML_DLLLOCAL,Audience);
@@ -192,24 +193,6 @@ namespace opensaml {
                     }
                 }
             }
-    
-            XMLObject* decrypt(KeyResolver* KEKresolver, const XMLCh* recipient) const
-            {
-                if (!m_EncryptedData)
-                    throw DecryptionException("No encrypted data present.");
-                Decrypter decrypter(KEKresolver, new EncryptedKeyResolver(*this, recipient));
-                DOMDocumentFragment* frag = decrypter.decryptData(m_EncryptedData);
-                if (frag->hasChildNodes() && frag->getFirstChild()==frag->getLastChild()) {
-                    DOMNode* plaintext=frag->getFirstChild();
-                    if (plaintext->getNodeType()==DOMNode::ELEMENT_NODE) {
-                        auto_ptr<XMLObject> ret(XMLObjectBuilder::buildOneFromElement(static_cast<DOMElement*>(plaintext)));
-                        ret->releaseThisAndChildrenDOM();
-                        return ret.release();
-                    }
-                }
-                frag->release();
-                throw DecryptionException("Decryption did not result in a single element.");
-            }
         
             IMPL_XMLOBJECT_CLONE(EncryptedElementType);
             IMPL_TYPED_FOREIGN_CHILD(EncryptedData,xmlencryption);
@@ -223,7 +206,6 @@ namespace opensaml {
             }
         };
 
-        //TODO unit test for this 
         class SAML_DLLLOCAL EncryptedIDImpl : public virtual EncryptedID, public EncryptedElementTypeImpl
         {
         public:
@@ -434,14 +416,20 @@ namespace opensaml {
             }
         };
 
-        class SAML_DLLLOCAL SubjectConfirmationDataImpl : public virtual SubjectConfirmationData, public AnyElementImpl
+        class SAML_DLLLOCAL SubjectConfirmationDataTypeImpl : public virtual SubjectConfirmationDataType, public virtual AbstractXMLObject
         {
             void init() {
                 m_NotBefore=m_NotOnOrAfter=NULL;
                 m_Recipient=m_InResponseTo=m_Address=NULL;
             }
+
+        protected:
+            SubjectConfirmationDataTypeImpl() {
+                init();
+            }
+
         public:
-            virtual ~SubjectConfirmationDataImpl() {
+            virtual ~SubjectConfirmationDataTypeImpl() {
                 delete m_NotBefore;
                 delete m_NotOnOrAfter;
                 XMLString::release(&m_Recipient);
@@ -449,12 +437,12 @@ namespace opensaml {
                 XMLString::release(&m_Address);
             }
     
-            SubjectConfirmationDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
+            SubjectConfirmationDataTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
                     : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
                 init();
             }
                 
-            SubjectConfirmationDataImpl(const SubjectConfirmationDataImpl& src) : AnyElementImpl(src) {
+            SubjectConfirmationDataTypeImpl(const SubjectConfirmationDataTypeImpl& src) : AbstractXMLObject(src) {
                 init();
                 setNotBefore(src.getNotBefore());
                 setNotOnOrAfter(src.getNotOnOrAfter());
@@ -463,14 +451,49 @@ namespace opensaml {
                 setAddress(src.getAddress());
             }
             
-            IMPL_XMLOBJECT_CLONE(SubjectConfirmationData);
             IMPL_DATETIME_ATTRIB(NotBefore,0);
             IMPL_DATETIME_ATTRIB(NotOnOrAfter,SAMLTIME_MAX);
             IMPL_STRING_ATTRIB(Recipient);
             IMPL_STRING_ATTRIB(InResponseTo);
             IMPL_STRING_ATTRIB(Address);
             
+        protected:
+            void marshallAttributes(DOMElement* domElement) const {
+                MARSHALL_DATETIME_ATTRIB(NotBefore,NOTBEFORE,NULL);
+                MARSHALL_DATETIME_ATTRIB(NotOnOrAfter,NOTONORAFTER,NULL);
+                MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
+                MARSHALL_STRING_ATTRIB(InResponseTo,INRESPONSETO,NULL);
+                MARSHALL_STRING_ATTRIB(Address,ADDRESS,NULL);
+            }
+            
+            void processAttribute(const DOMAttr* attribute) {
+                PROC_DATETIME_ATTRIB(NotBefore,NOTBEFORE,NULL);
+                PROC_DATETIME_ATTRIB(NotOnOrAfter,NOTONORAFTER,NULL);
+                PROC_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
+                PROC_STRING_ATTRIB(InResponseTo,INRESPONSETO,NULL);
+                PROC_STRING_ATTRIB(Address,ADDRESS,NULL);
+            }
+        };
+
+        class SAML_DLLLOCAL SubjectConfirmationDataImpl : public SubjectConfirmationData,
+            public SubjectConfirmationDataTypeImpl, public AnyElementImpl
+        {
         public:
+            virtual ~SubjectConfirmationDataImpl() {}
+    
+            SubjectConfirmationDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
+                    : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+            }
+                
+            SubjectConfirmationDataImpl(const SubjectConfirmationDataImpl& src)
+                    : SubjectConfirmationDataTypeImpl(src), AnyElementImpl(src) {
+            }
+
+            IMPL_XMLOBJECT_CLONE(SubjectConfirmationData);
+            SubjectConfirmationDataType* cloneSubjectConfirmationDataType() const {
+                return new SubjectConfirmationDataImpl(*this);
+            }
+
             void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false) {
                 if (!qualifiedName.hasNamespaceURI()) {
                     if (XMLString::equals(qualifiedName.getLocalPart(),NOTBEFORE_ATTRIB_NAME)) {
@@ -499,62 +522,48 @@ namespace opensaml {
 
         protected:
             void marshallAttributes(DOMElement* domElement) const {
-                MARSHALL_DATETIME_ATTRIB(NotBefore,NOTBEFORE,NULL);
-                MARSHALL_DATETIME_ATTRIB(NotOnOrAfter,NOTONORAFTER,NULL);
-                MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
-                MARSHALL_STRING_ATTRIB(InResponseTo,INRESPONSETO,NULL);
-                MARSHALL_STRING_ATTRIB(Address,ADDRESS,NULL);
+                SubjectConfirmationDataTypeImpl::marshallAttributes(domElement);
                 AnyElementImpl::marshallAttributes(domElement);
             }
-            
-            // The processAttributes hook is handled by AnyElementImpl
+
+            void processAttribute(const DOMAttr* attribute) {
+                PROC_DATETIME_ATTRIB(NotBefore,NOTBEFORE,NULL);
+                PROC_DATETIME_ATTRIB(NotOnOrAfter,NOTONORAFTER,NULL);
+                PROC_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
+                PROC_STRING_ATTRIB(InResponseTo,INRESPONSETO,NULL);
+                PROC_STRING_ATTRIB(Address,ADDRESS,NULL);
+                AnyElementImpl::processAttribute(attribute);
+            }
         };
 
         class SAML_DLLLOCAL KeyInfoConfirmationDataTypeImpl : public virtual KeyInfoConfirmationDataType,
+                public SubjectConfirmationDataTypeImpl,
                 public AbstractComplexElement,
                 public AbstractAttributeExtensibleXMLObject,
                 public AbstractDOMCachingXMLObject,
                 public AbstractXMLObjectMarshaller,
                 public AbstractXMLObjectUnmarshaller
         {
-            void init() {
-                m_NotBefore=m_NotOnOrAfter=NULL;
-                m_Recipient=m_InResponseTo=m_Address=NULL;
-            }
         public:
-            virtual ~KeyInfoConfirmationDataTypeImpl() {
-                delete m_NotBefore;
-                delete m_NotOnOrAfter;
-                XMLString::release(&m_Recipient);
-                XMLString::release(&m_InResponseTo);
-                XMLString::release(&m_Address);
-            }
+            virtual ~KeyInfoConfirmationDataTypeImpl() {}
     
             KeyInfoConfirmationDataTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
                     : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
-                init();
             }
                 
             KeyInfoConfirmationDataTypeImpl(const KeyInfoConfirmationDataTypeImpl& src)
-                    : AbstractXMLObject(src), AbstractComplexElement(src),
+                    : AbstractXMLObject(src), SubjectConfirmationDataTypeImpl(src), AbstractComplexElement(src),
                         AbstractAttributeExtensibleXMLObject(src), AbstractDOMCachingXMLObject(src) {
-                init();
-                setNotBefore(src.getNotBefore());
-                setNotOnOrAfter(src.getNotOnOrAfter());
-                setRecipient(src.getRecipient());
-                setInResponseTo(src.getInResponseTo());
-                setAddress(src.getAddress());
                 VectorOf(KeyInfo) v=getKeyInfos();
                 for (vector<KeyInfo*>::const_iterator i=src.m_KeyInfos.begin(); i!=src.m_KeyInfos.end(); ++i)
                     v.push_back((*i)->cloneKeyInfo());
             }
             
             IMPL_XMLOBJECT_CLONE(KeyInfoConfirmationDataType);
-            IMPL_DATETIME_ATTRIB(NotBefore,0);
-            IMPL_DATETIME_ATTRIB(NotOnOrAfter,SAMLTIME_MAX);
-            IMPL_STRING_ATTRIB(Recipient);
-            IMPL_STRING_ATTRIB(InResponseTo);
-            IMPL_STRING_ATTRIB(Address);
+            SubjectConfirmationDataType* cloneSubjectConfirmationDataType() const {
+                return new KeyInfoConfirmationDataTypeImpl(*this);
+            }
+
             IMPL_TYPED_CHILDREN(KeyInfo,m_children.end());
             
         public:
@@ -586,11 +595,7 @@ namespace opensaml {
 
         protected:
             void marshallAttributes(DOMElement* domElement) const {
-                MARSHALL_DATETIME_ATTRIB(NotBefore,NOTBEFORE,NULL);
-                MARSHALL_DATETIME_ATTRIB(NotOnOrAfter,NOTONORAFTER,NULL);
-                MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
-                MARSHALL_STRING_ATTRIB(InResponseTo,INRESPONSETO,NULL);
-                MARSHALL_STRING_ATTRIB(Address,ADDRESS,NULL);
+                SubjectConfirmationDataTypeImpl::marshallAttributes(domElement);
                 marshallExtensionAttributes(domElement);
             }
     
@@ -616,7 +621,6 @@ namespace opensaml {
                 m_NameID=NULL;
                 m_EncryptedID=NULL;
                 m_SubjectConfirmationData=NULL;
-                m_KeyInfoConfirmationDataType=NULL;
                 m_children.push_back(NULL);
                 m_children.push_back(NULL);
                 m_children.push_back(NULL);
@@ -628,8 +632,6 @@ namespace opensaml {
                 ++m_pos_EncryptedID;
                 m_pos_SubjectConfirmationData=m_pos_EncryptedID;
                 ++m_pos_SubjectConfirmationData;
-                m_pos_KeyInfoConfirmationDataType=m_pos_SubjectConfirmationData;
-                ++m_pos_KeyInfoConfirmationDataType;
             }
         public:
             virtual ~SubjectConfirmationImpl() {}
@@ -651,8 +653,6 @@ namespace opensaml {
                     setEncryptedID(src.getEncryptedID()->cloneEncryptedID());
                 if (src.getSubjectConfirmationData())
                     setSubjectConfirmationData(src.getSubjectConfirmationData()->clone());
-                if (src.getKeyInfoConfirmationDataType())
-                    setKeyInfoConfirmationDataType(src.getKeyInfoConfirmationDataType()->cloneKeyInfoConfirmationDataType());
             }
             
             IMPL_XMLOBJECT_CLONE(SubjectConfirmation);
@@ -661,7 +661,6 @@ namespace opensaml {
             IMPL_TYPED_CHILD(NameID);
             IMPL_TYPED_CHILD(EncryptedID);
             IMPL_XMLOBJECT_CHILD(SubjectConfirmationData);
-            IMPL_TYPED_CHILD(KeyInfoConfirmationDataType);
     
         protected:
             void marshallAttributes(DOMElement* domElement) const {
@@ -672,7 +671,6 @@ namespace opensaml {
                 PROC_TYPED_CHILD(BaseID,SAML20_NS,false);
                 PROC_TYPED_CHILD(NameID,SAML20_NS,false);
                 PROC_TYPED_CHILD(EncryptedID,SAML20_NS,false);
-                PROC_TYPED_CHILD(KeyInfoConfirmationDataType,SAML20_NS,false);
                 PROC_XMLOBJECT_CHILD(SubjectConfirmationData,SAML20_NS);
                 AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
             }
@@ -1097,7 +1095,6 @@ namespace opensaml {
             }
         };
 
-        //TODO need unit test for this
         class SAML_DLLLOCAL AttributeValueImpl : public virtual AttributeValue, public AnyElementImpl
         {
         public:
@@ -1594,17 +1591,12 @@ const XMLCh EncryptedAssertion::LOCAL_NAME[] =      UNICODE_LITERAL_18(E,n,c,r,y
 const XMLCh EncryptedAttribute::LOCAL_NAME[] =      UNICODE_LITERAL_18(E,n,c,r,y,p,t,e,d,A,t,t,r,i,b,u,t,e);
 const XMLCh EncryptedElementType::LOCAL_NAME[] =    {chNull};
 const XMLCh EncryptedElementType::TYPE_NAME[] =     UNICODE_LITERAL_20(E,n,c,r,y,p,t,e,d,E,l,e,m,e,n,t,T,y,p,e);
-const XMLCh EncryptedID::LOCAL_NAME[] =             UNICODE_LITERAL_11(E,n,c,r,y,p,t,e,d,I,d);
+const XMLCh EncryptedID::LOCAL_NAME[] =             UNICODE_LITERAL_11(E,n,c,r,y,p,t,e,d,I,D);
 const XMLCh Evidence::LOCAL_NAME[] =                UNICODE_LITERAL_8(E,v,i,d,e,n,c,e);
 const XMLCh Evidence::TYPE_NAME[] =                 UNICODE_LITERAL_12(E,v,i,d,e,n,c,e,T,y,p,e);
 const XMLCh Issuer::LOCAL_NAME[] =                  UNICODE_LITERAL_6(I,s,s,u,e,r);
 const XMLCh KeyInfoConfirmationDataType::LOCAL_NAME[] = UNICODE_LITERAL_23(S,u,b,j,e,c,t,C,o,n,f,i,r,m,a,t,i,o,n,D,a,t,a);
 const XMLCh KeyInfoConfirmationDataType::TYPE_NAME[] = UNICODE_LITERAL_27(K,e,y,I,n,f,o,C,o,n,f,i,r,m,a,t,i,o,n,D,a,t,a,T,y,p,e);
-const XMLCh KeyInfoConfirmationDataType::NOTBEFORE_ATTRIB_NAME[] =      UNICODE_LITERAL_9(N,o,t,B,e,f,o,r,e);
-const XMLCh KeyInfoConfirmationDataType::NOTONORAFTER_ATTRIB_NAME[] =   UNICODE_LITERAL_12(N,o,t,O,n,O,r,A,f,t,e,r);
-const XMLCh KeyInfoConfirmationDataType::INRESPONSETO_ATTRIB_NAME[] =   UNICODE_LITERAL_12(I,n,R,e,s,p,o,n,s,e,T,o);
-const XMLCh KeyInfoConfirmationDataType::RECIPIENT_ATTRIB_NAME[] =      UNICODE_LITERAL_9(R,e,c,i,p,i,e,n,t);
-const XMLCh KeyInfoConfirmationDataType::ADDRESS_ATTRIB_NAME[] =        UNICODE_LITERAL_7(A,d,d,r,e,s,s);
 const XMLCh NameID::LOCAL_NAME[] =                  UNICODE_LITERAL_6(N,a,m,e,I,D);
 const XMLCh NameIDType::LOCAL_NAME[] =              {chNull};
 const XMLCh NameIDType::TYPE_NAME[] =               UNICODE_LITERAL_10(N,a,m,e,I,D,T,y,p,e);
@@ -1624,11 +1616,11 @@ const XMLCh SubjectConfirmation::LOCAL_NAME[] =     UNICODE_LITERAL_19(S,u,b,j,e
 const XMLCh SubjectConfirmation::TYPE_NAME[] =      UNICODE_LITERAL_23(S,u,b,j,e,c,t,C,o,n,f,i,r,m,a,t,i,o,n,T,y,p,e);
 const XMLCh SubjectConfirmation::METHOD_ATTRIB_NAME[] = UNICODE_LITERAL_6(M,e,t,h,o,d);
 const XMLCh SubjectConfirmationData::LOCAL_NAME[] = UNICODE_LITERAL_23(S,u,b,j,e,c,t,C,o,n,f,i,r,m,a,t,i,o,n,D,a,t,a);
-const XMLCh SubjectConfirmationData::NOTBEFORE_ATTRIB_NAME[] =      UNICODE_LITERAL_9(N,o,t,B,e,f,o,r,e);
-const XMLCh SubjectConfirmationData::NOTONORAFTER_ATTRIB_NAME[] =   UNICODE_LITERAL_12(N,o,t,O,n,O,r,A,f,t,e,r);
-const XMLCh SubjectConfirmationData::INRESPONSETO_ATTRIB_NAME[] =   UNICODE_LITERAL_12(I,n,R,e,s,p,o,n,s,e,T,o);
-const XMLCh SubjectConfirmationData::RECIPIENT_ATTRIB_NAME[] =      UNICODE_LITERAL_9(R,e,c,i,p,i,e,n,t);
-const XMLCh SubjectConfirmationData::ADDRESS_ATTRIB_NAME[] =        UNICODE_LITERAL_7(A,d,d,r,e,s,s);
+const XMLCh SubjectConfirmationDataType::NOTBEFORE_ATTRIB_NAME[] =      UNICODE_LITERAL_9(N,o,t,B,e,f,o,r,e);
+const XMLCh SubjectConfirmationDataType::NOTONORAFTER_ATTRIB_NAME[] =   UNICODE_LITERAL_12(N,o,t,O,n,O,r,A,f,t,e,r);
+const XMLCh SubjectConfirmationDataType::INRESPONSETO_ATTRIB_NAME[] =   UNICODE_LITERAL_12(I,n,R,e,s,p,o,n,s,e,T,o);
+const XMLCh SubjectConfirmationDataType::RECIPIENT_ATTRIB_NAME[] =      UNICODE_LITERAL_9(R,e,c,i,p,i,e,n,t);
+const XMLCh SubjectConfirmationDataType::ADDRESS_ATTRIB_NAME[] =        UNICODE_LITERAL_7(A,d,d,r,e,s,s);
 const XMLCh SubjectLocality::LOCAL_NAME[] =         UNICODE_LITERAL_15(S,u,b,j,e,c,t,L,o,c,a,l,i,t,y);
 const XMLCh SubjectLocality::TYPE_NAME[] =          UNICODE_LITERAL_19(S,u,b,j,e,c,t,L,o,c,a,l,i,t,y,T,y,p,e);
 const XMLCh SubjectLocality::ADDRESS_ATTRIB_NAME[] =UNICODE_LITERAL_7(A,d,d,r,e,s,s);