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 /** Default serialization format for NameIDs */
32 #define DEFAULT_NAMEID_FORMATTER "$Name!!$NameQualifier!!$SPNameQualifier"
35 * An Attribute whose values are derived from or mappable to a SAML NameID.
37 class SHIBSP_API NameIDAttribute : public Attribute
43 * @param id Attribute identifier
45 NameIDAttribute(const char* id, const char* formatter=DEFAULT_NAMEID_FORMATTER)
46 : Attribute(id), m_formatter(formatter) {
49 virtual ~NameIDAttribute() {}
52 * Holds all the fields associated with a NameID.
54 struct SHIBSP_API Value
58 std::string m_NameQualifier;
59 std::string m_SPNameQualifier;
60 std::string m_SPProvidedID;
64 * Returns the set of values encoded as UTF-8 strings.
66 * <p>Each compound value is a pair containing the simple value and the scope.
68 * @return a mutable vector of the values
70 std::vector<Value>& getValues() {
74 size_t valueCount() const {
75 return m_values.size();
78 void clearSerializedValues() {
82 const std::vector<std::string>& getSerializedValues() const {
83 if (m_serialized.empty()) {
84 for (std::vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
85 // This is kind of a hack, but it's a good way to reuse some code.
86 xmltooling::XMLToolingException e(
88 xmltooling::namedparams(
91 "Format", i->m_Format,
92 "NameQualifier", i->m_NameQualifier,
93 "SPNameQualifier", i->m_SPNameQualifier,
94 "SPProvidedID", i->m_SPProvidedID
97 m_serialized.push_back(e.what());
100 return Attribute::getSerializedValues();
103 DDF marshall() const {
104 DDF ddf = Attribute::marshall();
105 ddf.name("NameIDAttribute");
106 DDF vlist = ddf.addmember("values").list();
107 for (std::vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
108 DDF val = DDF(NULL).structure();
109 val.addmember("Name").string(i->m_Name.c_str());
110 if (!i->m_Format.empty())
111 val.addmember("Format").string(i->m_Format.c_str());
112 if (!i->m_NameQualifier.empty())
113 val.addmember("NameQualifier").string(i->m_NameQualifier.c_str());
114 if (!i->m_SPNameQualifier.empty())
115 val.addmember("SPNameQualifier").string(i->m_SPNameQualifier.c_str());
116 if (!i->m_SPProvidedID.empty())
117 val.addmember("SPProvidedID").string(i->m_SPProvidedID.c_str());
124 std::vector<Value> m_values;
125 std::string m_formatter;
130 #endif /* __shibsp_nameidattr_h__ */