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.
24 * An Attribute whose values are derived from or mappable to a SAML NameID.
28 #include "attribute/NameIDAttribute.h"
30 #include <xmltooling/exceptions.h>
32 using namespace shibsp;
33 using namespace xmltooling;
37 SHIBSP_DLLLOCAL Attribute* NameIDAttributeFactory(DDF& in) {
38 return new NameIDAttribute(in);
42 NameIDAttribute::NameIDAttribute(const vector<string>& ids, const char* formatter) : Attribute(ids), m_formatter(formatter)
46 NameIDAttribute::NameIDAttribute(DDF& in) : Attribute(in)
48 DDF val = in["_formatter"];
50 m_formatter = val.string();
52 m_formatter = DEFAULT_NAMEID_FORMATTER;
54 val = in.first().first();
56 m_values.push_back(Value());
57 Value& v = m_values.back();
58 v.m_Name = val.name();
59 pch = val["Format"].string();
62 pch = val["NameQualifier"].string();
64 v.m_NameQualifier = pch;
65 pch = val["SPNameQualifier"].string();
67 v.m_SPNameQualifier = pch;
68 pch = val["SPProvidedID"].string();
70 v.m_SPProvidedID = pch;
71 val = in.first().next();
75 NameIDAttribute::~NameIDAttribute()
79 vector<NameIDAttribute::Value>& NameIDAttribute::getValues()
84 const vector<NameIDAttribute::Value>& NameIDAttribute::getValues() const
89 size_t NameIDAttribute::valueCount() const
91 return m_values.size();
94 void NameIDAttribute::clearSerializedValues()
99 const char* NameIDAttribute::getString(size_t index) const
101 return m_values[index].m_Name.c_str();
104 const char* NameIDAttribute::getScope(size_t index) const
106 return m_values[index].m_NameQualifier.c_str();
109 void NameIDAttribute::removeValue(size_t index)
111 Attribute::removeValue(index);
112 if (index < m_values.size())
113 m_values.erase(m_values.begin() + index);
116 const vector<string>& NameIDAttribute::getSerializedValues() const
118 if (m_serialized.empty()) {
119 for (vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
120 // This is kind of a hack, but it's a good way to reuse some code.
121 XMLToolingException e(
125 "Name", i->m_Name.c_str(),
126 "Format", i->m_Format.c_str(),
127 "NameQualifier", i->m_NameQualifier.c_str(),
128 "SPNameQualifier", i->m_SPNameQualifier.c_str(),
129 "SPProvidedID", i->m_SPProvidedID.c_str()
132 m_serialized.push_back(e.what());
135 return Attribute::getSerializedValues();
138 DDF NameIDAttribute::marshall() const
140 DDF ddf = Attribute::marshall();
142 ddf.addmember("_formatter").string(m_formatter.c_str());
143 DDF vlist = ddf.first();
144 for (vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
145 DDF val = DDF(i->m_Name.c_str()).structure();
146 if (!i->m_Format.empty())
147 val.addmember("Format").string(i->m_Format.c_str());
148 if (!i->m_NameQualifier.empty())
149 val.addmember("NameQualifier").string(i->m_NameQualifier.c_str());
150 if (!i->m_SPNameQualifier.empty())
151 val.addmember("SPNameQualifier").string(i->m_SPNameQualifier.c_str());
152 if (!i->m_SPProvidedID.empty())
153 val.addmember("SPProvidedID").string(i->m_SPProvidedID.c_str());