Metadata extension classes.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 27 Dec 2006 19:55:49 +0000 (19:55 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 27 Dec 2006 19:55:49 +0000 (19:55 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2096 cb58f699-b61c-0410-a6fe-9272a202ed29

shibsp/Makefile.am
shibsp/MetadataExt.h [new file with mode: 0644]
shibsp/MetadataExtImpl.cpp [new file with mode: 0644]
shibsp/MetadataExtSchemaValidators.cpp [new file with mode: 0644]
shibsp/SPConfig.cpp
shibsp/SPConstants.cpp
shibsp/SPConstants.h
shibsp/shibsp.vcproj

index 317ded5..a2f9493 100644 (file)
@@ -13,11 +13,13 @@ libshibspinclude_HEADERS = \
        DOMPropertySet.h \
        exceptions.h \
        ListenerService.h \
+       MetadataExt.h \
        paths.h \
        PropertySet.h \
        version.h \
        SocketListener.h \
-       SPConfig.h
+       SPConfig.h \
+       SPConstants.h
 
 noinst_HEADERS = \
        internal.h
@@ -26,10 +28,13 @@ libshibsp_la_SOURCES = \
        ddf.cpp \
        DOMPropertySet.cpp \
        ListenerService.cpp \
+       MetadataExtImpl.cpp \
+       MetadataExtSchemaValidators.cpp \
        SocketListener.cpp \
        TCPListener.cpp \
        UnixListener.cpp \
-       SPConfig.cpp
+       SPConfig.cpp \
+       SPConstants.cpp
 
 # this is different from the project version
 # http://sources.redhat.com/autobook/autobook/autobook_91.html
diff --git a/shibsp/MetadataExt.h b/shibsp/MetadataExt.h
new file mode 100644 (file)
index 0000000..7473025
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  Copyright 2001-2006 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file shibsp/MetadataExt
+ * 
+ * XMLObjects representing Shibboleth metadata extensions
+ */
+
+#ifndef __shibsp_metaext_h__
+#define __shibsp_metaext_h__
+
+#include <shibsp/SPConstants.h>
+#include <xmltooling/XMLObjectBuilder.h>
+#include <xmltooling/signature/KeyInfo.h>
+#include <xercesc/util/XMLUniDefs.hpp>
+
+#define DECL_SHIBOBJECTBUILDER(cname) \
+    DECL_XMLOBJECTBUILDER(SHIBSP_API,cname,shibspconstants::SHIBMD_NS,shibspconstants::SHIBMD_PREFIX)
+
+namespace shibsp {
+
+    BEGIN_XMLOBJECT(SHIBSP_API,Scope,xmltooling::XMLObject,Scope element);
+        DECL_BOOLEAN_ATTRIB(regexp,REGEXP,false);
+        DECL_SIMPLE_CONTENT(Value);
+    END_XMLOBJECT;
+
+    BEGIN_XMLOBJECT(SHIBSP_API,KeyAuthority,xmltooling::AttributeExtensibleXMLObject,KeyAuthority element);
+        DECL_INTEGER_ATTRIB(VerifyDepth,VERIFYDEPTH);
+        DECL_TYPED_FOREIGN_CHILDREN(KeyInfo,xmlsignature);
+    END_XMLOBJECT;
+
+    DECL_SHIBOBJECTBUILDER(Scope);
+    DECL_SHIBOBJECTBUILDER(KeyAuthority);
+    
+    /**
+     * Registers builders and validators for Shibboleth metadata extension classes into the runtime.
+     */
+    void SHIBSP_API registerMetadataExtClasses();
+};
+
+#endif /* __shibsp_metaext_h__ */
diff --git a/shibsp/MetadataExtImpl.cpp b/shibsp/MetadataExtImpl.cpp
new file mode 100644 (file)
index 0000000..208035f
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ *  Copyright 2001-2006 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * MetadataExtImpl.cpp
+ * 
+ * Implementation classes for Shibboleth metadata extensions schema
+ */
+
+#include "internal.h"
+#include "exceptions.h"
+#include "MetadataExt.h"
+
+#include <xmltooling/AbstractComplexElement.h>
+#include <xmltooling/AbstractSimpleElement.h>
+#include <xmltooling/impl/AnyElement.h>
+#include <xmltooling/io/AbstractXMLObjectMarshaller.h>
+#include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
+#include <xmltooling/util/XMLHelper.h>
+
+using namespace shibsp;
+using namespace xmlsignature;
+using namespace xmltooling;
+using namespace std;
+
+using xmlconstants::XMLSIG_NS;
+using xmlconstants::XML_BOOL_NULL;
+using shibspconstants::SHIBMD_NS;
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4250 4251 )
+#endif
+
+namespace shibsp {
+
+    class SHIBSP_DLLLOCAL ScopeImpl : public virtual Scope,
+        public AbstractSimpleElement,
+        public AbstractDOMCachingXMLObject,
+        public AbstractXMLObjectMarshaller,
+        public AbstractXMLObjectUnmarshaller
+    {
+        void init() {
+            m_regexp=XML_BOOL_NULL;
+        }
+
+    public:
+
+        ScopeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
+                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+            init();
+        }
+            
+        ScopeImpl(const ScopeImpl& src)
+                : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src) {
+            init();
+            regexp(src.m_regexp);
+        }
+        
+        IMPL_XMLOBJECT_CLONE(Scope);
+        IMPL_BOOLEAN_ATTRIB(regexp);
+
+    protected:
+        void marshallAttributes(DOMElement* domElement) const {
+            MARSHALL_BOOLEAN_ATTRIB(regexp,REGEXP,NULL);
+        }
+
+        void processAttribute(const DOMAttr* attribute) {
+            PROC_BOOLEAN_ATTRIB(regexp,REGEXP,NULL);
+            AbstractXMLObjectUnmarshaller::processAttribute(attribute);
+        }
+    };
+
+    class SHIBSP_DLLLOCAL KeyAuthorityImpl : public virtual KeyAuthority,
+            public AbstractComplexElement,
+            public AbstractAttributeExtensibleXMLObject,
+            public AbstractDOMCachingXMLObject,
+            public AbstractXMLObjectMarshaller,
+            public AbstractXMLObjectUnmarshaller
+    {
+        void init() {
+            m_VerifyDepth=NULL;
+        }
+    public:
+        virtual ~KeyAuthorityImpl() {
+            XMLString::release(&m_VerifyDepth);
+        }
+
+        KeyAuthorityImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
+                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+            init();
+        }
+            
+        KeyAuthorityImpl(const KeyAuthorityImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src),
+                    AbstractAttributeExtensibleXMLObject(src), AbstractDOMCachingXMLObject(src) {
+            init();
+            setVerifyDepth(src.m_VerifyDepth);
+            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(KeyAuthority);
+        IMPL_INTEGER_ATTRIB(VerifyDepth);
+        IMPL_TYPED_CHILDREN(KeyInfo,m_children.end());
+        
+    public:
+        void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false) {
+            if (!qualifiedName.hasNamespaceURI()) {
+                if (XMLString::equals(qualifiedName.getLocalPart(),VERIFYDEPTH_ATTRIB_NAME)) {
+                    setVerifyDepth(value);
+                    return;
+                }
+            }
+            AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value, ID);
+        }
+
+    protected:
+        void marshallAttributes(DOMElement* domElement) const {
+            MARSHALL_INTEGER_ATTRIB(VerifyDepth,VERIFYDEPTH,NULL);
+            marshallExtensionAttributes(domElement);
+        }
+
+        void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
+            PROC_TYPED_CHILDREN(KeyInfo,XMLSIG_NS,false);
+            AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
+        }
+
+        void processAttribute(const DOMAttr* attribute) {
+            unmarshallExtensionAttribute(attribute);
+        }
+    };
+
+};
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
+// Builder Implementations
+
+IMPL_XMLOBJECTBUILDER(Scope);
+IMPL_XMLOBJECTBUILDER(KeyAuthority);
+
+const XMLCh Scope::LOCAL_NAME[] =                       UNICODE_LITERAL_5(S,c,o,p,e);
+const XMLCh Scope::REGEXP_ATTRIB_NAME[] =               UNICODE_LITERAL_6(r,e,g,e,x,p);
+const XMLCh KeyAuthority::LOCAL_NAME[] =                UNICODE_LITERAL_12(K,e,y,A,u,t,h,o,r,i,t,y);
+const XMLCh KeyAuthority::VERIFYDEPTH_ATTRIB_NAME[] =   UNICODE_LITERAL_11(V,e,r,i,f,y,D,e,p,t,h);
diff --git a/shibsp/MetadataExtSchemaValidators.cpp b/shibsp/MetadataExtSchemaValidators.cpp
new file mode 100644 (file)
index 0000000..4ce8cec
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+*  Copyright 2001-2006 Internet2
+ * 
+* Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * MetadataExtSchemaValidators.cpp
+ * 
+ * Schema-based validators for Shibboleth metadata extension classes
+ */
+
+#include "internal.h"
+#include "exceptions.h"
+#include "MetadataExt.h"
+
+#include <xmltooling/validation/ValidatorSuite.h>
+
+using namespace shibsp;
+using namespace xmltooling;
+using namespace std;
+
+using shibspconstants::SHIBMD_NS;
+
+namespace shibsp {
+    XMLOBJECTVALIDATOR_SIMPLE(SHIBSP_DLLLOCAL,Scope);
+
+    BEGIN_XMLOBJECTVALIDATOR(SHIBSP_DLLLOCAL,KeyAuthority);
+        XMLOBJECTVALIDATOR_NONEMPTY(KeyAuthority,KeyInfo);
+    END_XMLOBJECTVALIDATOR;
+};
+
+#define REGISTER_ELEMENT(cname) \
+    q=QName(SHIBMD_NS,cname::LOCAL_NAME); \
+    XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
+    SchemaValidators.registerValidator(q,new cname##SchemaValidator())
+    
+void shibsp::registerMetadataExtClasses() {
+    QName q;
+    REGISTER_ELEMENT(Scope);
+    REGISTER_ELEMENT(KeyAuthority);
+}
index 90bd9c2..34728fb 100644 (file)
@@ -24,6 +24,7 @@
 #include "internal.h"
 #include "exceptions.h"
 #include "ListenerService.h"
+#include "MetadataExt.h"
 #include "SPConfig.h"
 
 #include <log4cpp/Category.hh>
@@ -87,6 +88,7 @@ bool SPInternalConfig::init(const char* catalog_path)
     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
     
     registerListenerServices();
+    registerMetadataExtClasses();
 
     log.info("library initialization complete");
     return true;
index 5cafeae..c98c17a 100644 (file)
@@ -32,6 +32,15 @@ const XMLCh shibspconstants::SHIB1_PROTOCOL_ENUM[] = // urn:mace:shibboleth:1.0
   chDigit_1, chPeriod, chDigit_0, chNull\r
 };\r
 \r
