[cpp-opensaml] branch main updated: CPPOST-119 - Discovery filter for inline logos
Scott Cantor
cantor.2 at osu.edu
Thu Dec 3 22:10:47 UTC 2020
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository cpp-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-opensaml.git;a=commit;h=8f5f674f202d35dac5f25a131e43f1e7522aeee3
The following commit(s) were added to refs/heads/main by this push:
new 8f5f674 CPPOST-119 - Discovery filter for inline logos
8f5f674 is described below
commit 8f5f674f202d35dac5f25a131e43f1e7522aeee3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Dec 3 17:09:52 2020 -0500
CPPOST-119 - Discovery filter for inline logos
https://issues.shibboleth.net/jira/browse/CPPOST-119
---
Projects/vc15/saml/saml.vcxproj | 1 +
Projects/vc15/saml/saml.vcxproj.filters | 3 +
saml/Makefile.am | 1 +
saml/saml2/metadata/MetadataFilter.h | 3 +
.../metadata/impl/InlineLogoMetadataFilter.cpp | 125 +++++++++++++++++++++
saml/saml2/metadata/impl/MetadataProvider.cpp | 23 ++--
6 files changed, 149 insertions(+), 7 deletions(-)
diff --git a/Projects/vc15/saml/saml.vcxproj b/Projects/vc15/saml/saml.vcxproj
index 0d73c3f..aa96717 100644
--- a/Projects/vc15/saml/saml.vcxproj
+++ b/Projects/vc15/saml/saml.vcxproj
@@ -199,6 +199,7 @@
<ClCompile Include="..\..\..\saml\saml2\metadata\impl\ExcludeMetadataFilter.cpp" />
<ClCompile Include="..\..\..\saml\saml2\metadata\impl\FolderMetadataProvider.cpp" />
<ClCompile Include="..\..\..\saml\saml2\metadata\impl\IncludeMetadataFilter.cpp" />
+ <ClCompile Include="..\..\..\saml\saml2\metadata\impl\InlineLogoMetadataFilter.cpp" />
<ClCompile Include="..\..\..\saml\saml2\metadata\impl\NameEntityMatcher.cpp" />
<ClCompile Include="..\..\..\saml\saml2\metadata\impl\RegistrationAuthorityEntityMatcher.cpp" />
<ClCompile Include="..\..\..\saml\SAMLConfig.cpp" />
diff --git a/Projects/vc15/saml/saml.vcxproj.filters b/Projects/vc15/saml/saml.vcxproj.filters
index f626cd2..4d922ae 100644
--- a/Projects/vc15/saml/saml.vcxproj.filters
+++ b/Projects/vc15/saml/saml.vcxproj.filters
@@ -366,6 +366,9 @@
<ClCompile Include="..\..\..\saml\saml2\metadata\impl\IncludeMetadataFilter.cpp">
<Filter>Source Files\saml2\metadata\impl</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\saml\saml2\metadata\impl\InlineLogoMetadataFilter.cpp">
+ <Filter>Source Files\saml2\metadata\impl</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\saml\Assertion.h">
diff --git a/saml/Makefile.am b/saml/Makefile.am
index 15949f6..048ebdd 100644
--- a/saml/Makefile.am
+++ b/saml/Makefile.am
@@ -151,6 +151,7 @@ libsaml_la_SOURCES = \
saml2/metadata/impl/ObservableMetadataProvider.cpp \
saml2/metadata/impl/ExcludeMetadataFilter.cpp \
saml2/metadata/impl/IncludeMetadataFilter.cpp \
+ saml2/metadata/impl/InlineLogoMetadataFilter.cpp \
saml2/metadata/impl/RequireValidUntilMetadataFilter.cpp \
saml2/metadata/impl/SignatureMetadataFilter.cpp \
saml2/metadata/impl/RegistrationAuthorityEntityMatcher.cpp \
diff --git a/saml/saml2/metadata/MetadataFilter.h b/saml/saml2/metadata/MetadataFilter.h
index e923dc8..e1632d8 100644
--- a/saml/saml2/metadata/MetadataFilter.h
+++ b/saml/saml2/metadata/MetadataFilter.h
@@ -138,6 +138,9 @@ namespace opensaml {
/** MetadataFilter that adds EntityAttributes extension. */
#define ENTITYATTR_METADATA_FILTER "EntityAttributes"
+ /** MetadataFilter that removes inline logos from metadata. */
+ #define INLINELOGO_METADATA_FILTER "InlineLogo"
+
DECL_XMLTOOLING_EXCEPTION(MetadataFilterException,SAML_EXCEPTIONAPI(SAML_API),opensaml::saml2md,MetadataException,Exceptions related to metadata filtering);
};
};
diff --git a/saml/saml2/metadata/impl/InlineLogoMetadataFilter.cpp b/saml/saml2/metadata/impl/InlineLogoMetadataFilter.cpp
new file mode 100644
index 0000000..a80648f
--- /dev/null
+++ b/saml/saml2/metadata/impl/InlineLogoMetadataFilter.cpp
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you 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.
+ */
+
+/**
+ * InlineLogoMetadataFilter.cpp
+ *
+ * Removes inline logos from a metadata instance
+ */
+
+#include "internal.h"
+#include "saml2/metadata/Metadata.h"
+#include "saml2/metadata/MetadataFilter.h"
+
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/casts.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <xmltooling/logging.h>
+
+using namespace opensaml::saml2md;
+using namespace opensaml::saml2;
+using namespace xmltooling::logging;
+using namespace xmltooling;
+using namespace boost::lambda;
+using namespace boost;
+using namespace std;
+
+namespace opensaml {
+ namespace saml2md {
+ class SAML_DLLLOCAL InlineLogoMetadataFilter : public MetadataFilter
+ {
+ public:
+ InlineLogoMetadataFilter(const DOMElement* e, bool deprecationSupport=true) {}
+ ~InlineLogoMetadataFilter() {}
+
+ const char* getId() const { return EXCLUDE_METADATA_FILTER; }
+ void doFilter(const MetadataFilterContext* ctx, XMLObject& xmlObject) const;
+
+ private:
+ void filterGroup(EntitiesDescriptor*) const;
+ void filterEntity(EntityDescriptor*) const;
+ };
+
+ MetadataFilter* SAML_DLLLOCAL InlineLogoMetadataFilterFactory(const DOMElement* const & e, bool deprecationSupport)
+ {
+ return new InlineLogoMetadataFilter(e);
+ }
+ };
+};
+
+
+void InlineLogoMetadataFilter::doFilter(const MetadataFilterContext* ctx, XMLObject& xmlObject) const
+{
+ EntitiesDescriptor* group = dynamic_cast<EntitiesDescriptor*>(&xmlObject);
+ if (group) {
+ filterGroup(group);
+ }
+ else {
+ EntityDescriptor* entity = dynamic_cast<EntityDescriptor*>(&xmlObject);
+ if (entity) {
+ filterEntity(entity);
+ }
+ else {
+ throw MetadataFilterException(INLINELOGO_METADATA_FILTER " MetadataFilter was given an improper metadata instance to filter.");
+ }
+ }
+}
+
+void InlineLogoMetadataFilter::filterGroup(EntitiesDescriptor* entities) const
+{
+ const vector<EntityDescriptor*>& v = const_cast<const EntitiesDescriptor*>(entities)->getEntityDescriptors();
+ for_each(v.begin(), v.end(), lambda::bind(&InlineLogoMetadataFilter::filterEntity, this, _1));
+
+ const vector<EntitiesDescriptor*>& v2 = const_cast<const EntitiesDescriptor*>(entities)->getEntitiesDescriptors();
+ for_each(v2.begin(), v2.end(), lambda::bind(&InlineLogoMetadataFilter::filterGroup, this, _1));
+}
+
+void InlineLogoMetadataFilter::filterEntity(EntityDescriptor* entity) const
+{
+ static const XMLCh prefix[] = { chLatin_d, chLatin_a, chLatin_t, chLatin_a, chColon, chNull };
+
+ const list<XMLObject*>& children = const_cast<const EntityDescriptor*>(entity)->getOrderedChildren();
+ for (list<XMLObject*>::const_iterator child = children.begin(); child != children.end(); ++child) {
+ if (dynamic_cast<const RoleDescriptor*>(*child)) {
+ const Extensions* ext = dynamic_cast<const RoleDescriptor*>(*child)->getExtensions();
+ if (!ext)
+ continue;
+ const vector<XMLObject*>& exts = ext->getUnknownXMLObjects();
+ for (vector<XMLObject*>::const_iterator ext = exts.begin(); ext != exts.end(); ++ext) {
+ UIInfo* info = dynamic_cast<UIInfo*>(*ext);
+ if (info) {
+ VectorOf(Logo) v = info->getLogos();
+ for (VectorOf(Logo)::size_type i = 0; i < v.size(); ) {
+ const XMLCh* url = v[i]->getURL();
+ if (XMLString::startsWithI(url, prefix)) {
+ v.erase(v.begin() + i);
+ }
+ else {
+ i++;
+ }
+ }
+
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/saml/saml2/metadata/impl/MetadataProvider.cpp b/saml/saml2/metadata/impl/MetadataProvider.cpp
index 01ef9ef..0b0e922 100644
--- a/saml/saml2/metadata/impl/MetadataProvider.cpp
+++ b/saml/saml2/metadata/impl/MetadataProvider.cpp
@@ -54,6 +54,7 @@ namespace opensaml {
SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory NullMetadataProviderFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory ExcludeMetadataFilterFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory IncludeMetadataFilterFactory;
+ SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory InlineLogoMetadataFilterFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory SignatureMetadataFilterFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory RequireValidUntilMetadataFilterFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory EntityRoleMetadataFilterFactory;
@@ -75,6 +76,7 @@ void SAML_API opensaml::saml2md::registerMetadataFilters()
{
SAMLConfig::getConfig().MetadataFilterManager.registerFactory(EXCLUDE_METADATA_FILTER, ExcludeMetadataFilterFactory);
SAMLConfig::getConfig().MetadataFilterManager.registerFactory(INCLUDE_METADATA_FILTER, IncludeMetadataFilterFactory);
+ SAMLConfig::getConfig().MetadataFilterManager.registerFactory(INLINELOGO_METADATA_FILTER, InlineLogoMetadataFilterFactory);
SAMLConfig::getConfig().MetadataFilterManager.registerFactory(SIGNATURE_METADATA_FILTER, SignatureMetadataFilterFactory);
SAMLConfig::getConfig().MetadataFilterManager.registerFactory(REQUIREVALIDUNTIL_METADATA_FILTER, RequireValidUntilMetadataFilterFactory);
// additional name matching Java code
@@ -85,14 +87,13 @@ void SAML_API opensaml::saml2md::registerMetadataFilters()
// Deprecated names.
SAMLConfig::getConfig().MetadataFilterManager.registerFactory(BLACKLIST_METADATA_FILTER, ExcludeMetadataFilterFactory);
SAMLConfig::getConfig().MetadataFilterManager.registerFactory(WHITELIST_METADATA_FILTER, IncludeMetadataFilterFactory);
- SAMLConfig::getConfig().MetadataFilterManager.registerFactory("EntityRoleWhitelist", EntityRoleMetadataFilterFactory);
+ SAMLConfig::getConfig().MetadataFilterManager.registerFactory("EntityRoleWhiteList", EntityRoleMetadataFilterFactory);
}
static const XMLCh _MetadataFilter[] = UNICODE_LITERAL_14(M,e,t,a,d,a,t,a,F,i,l,t,e,r);
static const XMLCh BlacklistMF[] = UNICODE_LITERAL_23(B,l,a,c,k,l,i,s,t,M,e,t,a,d,a,t,a,F,i,l,t,e,r);
static const XMLCh WhitelistMF[] = UNICODE_LITERAL_23(W,h,i,t,e,l,i,s,t,M,e,t,a,d,a,t,a,F,i,l,t,e,r);
static const XMLCh SigFilter[] = UNICODE_LITERAL_23(S,i,g,n,a,t,u,r,e,M,e,t,a,d,a,t,a,F,i,l,t,e,r);
-static const XMLCh EntityRoleWhitelist[] = UNICODE_LITERAL_19(E,n,t,i,t,y,R,o,l,e,W,h,i,t,e,L,i,s,t);
static const XMLCh Exclude[] = UNICODE_LITERAL_7(E,x,c,l,u,d,e);
static const XMLCh Include[] = UNICODE_LITERAL_7(I,n,c,l,u,d,e);
static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
@@ -113,6 +114,19 @@ MetadataProvider::MetadataProvider(const DOMElement* e, bool deprecationSupport)
if (XMLString::equals(child->getLocalName(), _MetadataFilter)) {
string t = XMLHelper::getAttrString(child, nullptr, _type);
if (!t.empty()) {
+ if (t == WHITELIST_METADATA_FILTER) {
+ log.warn("DEPRECATED: type=\"%s\" replaced by type=\"%s\"", WHITELIST_METADATA_FILTER, INCLUDE_METADATA_FILTER);
+ t = INCLUDE_METADATA_FILTER;
+ }
+ else if (t == BLACKLIST_METADATA_FILTER) {
+ log.warn("DEPRECATED: type=\"%s\" replaced by type=\"%s\"", BLACKLIST_METADATA_FILTER, EXCLUDE_METADATA_FILTER);
+ t = EXCLUDE_METADATA_FILTER;
+ }
+ else if (t == "EntityRoleWhiteList") {
+ log.warn("DEPRECATED: type=\"EntityRoleWhiteList\" replaced by type=\"%s\"", ENTITYROLE_METADATA_FILTER);
+ t = ENTITYROLE_METADATA_FILTER;
+ }
+
log.info("building MetadataFilter of type %s", t.c_str());
auto_ptr<MetadataFilter> np(conf.MetadataFilterManager.newPlugin(t.c_str(), child, deprecationSupport));
m_filters.push_back(np.get());
@@ -122,11 +136,6 @@ MetadataProvider::MetadataProvider(const DOMElement* e, bool deprecationSupport)
log.error("MetadataFilter element missing type attribute");
}
}
- else if (deprecationSupport && XMLString::equals(child->getLocalName(), EntityRoleWhitelist)) {
- log.warn("DEPRECATED: type=\"EntityRoleWhiteList\" replaced by type=\"%s\"", ENTITYROLE_METADATA_FILTER);
- log.info("building MetadataFilter of type %s", ENTITYROLE_METADATA_FILTER);
- m_filters.push_back(conf.MetadataFilterManager.newPlugin(ENTITYROLE_METADATA_FILTER, child, deprecationSupport));
- }
else if (deprecationSupport && XMLString::equals(child->getLocalName(), SigFilter)) {
log.warn("DEPRECATED: <SignatureMetadataFilter> replaced by type=\"%s\"", SIGNATURE_METADATA_FILTER);
log.info("building MetadataFilter of type %s", SIGNATURE_METADATA_FILTER);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list