Imported Upstream version 2.3+dfsg
[shibboleth/sp.git] / shibsp / attribute / NameIDAttribute.h
1 /*
2  *  Copyright 2001-2009 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file shibsp/attribute/NameIDAttribute.h
19  * 
20  * An Attribute whose values are derived from or mappable to a SAML NameID.
21  */
22
23 #ifndef __shibsp_nameidattr_h__
24 #define __shibsp_nameidattr_h__
25
26 #include <shibsp/attribute/Attribute.h>
27
28 namespace shibsp {
29
30 #if defined (_MSC_VER)
31     #pragma warning( push )
32     #pragma warning( disable : 4251 )
33 #endif
34
35     /** Default serialization format for NameIDs */
36     #define DEFAULT_NAMEID_FORMATTER    "$Name!!$NameQualifier!!$SPNameQualifier"
37
38     /**
39      * An Attribute whose values are derived from or mappable to a SAML NameID.
40      */
41     class SHIBSP_API NameIDAttribute : public Attribute
42     {
43     public:
44         /**
45          * Constructor.
46          * 
47          * @param ids       array with primary identifier in first position, followed by any aliases
48          * @param formatter template for serialization of tuple
49          */
50         NameIDAttribute(const std::vector<std::string>& ids, const char* formatter=DEFAULT_NAMEID_FORMATTER);
51
52         /**
53          * Constructs based on a remoted NameIDAttribute.
54          * 
55          * @param in    input object containing marshalled NameIDAttribute
56          */
57         NameIDAttribute(DDF& in);
58         
59         virtual ~NameIDAttribute();
60         
61         /**
62          * Holds all the fields associated with a NameID.
63          */
64         struct SHIBSP_API Value
65         {
66             std::string m_Name;
67             std::string m_Format;
68             std::string m_NameQualifier;
69             std::string m_SPNameQualifier;
70             std::string m_SPProvidedID;
71         };
72         
73         /**
74          * Returns the set of values encoded as UTF-8 strings.
75          * 
76          * @return  a mutable vector of the values
77          */
78         std::vector<Value>& getValues();
79
80         /**
81          * Returns the set of values encoded as UTF-8 strings.
82          * 
83          * @return  an immutable vector of the values
84          */
85         const std::vector<Value>& getValues() const;
86
87         // Virtual function overrides.
88         size_t valueCount() const;
89         void clearSerializedValues();
90         const char* getString(size_t index) const;
91         const char* getScope(size_t index) const;
92         void removeValue(size_t index);
93         const std::vector<std::string>& getSerializedValues() const;
94         DDF marshall() const;
95     
96     private:
97         std::vector<Value> m_values;
98         std::string m_formatter;
99     };
100
101 #if defined (_MSC_VER)
102     #pragma warning( pop )
103 #endif
104
105 };
106
107 #endif /* __shibsp_nameidattr_h__ */