From 5e9effa89c8863b16112fec370d63a64b5803744 Mon Sep 17 00:00:00 2001 From: cantor Date: Wed, 27 Dec 2006 19:55:49 +0000 Subject: [PATCH] Metadata extension classes. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2096 cb58f699-b61c-0410-a6fe-9272a202ed29 --- shibsp/Makefile.am | 9 +- shibsp/MetadataExt.h | 55 +++++++++++ shibsp/MetadataExtImpl.cpp | 162 +++++++++++++++++++++++++++++++++ shibsp/MetadataExtSchemaValidators.cpp | 52 +++++++++++ shibsp/SPConfig.cpp | 2 + shibsp/SPConstants.cpp | 9 ++ shibsp/SPConstants.h | 1 + shibsp/shibsp.vcproj | 12 +++ 8 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 shibsp/MetadataExt.h create mode 100644 shibsp/MetadataExtImpl.cpp create mode 100644 shibsp/MetadataExtSchemaValidators.cpp diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am index 317ded5..a2f9493 100644 --- a/shibsp/Makefile.am +++ b/shibsp/Makefile.am @@ -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 index 0000000..7473025 --- /dev/null +++ b/shibsp/MetadataExt.h @@ -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 +#include +#include +#include + +#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 index 0000000..208035f --- /dev/null +++ b/shibsp/MetadataExtImpl.cpp @@ -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 +#include +#include +#include +#include +#include + +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::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 index 0000000..4ce8cec --- /dev/null +++ b/shibsp/MetadataExtSchemaValidators.cpp @@ -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 + +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); +} diff --git a/shibsp/SPConfig.cpp b/shibsp/SPConfig.cpp index 90bd9c2..34728fb 100644 --- a/shibsp/SPConfig.cpp +++ b/shibsp/SPConfig.cpp @@ -24,6 +24,7 @@ #include "internal.h" #include "exceptions.h" #include "ListenerService.h" +#include "MetadataExt.h" #include "SPConfig.h" #include @@ -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; diff --git a/shibsp/SPConstants.cpp b/shibsp/SPConstants.cpp index 5cafeae..c98c17a 100644 --- a/shibsp/SPConstants.cpp +++ b/shibsp/SPConstants.cpp @@ -32,6 +32,15 @@ const XMLCh shibspconstants::SHIB1_PROTOCOL_ENUM[] = // urn:mace:shibboleth:1.0 chDigit_1, chPeriod, chDigit_0, chNull }; +const XMLCh shibspconstants::SHIBMD_NS[] = // urn:mace:shibboleth:metadata:1.0 +{ chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_m, chLatin_a, chLatin_c, chLatin_e, chColon, + chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, chColon, + chLatin_m, chLatin_e, chLatin_t, chLatin_a, chLatin_d, chLatin_a, chLatin_t, chLatin_a, chColon, + chDigit_1, chPeriod, chDigit_0, chNull +}; + +const XMLCh shibspconstants::SHIBMD_PREFIX[] = UNICODE_LITERAL_6(s,h,i,b,m,d); + const XMLCh shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI[] = // urn:mace:shibboleth:1.0:attributeNamespace:uri { chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_m, chLatin_a, chLatin_c, chLatin_e, chColon, chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, chColon, diff --git a/shibsp/SPConstants.h b/shibsp/SPConstants.h index 16e9d9b..8c04d80 100644 --- a/shibsp/SPConstants.h +++ b/shibsp/SPConstants.h @@ -23,6 +23,7 @@ #ifndef __shibsp_constants_h__ #define __shibsp_constants_h__ +#include #include /** diff --git a/shibsp/shibsp.vcproj b/shibsp/shibsp.vcproj index 8d730e9..022e889 100644 --- a/shibsp/shibsp.vcproj +++ b/shibsp/shibsp.vcproj @@ -197,6 +197,14 @@ > + + + + @@ -239,6 +247,10 @@ > + + -- 2.1.4