From dab967a4c891e87feb242cd47e32bf646286174d Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Tue, 2 Jan 2007 03:03:31 +0000 Subject: [PATCH] Clean up catalogs, metadata endpoint mgmt template. --- saml/Makefile.am | 1 + saml/saml.vcproj | 4 ++ saml/saml2/metadata/EndpointManager.h | 130 ++++++++++++++++++++++++++++++++++ saml/util/SAMLConstants.cpp | 7 ++ saml/util/SAMLConstants.h | 4 +- schemas/saml10-catalog.xml.in | 1 - schemas/saml11-catalog.xml.in | 1 - schemas/saml20-catalog.xml.in | 1 - 8 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 saml/saml2/metadata/EndpointManager.h diff --git a/saml/Makefile.am b/saml/Makefile.am index 8dcd88e..81322b2 100644 --- a/saml/Makefile.am +++ b/saml/Makefile.am @@ -99,6 +99,7 @@ saml2bindinclude_HEADERS = \ saml2mdinclude_HEADERS = \ saml2/metadata/AbstractMetadataProvider.h \ saml2/metadata/ChainingMetadataProvider.h \ + saml2/metadata/EndpointManager.h \ saml2/metadata/Metadata.h \ saml2/metadata/MetadataFilter.h \ saml2/metadata/MetadataKeyInfoIterator.h \ diff --git a/saml/saml.vcproj b/saml/saml.vcproj index 2d13c5a..864a6e2 100644 --- a/saml/saml.vcproj +++ b/saml/saml.vcproj @@ -704,6 +704,10 @@ > + + diff --git a/saml/saml2/metadata/EndpointManager.h b/saml/saml2/metadata/EndpointManager.h new file mode 100644 index 0000000..d8b0b8b --- /dev/null +++ b/saml/saml2/metadata/EndpointManager.h @@ -0,0 +1,130 @@ +/* + * 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 saml/saml2/metadata/EndpointManager.h + * + * Templates for processing endpoint information. + */ + +#ifndef __saml_epmgr_h__ +#define __saml_epmgr_h__ + +#include + +namespace opensaml { + namespace saml2md { + + /** + * Template for processing unindexed endpoint information. + * + * @param _Tx the endpoint type being managed + */ + template + class EndpointManager + { + protected: + typename const std::vector<_Tx*>& m_endpoints; + + public: + /** + * Constructor. + * + * @param endpoints array of endpoints to manage + */ + EndpointManager(typename const std::vector<_Tx*>& endpoints) : m_endpoints(endpoints) { + } + + /** + * Returns endpoint that supports a particular binding. + * + * @param binding binding to locate + * @return a supporting endpoint, favoring the default, or NULL + */ + const _Tx* getByBinding(const XMLCh* binding) const { + for (std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) { + if (xercesc::XMLString::equals(binding,(*i)->getBinding())) + return *i; + } + return NULL; + } + }; + + /** + * Template for processing indexed endpoint information. + * + * @param _Tx the endpoint type being managed + */ + template + class IndexedEndpointManager : public EndpointManager<_Tx> + { + typename const _Tx* m_default; + + public: + /** + * Constructor. + * + * @param endpoints array of endpoints to manage + */ + IndexedEndpointManager(typename const std::vector<_Tx*>& endpoints) : EndpointManager(endpoints), m_default(NULL) { + } + + /** + * Returns the default endpoint in the set. + * + * @return the default endpoint + */ + const _Tx* getDefault() const { + if (m_default) + return m_default; + for (std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) { + if ((*i)->isDefault()) + return m_default=*i; + } + return (m_endpoints.empty()) ? m_default=NULL : m_default=m_endpoints.front(); + } + + /** + * Returns indexed endpoint. + * + * @param index index to locate + * @return matching endpoint, or NULL + */ + const _Tx* getByIndex(unsigned short index) const { + for (std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) { + std::pair comp = (*i)->getIndex(); + if (comp.first && index == comp.second) + return *i; + } + return NULL; + } + + /** + * Returns endpoint that supports a particular binding. + * + * @param binding binding to locate + * @return a supporting endpoint, favoring the default, or NULL + */ + const _Tx* getByBinding(const XMLCh* binding) const { + if (getDefault() && xercesc::XMLString::equals(binding,m_default->getBinding())) + return m_default; + return EndpointManager::getByBinding(binding); + } + }; + }; +}; + +#endif /* __saml_epmgr_h__ */ diff --git a/saml/util/SAMLConstants.cpp b/saml/util/SAMLConstants.cpp index 1069ea4..304b048 100644 --- a/saml/util/SAMLConstants.cpp +++ b/saml/util/SAMLConstants.cpp @@ -149,6 +149,13 @@ const XMLCh samlconstants::SAML1MD_NS[] = // urn:oasis:names:tc:SAML:profiles:v1 const XMLCh samlconstants::SAML1MD_PREFIX[] = { chLatin_s, chLatin_a, chLatin_m, chLatin_l, chDigit_1, chLatin_m, chLatin_d, chNull }; +const XMLCh samlconstants::SAML10_PROTOCOL_ENUM[] = // urn:oasis:names:tc:SAML:1.0:protocol +{ chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_o, chLatin_a, chLatin_s, chLatin_i, chLatin_s, chColon, + chLatin_n, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chColon, chLatin_t, chLatin_c, chColon, + chLatin_S, chLatin_A, chLatin_M, chLatin_L, chColon, chDigit_1, chPeriod, chDigit_0, chColon, + chLatin_p, chLatin_r, chLatin_o, chLatin_t, chLatin_o, chLatin_c, chLatin_o, chLatin_l, chNull +}; + const XMLCh samlconstants::SAML11_PROTOCOL_ENUM[] = // urn:oasis:names:tc:SAML:1.1:protocol { chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_o, chLatin_a, chLatin_s, chLatin_i, chLatin_s, chColon, chLatin_n, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chColon, chLatin_t, chLatin_c, chColon, diff --git a/saml/util/SAMLConstants.h b/saml/util/SAMLConstants.h index 8f9a9c5..40953bf 100644 --- a/saml/util/SAMLConstants.h +++ b/saml/util/SAMLConstants.h @@ -105,10 +105,8 @@ namespace samlconstants { /** SAML 1.x Metadata Profile QName prefix ("saml1md") */ extern SAML_API const XMLCh SAML1MD_PREFIX[]; -#ifndef SAML10_PROTOCOL_ENUM /** SAML 1.0 Protocol Enumeration constant ("urn:oasis:names:tc:SAML:1.0:protocol") */ - #define SAML10_PROTOCOL_ENUM samlconstants::SAML1P_NS -#endif + extern SAML_API const XMLCh SAML10_PROTOCOL_ENUM[]; /** SAML 1.1 Protocol Enumeration constant ("urn:oasis:names:tc:SAML:1.1:protocol") */ extern SAML_API const XMLCh SAML11_PROTOCOL_ENUM[]; diff --git a/schemas/saml10-catalog.xml.in b/schemas/saml10-catalog.xml.in index e861335..24c8b71 100644 --- a/schemas/saml10-catalog.xml.in +++ b/schemas/saml10-catalog.xml.in @@ -1,7 +1,6 @@ - diff --git a/schemas/saml11-catalog.xml.in b/schemas/saml11-catalog.xml.in index 5f484d9..090084a 100644 --- a/schemas/saml11-catalog.xml.in +++ b/schemas/saml11-catalog.xml.in @@ -1,7 +1,6 @@ - diff --git a/schemas/saml20-catalog.xml.in b/schemas/saml20-catalog.xml.in index 9fb17d7..fa4fcf5 100644 --- a/schemas/saml20-catalog.xml.in +++ b/schemas/saml20-catalog.xml.in @@ -1,7 +1,6 @@ - -- 2.1.4