+const XMLCh shibspconstants::SHIBMD_NS[] = // urn:mace:shibboleth:metadata:1.0\r
+{ chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_m, chLatin_a, chLatin_c, chLatin_e, chColon,\r
+  chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, chColon,\r
+  chLatin_m, chLatin_e, chLatin_t, chLatin_a, chLatin_d, chLatin_a, chLatin_t, chLatin_a, chColon,\r
+  chDigit_1, chPeriod, chDigit_0, chNull\r
+};\r
+\r
+const XMLCh shibspconstants::SHIBMD_PREFIX[] = UNICODE_LITERAL_6(s,h,i,b,m,d);\r
+\r
 const XMLCh shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI[] = // urn:mace:shibboleth:1.0:attributeNamespace:uri\r
 { chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_m, chLatin_a, chLatin_c, chLatin_e, chColon,\r
   chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, chColon,\r
index 16e9d9b..8c04d80 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __shibsp_constants_h__
 #define __shibsp_constants_h__
 
+#include <shibsp/base.h>
 #include <saml/util/SAMLConstants.h>
 
 /**
index 8d730e9..022e889 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\MetadataExtImpl.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\MetadataExtSchemaValidators.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\SocketListener.cpp"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\MetadataExt.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\PropertySet.h"\r
                                >\r
                        </File>\r