-/*\r
- * Copyright 2009 Internet2\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * XMLAttributeDecoder.cpp\r
- *\r
- * Decodes arbitrary XML into an XMLAttribute.\r
- */\r
-\r
-#include "internal.h"\r
-#include "attribute/AttributeDecoder.h"\r
-#include "attribute/XMLAttribute.h"\r
-\r
-#include <saml/saml1/core/Assertions.h>\r
-#include <saml/saml2/core/Assertions.h>\r
-#include <xmltooling/util/XMLHelper.h>\r
-\r
-using namespace shibsp;\r
-using namespace opensaml;\r
-using namespace xmltooling;\r
-using namespace std;\r
-\r
-namespace shibsp {\r
- class SHIBSP_DLLLOCAL XMLAttributeDecoder : virtual public AttributeDecoder\r
- {\r
- public:\r
- XMLAttributeDecoder(const DOMElement* e) : AttributeDecoder(e) {}\r
- ~XMLAttributeDecoder() {}\r
-\r
- Attribute* decode(\r
- const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=NULL, const char* relyingParty=NULL\r
- ) const;\r
-\r
- private:\r
- DDF convert(DOMElement* e, bool nameit=true) const;\r
- auto_ptr_char m_formatter;\r
- map<pair<xstring,xstring>,string> m_tagMap;\r
- };\r
-\r
- AttributeDecoder* SHIBSP_DLLLOCAL XMLAttributeDecoderFactory(const DOMElement* const & e)\r
- {\r
- return new XMLAttributeDecoder(e);\r
- }\r
-};\r
-\r
-\r
-Attribute* XMLAttributeDecoder::decode(\r
- const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty\r
- ) const\r
-{\r
- if (!xmlObject)\r
- return NULL;\r
-\r
- Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder.XML");\r
-\r
- auto_ptr<XMLAttribute> attr(new XMLAttribute(ids));\r
- vector<string>& dest = attr->getValues();\r
-\r
- // Handle any non-Attribute object directly.\r
- if (!xmlObject || !XMLString::equals(saml1::Attribute::LOCAL_NAME, xmlObject->getElementQName().getLocalPart())) {\r
- DOMElement* e = xmlObject->getDOM();\r
- if (e) {\r
- if (log.isDebugEnabled()) {\r
- log.debug(\r
- "decoding XMLAttribute (%s) from XMLObject (%s)",\r
- ids.front().c_str(),\r
- (xmlObject->getSchemaType() ? xmlObject->getSchemaType()->toString() : xmlObject->getElementQName().toString()).c_str()\r
- );\r
- }\r
- dest.push_back(string());\r
- XMLHelper::serialize(e, dest.back());\r
- }\r
- else {\r
- log.warn("skipping XMLObject without a backing DOM");\r
- }\r
- return dest.empty() ? NULL : _decode(attr.release());\r
- }\r
-\r
- vector<XMLObject*>::const_iterator v,stop;\r
-\r
- const saml2::Attribute* saml2attr = dynamic_cast<const saml2::Attribute*>(xmlObject);\r
- if (saml2attr) {\r
- const vector<XMLObject*>& values = saml2attr->getAttributeValues();\r
- v = values.begin();\r
- stop = values.end();\r
- if (log.isDebugEnabled()) {\r
- auto_ptr_char n(saml2attr->getName());\r
- log.debug(\r
- "decoding XMLAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)",\r
- ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()\r
- );\r
- }\r
- }\r
- else {\r
- const saml1::Attribute* saml1attr = dynamic_cast<const saml1::Attribute*>(xmlObject);\r
- if (saml1attr) {\r
- const vector<XMLObject*>& values = saml1attr->getAttributeValues();\r
- v = values.begin();\r
- stop = values.end();\r
- if (log.isDebugEnabled()) {\r
- auto_ptr_char n(saml1attr->getAttributeName());\r
- log.debug(\r
- "decoding XMLAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)",\r
- ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()\r
- );\r
- }\r
- }\r
- else {\r
- log.warn("XMLObject type not recognized by XMLAttributeDecoder, no values returned");\r
- return NULL;\r
- }\r
- }\r
-\r
- for (; v!=stop; ++v) {\r
- DOMElement* e = (*v)->getDOM();\r
- if (e) {\r
- dest.push_back(string());\r
- XMLHelper::serialize(e, dest.back());\r
- }\r
- else\r
- log.warn("skipping AttributeValue without a backing DOM");\r
- }\r
-\r
- return dest.empty() ? NULL : _decode(attr.release());\r
-}\r
+/**
+ * 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.
+ */
+
+/**
+ * XMLAttributeDecoder.cpp
+ *
+ * Decodes arbitrary XML into an XMLAttribute.
+ */
+
+#include "internal.h"
+#include "attribute/AttributeDecoder.h"
+#include "attribute/XMLAttribute.h"
+
+#include <saml/saml1/core/Assertions.h>
+#include <saml/saml2/core/Assertions.h>
+#include <xmltooling/util/XMLHelper.h>
+
+using namespace shibsp;
+using namespace opensaml;
+using namespace xmltooling;
+using namespace std;
+
+namespace shibsp {
+ class SHIBSP_DLLLOCAL XMLAttributeDecoder : virtual public AttributeDecoder
+ {
+ public:
+ XMLAttributeDecoder(const DOMElement* e) : AttributeDecoder(e) {}
+ ~XMLAttributeDecoder() {}
+
+ // deprecated method
+ Attribute* decode(
+ const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=nullptr, const char* relyingParty=nullptr
+ ) const {
+ return decode(nullptr, ids, xmlObject, assertingParty, relyingParty);
+ }
+
+ Attribute* decode(
+ const GenericRequest*, const vector<string>&, const XMLObject*, const char* assertingParty=nullptr, const char* relyingParty=nullptr
+ ) const;
+
+ private:
+ DDF convert(DOMElement* e, bool nameit=true) const;
+ auto_ptr_char m_formatter;
+ map<pair<xstring,xstring>,string> m_tagMap;
+ };
+
+ AttributeDecoder* SHIBSP_DLLLOCAL XMLAttributeDecoderFactory(const DOMElement* const & e)
+ {
+ return new XMLAttributeDecoder(e);
+ }
+};
+
+
+Attribute* XMLAttributeDecoder::decode(
+ const GenericRequest* request, const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty
+ ) const
+{
+ if (!xmlObject)
+ return nullptr;
+
+ Category& log = Category::getInstance(SHIBSP_LOGCAT ".AttributeDecoder.XML");
+
+ auto_ptr<XMLAttribute> attr(new XMLAttribute(ids));
+ vector<string>& dest = attr->getValues();
+
+ // Handle any non-Attribute object directly.
+ if (!xmlObject || !XMLString::equals(saml1::Attribute::LOCAL_NAME, xmlObject->getElementQName().getLocalPart())) {
+ DOMElement* e = xmlObject->getDOM();
+ if (e) {
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "decoding XMLAttribute (%s) from XMLObject (%s)",
+ ids.front().c_str(),
+ (xmlObject->getSchemaType() ? xmlObject->getSchemaType()->toString() : xmlObject->getElementQName().toString()).c_str()
+ );
+ }
+ dest.push_back(string());
+ XMLHelper::serialize(e, dest.back());
+ }
+ else {
+ log.warn("skipping XMLObject without a backing DOM");
+ }
+ return dest.empty() ? nullptr : _decode(attr.release());
+ }
+
+ pair<vector<XMLObject*>::const_iterator,vector<XMLObject*>::const_iterator> valrange;
+
+ const saml2::Attribute* saml2attr = dynamic_cast<const saml2::Attribute*>(xmlObject);
+ if (saml2attr) {
+ const vector<XMLObject*>& values = saml2attr->getAttributeValues();
+ valrange = valueRange(request, values);
+ if (log.isDebugEnabled()) {
+ auto_ptr_char n(saml2attr->getName());
+ log.debug(
+ "decoding XMLAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)",
+ ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()
+ );
+ }
+ }
+ else {
+ const saml1::Attribute* saml1attr = dynamic_cast<const saml1::Attribute*>(xmlObject);
+ if (saml1attr) {
+ const vector<XMLObject*>& values = saml1attr->getAttributeValues();
+ valrange = valueRange(request, values);
+ if (log.isDebugEnabled()) {
+ auto_ptr_char n(saml1attr->getAttributeName());
+ log.debug(
+ "decoding XMLAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)",
+ ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()
+ );
+ }
+ }
+ else {
+ log.warn("XMLObject type not recognized by XMLAttributeDecoder, no values returned");
+ return nullptr;
+ }
+ }
+
+ for (; valrange.first != valrange.second; ++valrange.first) {
+ DOMElement* e = (*valrange.first)->getDOM();
+ if (e) {
+ dest.push_back(string());
+ XMLHelper::serialize(e, dest.back());
+ }
+ else
+ log.warn("skipping AttributeValue without a backing DOM");
+ }
+
+ return dest.empty() ? nullptr : _decode(attr.release());
+}