2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * XMLAttributeDecoder.cpp
24 * Decodes arbitrary XML into an XMLAttribute.
28 #include "attribute/AttributeDecoder.h"
29 #include "attribute/XMLAttribute.h"
31 #include <saml/saml1/core/Assertions.h>
32 #include <saml/saml2/core/Assertions.h>
33 #include <xmltooling/util/XMLHelper.h>
35 using namespace shibsp;
36 using namespace opensaml;
37 using namespace xmltooling;
41 class SHIBSP_DLLLOCAL XMLAttributeDecoder : virtual public AttributeDecoder
44 XMLAttributeDecoder(const DOMElement* e) : AttributeDecoder(e) {}
45 ~XMLAttributeDecoder() {}
48 const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=nullptr, const char* relyingParty=nullptr
52 DDF convert(DOMElement* e, bool nameit=true) const;
53 auto_ptr_char m_formatter;
54 map<pair<xstring,xstring>,string> m_tagMap;
57 AttributeDecoder* SHIBSP_DLLLOCAL XMLAttributeDecoderFactory(const DOMElement* const & e)
59 return new XMLAttributeDecoder(e);
64 Attribute* XMLAttributeDecoder::decode(
65 const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty
71 Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder.XML");
73 auto_ptr<XMLAttribute> attr(new XMLAttribute(ids));
74 vector<string>& dest = attr->getValues();
76 // Handle any non-Attribute object directly.
77 if (!xmlObject || !XMLString::equals(saml1::Attribute::LOCAL_NAME, xmlObject->getElementQName().getLocalPart())) {
78 DOMElement* e = xmlObject->getDOM();
80 if (log.isDebugEnabled()) {
82 "decoding XMLAttribute (%s) from XMLObject (%s)",
84 (xmlObject->getSchemaType() ? xmlObject->getSchemaType()->toString() : xmlObject->getElementQName().toString()).c_str()
87 dest.push_back(string());
88 XMLHelper::serialize(e, dest.back());
91 log.warn("skipping XMLObject without a backing DOM");
93 return dest.empty() ? nullptr : _decode(attr.release());
96 vector<XMLObject*>::const_iterator v,stop;
98 const saml2::Attribute* saml2attr = dynamic_cast<const saml2::Attribute*>(xmlObject);
100 const vector<XMLObject*>& values = saml2attr->getAttributeValues();
103 if (log.isDebugEnabled()) {
104 auto_ptr_char n(saml2attr->getName());
106 "decoding XMLAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)",
107 ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()
112 const saml1::Attribute* saml1attr = dynamic_cast<const saml1::Attribute*>(xmlObject);
114 const vector<XMLObject*>& values = saml1attr->getAttributeValues();
117 if (log.isDebugEnabled()) {
118 auto_ptr_char n(saml1attr->getAttributeName());
120 "decoding XMLAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)",
121 ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()
126 log.warn("XMLObject type not recognized by XMLAttributeDecoder, no values returned");
131 for (; v!=stop; ++v) {
132 DOMElement* e = (*v)->getDOM();
134 dest.push_back(string());
135 XMLHelper::serialize(e, dest.back());
138 log.warn("skipping AttributeValue without a backing DOM");
141 return dest.empty() ? nullptr : _decode(attr.release());