-/*
- * Copyright 2009 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.
*/
/**
* EntityRoleMetadataFilter.cpp
*
- * Removes non-whitelisted roles from a metadata instance
+ * Removes non-whitelisted roles from a metadata instance.
*/
#include "internal.h"
#include "saml2/metadata/MetadataFilter.h"
#include <xmltooling/logging.h>
-#include <xmltooling/util/NDC.h>
using namespace opensaml::saml2md;
using namespace xmltooling::logging;
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(NULL, removeRolelessEntityDescriptors) : NULL;
- if (flag && (*flag == chLatin_f || *flag == chDigit_0))
- m_removeRolelessEntityDescriptors = false;
- flag = e ? e->getAttributeNS(NULL, removeEmptyEntitiesDescriptors) : NULL;
- 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));
else if (*q == AuthzDecisionQueryDescriptorType::TYPE_QNAME)
m_authzq = true;
else
- m_roles.insert(*q.get());
+ m_roles.insert(*q);
}
e = XMLHelper::getNextSiblingElement(e, RetainedRole);
}
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]);
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()) {
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);