2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file shibsp/attribute/NameIDAttribute.h
20 * An Attribute whose values are relations of a value and a scope.
23 #ifndef __shibsp_nameidattr_h__
24 #define __shibsp_nameidattr_h__
26 #include <shibsp/attribute/Attribute.h>
27 #include <xmltooling/exceptions.h>
31 #if defined (_MSC_VER)
32 #pragma warning( push )
33 #pragma warning( disable : 4251 )
36 /** Default serialization format for NameIDs */
37 #define DEFAULT_NAMEID_FORMATTER "$Name!!$NameQualifier!!$SPNameQualifier"
40 * An Attribute whose values are derived from or mappable to a SAML NameID.
42 class SHIBSP_API NameIDAttribute : public Attribute
48 * @param id Attribute identifier
50 NameIDAttribute(const char* id, const char* formatter=DEFAULT_NAMEID_FORMATTER)
51 : Attribute(id), m_formatter(formatter) {
55 * Constructs based on a remoted NameIDAttribute.
57 * @param in input object containing marshalled NameIDAttribute
59 NameIDAttribute(DDF& in) : Attribute(in) {
61 DDF val = in.first().first();
63 m_values.push_back(Value());
64 Value& v = m_values.back();
65 v.m_Name = val.name();
66 pch = val["Format"].string();
69 pch = val["NameQualifier"].string();
71 v.m_NameQualifier = pch;
72 pch = val["SPNameQualifier"].string();
74 v.m_SPNameQualifier = pch;
75 pch = val["SPProvidedID"].string();
77 v.m_SPProvidedID = pch;
78 val = in.first().next();
82 virtual ~NameIDAttribute() {}
85 * Holds all the fields associated with a NameID.
87 struct SHIBSP_API Value
91 std::string m_NameQualifier;
92 std::string m_SPNameQualifier;
93 std::string m_SPProvidedID;
97 * Returns the set of values encoded as UTF-8 strings.
99 * <p>Each compound value is a pair containing the simple value and the scope.
101 * @return a mutable vector of the values
103 std::vector<Value>& getValues() {
107 size_t valueCount() const {
108 return m_values.size();
111 void clearSerializedValues() {
112 m_serialized.clear();
115 const std::vector<std::string>& getSerializedValues() const {
116 if (m_serialized.empty()) {
117 for (std::vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
118 // This is kind of a hack, but it's a good way to reuse some code.
119 xmltooling::XMLToolingException e(
121 xmltooling::namedparams(
123 "Name", i->m_Name.c_str(),
124 "Format", i->m_Format.c_str(),
125 "NameQualifier", i->m_NameQualifier.c_str(),
126 "SPNameQualifier", i->m_SPNameQualifier.c_str(),
127 "SPProvidedID", i->m_SPProvidedID.c_str()
130 m_serialized.push_back(e.what());
133 return Attribute::getSerializedValues();
136 DDF marshall() const {
137 DDF ddf = Attribute::marshall();
139 DDF vlist = ddf.first();
140 for (std::vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
141 DDF val = DDF(i->m_Name.c_str()).structure();
142 if (!i->m_Format.empty())
143 val.addmember("Format").string(i->m_Format.c_str());
144 if (!i->m_NameQualifier.empty())
145 val.addmember("NameQualifier").string(i->m_NameQualifier.c_str());
146 if (!i->m_SPNameQualifier.empty())
147 val.addmember("SPNameQualifier").string(i->m_SPNameQualifier.c_str());
148 if (!i->m_SPProvidedID.empty())
149 val.addmember("SPProvidedID").string(i->m_SPProvidedID.c_str());
156 std::vector<Value> m_values;
157 std::string m_formatter;
160 #if defined (_MSC_VER)
161 #pragma warning( pop )
166 #endif /* __shibsp_nameidattr_h__ */