2 * Copyright 2001-2007 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 * SimpleAttributeDecoder.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 <log4cpp/Category.hh>
\r
28 #include <saml/saml1/core/Assertions.h>
\r
29 #include <saml/saml2/core/Assertions.h>
\r
31 using namespace shibsp;
\r
32 using namespace opensaml::saml1;
\r
33 using namespace opensaml::saml2;
\r
34 using namespace xmltooling;
\r
35 using namespace log4cpp;
\r
36 using namespace std;
\r
39 class SHIBSP_DLLLOCAL SimpleAttributeDecoder : virtual public AttributeDecoder
\r
42 SimpleAttributeDecoder(const DOMElement* e) {}
\r
43 ~SimpleAttributeDecoder() {}
\r
45 shibsp::Attribute* decode(
\r
46 const char* id, const XMLObject* xmlObject, const char* assertingParty=NULL, const char* relyingParty=NULL
\r
50 AttributeDecoder* SHIBSP_DLLLOCAL SimpleAttributeDecoderFactory(const DOMElement* const & e)
\r
52 return new SimpleAttributeDecoder(e);
\r
56 shibsp::Attribute* SimpleAttributeDecoder::decode(
\r
57 const char* id, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty
\r
61 auto_ptr<SimpleAttribute> simple(new SimpleAttribute(id));
\r
62 vector<string>& dest = simple->getValues();
\r
63 vector<XMLObject*>::const_iterator v,stop;
\r
65 Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder");
\r
67 if (xmlObject && XMLString::equals(opensaml::saml1::Attribute::LOCAL_NAME,xmlObject->getElementQName().getLocalPart())) {
\r
68 const opensaml::saml2::Attribute* saml2attr = dynamic_cast<const opensaml::saml2::Attribute*>(xmlObject);
\r
70 const vector<XMLObject*>& values = saml2attr->getAttributeValues();
\r
72 stop = values.end();
\r
73 if (log.isDebugEnabled()) {
\r
74 auto_ptr_char n(saml2attr->getName());
\r
75 log.debug("decoding SimpleAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)", id, n.get() ? n.get() : "unnamed", values.size());
\r
79 const opensaml::saml1::Attribute* saml1attr = dynamic_cast<const opensaml::saml1::Attribute*>(xmlObject);
\r
81 const vector<XMLObject*>& values = saml1attr->getAttributeValues();
\r
83 stop = values.end();
\r
84 if (log.isDebugEnabled()) {
\r
85 auto_ptr_char n(saml1attr->getAttributeName());
\r
86 log.debug("decoding SimpleAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)", id, n.get() ? n.get() : "unnamed", values.size());
\r
90 log.warn("XMLObject type not recognized by SimpleAttributeDecoder, no values returned");
\r
95 for (; v!=stop; ++v) {
\r
96 if (!(*v)->hasChildren()) {
\r
97 val = toUTF8((*v)->getTextContent());
\r
99 dest.push_back(val);
\r
101 log.warn("skipping empty AttributeValue");
\r
105 log.warn("skipping complex AttributeValue");
\r
109 return dest.empty() ? NULL : simple.release();
\r
112 const NameID* saml2name = dynamic_cast<const NameID*>(xmlObject);
\r
114 if (log.isDebugEnabled()) {
\r
115 auto_ptr_char f(saml2name->getFormat());
\r
116 log.debug("decoding SimpleAttribute (%s) from SAML 2 NameID with Format (%s)", id, f.get() ? f.get() : "unspecified");
\r
118 val = toUTF8(saml2name->getName());
\r
121 const NameIdentifier* saml1name = dynamic_cast<const NameIdentifier*>(xmlObject);
\r
123 if (log.isDebugEnabled()) {
\r
124 auto_ptr_char f(saml1name->getFormat());
\r
125 log.debug("decoding SimpleAttribute (%s) from SAML 1 NameIdentifier with Format (%s)", id, f.get() ? f.get() : "unspecified");
\r
127 val = toUTF8(saml1name->getName());
\r
130 log.warn("XMLObject type not recognized by SimpleAttributeDecoder, no values returned");
\r
136 dest.push_back(val);
\r
138 log.warn("ignoring empty NameID");
\r
140 return dest.empty() ? NULL : simple.release();
\r