2 * Copyright 2001-2009 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * StringAttributeDecoder.cpp
\r
20 * Decodes SAML into SimpleAttributes
\r
23 #include "internal.h"
\r
24 #include "attribute/AttributeDecoder.h"
\r
25 #include "attribute/SimpleAttribute.h"
\r
27 #include <saml/saml1/core/Assertions.h>
\r
28 #include <saml/saml2/core/Assertions.h>
\r
30 using namespace shibsp;
\r
31 using namespace opensaml::saml1;
\r
32 using namespace opensaml::saml2;
\r
33 using namespace xmltooling;
\r
34 using namespace std;
\r
37 class SHIBSP_DLLLOCAL StringAttributeDecoder : virtual public AttributeDecoder
\r
40 StringAttributeDecoder(const DOMElement* e) : AttributeDecoder(e) {}
\r
41 ~StringAttributeDecoder() {}
\r
43 shibsp::Attribute* decode(
\r
44 const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=NULL, const char* relyingParty=NULL
\r
48 AttributeDecoder* SHIBSP_DLLLOCAL StringAttributeDecoderFactory(const DOMElement* const & e)
\r
50 return new StringAttributeDecoder(e);
\r
54 shibsp::Attribute* StringAttributeDecoder::decode(
\r
55 const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty
\r
59 auto_ptr<SimpleAttribute> simple(new SimpleAttribute(ids));
\r
60 vector<string>& dest = simple->getValues();
\r
61 vector<XMLObject*>::const_iterator v,stop;
\r
63 Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder.String");
\r
65 if (xmlObject && XMLString::equals(opensaml::saml1::Attribute::LOCAL_NAME,xmlObject->getElementQName().getLocalPart())) {
\r
66 const opensaml::saml2::Attribute* saml2attr = dynamic_cast<const opensaml::saml2::Attribute*>(xmlObject);
\r
68 const vector<XMLObject*>& values = saml2attr->getAttributeValues();
\r
70 stop = values.end();
\r
71 if (log.isDebugEnabled()) {
\r
72 auto_ptr_char n(saml2attr->getName());
\r
74 "decoding SimpleAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)",
\r
75 ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()
\r
80 const opensaml::saml1::Attribute* saml1attr = dynamic_cast<const opensaml::saml1::Attribute*>(xmlObject);
\r
82 const vector<XMLObject*>& values = saml1attr->getAttributeValues();
\r
84 stop = values.end();
\r
85 if (log.isDebugEnabled()) {
\r
86 auto_ptr_char n(saml1attr->getAttributeName());
\r
88 "decoding SimpleAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)",
\r
89 ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()
\r
94 log.warn("XMLObject type not recognized by StringAttributeDecoder, no values returned");
\r
99 for (; v!=stop; ++v) {
\r
100 if (!(*v)->hasChildren()) {
\r
101 val = toUTF8((*v)->getTextContent());
\r
103 dest.push_back(val);
\r
105 log.warn("skipping empty AttributeValue");
\r
109 log.warn("skipping complex AttributeValue");
\r
113 return dest.empty() ? NULL : _decode(simple.release());
\r
116 const NameID* saml2name = dynamic_cast<const NameID*>(xmlObject);
\r
118 if (log.isDebugEnabled()) {
\r
119 auto_ptr_char f(saml2name->getFormat());
\r
120 log.debug("decoding SimpleAttribute (%s) from SAML 2 NameID with Format (%s)", ids.front().c_str(), f.get() ? f.get() : "unspecified");
\r
122 val = toUTF8(saml2name->getName());
\r
125 const NameIdentifier* saml1name = dynamic_cast<const NameIdentifier*>(xmlObject);
\r
127 if (log.isDebugEnabled()) {
\r
128 auto_ptr_char f(saml1name->getFormat());
\r
130 "decoding SimpleAttribute (%s) from SAML 1 NameIdentifier with Format (%s)",
\r
131 ids.front().c_str(), f.get() ? f.get() : "unspecified"
\r
134 val = toUTF8(saml1name->getName());
\r
137 log.warn("XMLObject type not recognized by StringAttributeDecoder, no values returned");
\r
143 dest.push_back(val);
\r
145 log.warn("ignoring empty NameID");
\r
147 return dest.empty() ? NULL : _decode(simple.release());
\r