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