SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / EntityRoleMetadataFilter.cpp
index 0457339..3f4b9ac 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2009-2010 Internet2
+/**
+ * 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.
  *
- * 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
+ * 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
+ * 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.
+ * 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.
  */
 
 /**
@@ -25,7 +29,6 @@
 #include "saml2/metadata/MetadataFilter.h"
 
 #include <xmltooling/logging.h>
-#include <xmltooling/util/NDC.h>
 
 using namespace opensaml::saml2md;
 using namespace xmltooling::logging;
@@ -66,16 +69,10 @@ static const XMLCh removeRolelessEntityDescriptors[] =  UNICODE_LITERAL_31(r,e,m
 static const XMLCh removeEmptyEntitiesDescriptors[] =   UNICODE_LITERAL_30(r,e,m,o,v,e,E,m,p,t,y,E,n,t,i,t,i,e,s,D,e,s,c,r,i,p,t,o,r,s);
 
 EntityRoleMetadataFilter::EntityRoleMetadataFilter(const DOMElement* e)
-    : m_removeRolelessEntityDescriptors(true), m_removeEmptyEntitiesDescriptors(true),
+    : m_removeRolelessEntityDescriptors(XMLHelper::getAttrBool(e, true, removeRolelessEntityDescriptors)),
+        m_removeEmptyEntitiesDescriptors(XMLHelper::getAttrBool(e, true, removeEmptyEntitiesDescriptors)),
         m_idp(false), m_sp(false), m_authn(false), m_attr(false), m_pdp(false), m_authnq(false), m_attrq(false), m_authzq(false)
 {
-    const XMLCh* flag = e ? e->getAttributeNS(nullptr, removeRolelessEntityDescriptors) : nullptr;
-    if (flag && (*flag == chLatin_f || *flag == chDigit_0))
-        m_removeRolelessEntityDescriptors = false;
-    flag = e ? e->getAttributeNS(nullptr, removeEmptyEntitiesDescriptors) : nullptr;
-    if (flag && (*flag == chLatin_f || *flag == chDigit_0))
-        m_removeEmptyEntitiesDescriptors = false;
-
     e = XMLHelper::getFirstChildElement(e, RetainedRole);
     while (e) {
         auto_ptr<xmltooling::QName> q(XMLHelper::getNodeValueAsQName(e));
@@ -97,7 +94,7 @@ EntityRoleMetadataFilter::EntityRoleMetadataFilter(const DOMElement* e)
             else if (*q == AuthzDecisionQueryDescriptorType::TYPE_QNAME)
                 m_authzq = true;
             else
-                m_roles.insert(*q.get());
+                m_roles.insert(*q);
         }
         e = XMLHelper::getNextSiblingElement(e, RetainedRole);
     }
@@ -105,33 +102,27 @@ EntityRoleMetadataFilter::EntityRoleMetadataFilter(const DOMElement* e)
 
 void EntityRoleMetadataFilter::doFilter(XMLObject& xmlObject) const
 {
-#ifdef _DEBUG
-    NDC ndc("doFilter");
-#endif
-
-    try {
-        doFilter(dynamic_cast<EntitiesDescriptor&>(xmlObject));
-        return;
-    }
-    catch (bad_cast) {
-    }
-
-    try {
-        doFilter(dynamic_cast<EntityDescriptor&>(xmlObject));
-        return;
+    EntitiesDescriptor* group = dynamic_cast<EntitiesDescriptor*>(&xmlObject);
+    if (group) {
+        doFilter(*group);
     }
-    catch (bad_cast) {
+    else {
+        EntityDescriptor* entity = dynamic_cast<EntityDescriptor*>(&xmlObject);
+        if (entity) {
+            doFilter(*entity);
+        }
+        else {
+            throw MetadataFilterException(ENTITYROLE_METADATA_FILTER " MetadataFilter was given an improper metadata instance to filter.");
+        }
     }
-
-    throw MetadataFilterException("EntityRoleWhiteList MetadataFilter was given an improper metadata instance to filter.");
 }
 
 void EntityRoleMetadataFilter::doFilter(EntitiesDescriptor& entities) const
 {
-    Category& log=Category::getInstance(SAML_LOGCAT".MetadataFilter.EntityRoleWhiteList");
+    Category& log=Category::getInstance(SAML_LOGCAT ".MetadataFilter." ENTITYROLE_METADATA_FILTER);
 
-    VectorOf(EntityDescriptor) v=entities.getEntityDescriptors();
-    for (VectorOf(EntityDescriptor)::size_type i=0; i<v.size(); ) {
+    VectorOf(EntityDescriptor) v = entities.getEntityDescriptors();
+    for (VectorOf(EntityDescriptor)::size_type i = 0; i < v.size(); ) {
         doFilter(*v[i]);
         if (m_removeRolelessEntityDescriptors) {
             const EntityDescriptor& e = const_cast<const EntityDescriptor&>(*v[i]);
@@ -153,8 +144,8 @@ void EntityRoleMetadataFilter::doFilter(EntitiesDescriptor& entities) const
         i++;
     }
 
-    VectorOf(EntitiesDescriptor) groups=entities.getEntitiesDescriptors();
-    for (VectorOf(EntitiesDescriptor)::size_type j=0; j<groups.size(); ) {
+    VectorOf(EntitiesDescriptor) groups = entities.getEntitiesDescriptors();
+    for (VectorOf(EntitiesDescriptor)::size_type j = 0; j < groups.size(); ) {
         EntitiesDescriptor* group = groups[j];
         doFilter(*group);
         if (m_removeEmptyEntitiesDescriptors && group->getEntitiesDescriptors().empty() && group->getEntityDescriptors().empty()) {
@@ -193,7 +184,7 @@ void EntityRoleMetadataFilter::doFilter(EntityDescriptor& entity) const
         entity.getAuthzDecisionQueryDescriptorTypes().clear();
 
     VectorOf(RoleDescriptor) v = entity.getRoleDescriptors();
-    for (VectorOf(RoleDescriptor)::size_type i=0; i<v.size(); ) {
+    for (VectorOf(RoleDescriptor)::size_type i = 0; i < v.size(); ) {
         const xmltooling::QName* type = v[i]->getSchemaType();
         if (!type || m_roles.find(*type) != m_roles.end())
             v.erase(v.begin() + i);