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.
22 * @file shibsp/attribute/Attribute.h
24 * A resolved attribute.
27 #ifndef __shibsp_attribute_h__
28 #define __shibsp_attribute_h__
30 #include <shibsp/remoting/ddf.h>
38 #if defined (_MSC_VER)
39 #pragma warning( push )
40 #pragma warning( disable : 4251 )
44 * A resolved attribute.
46 * <p>Resolved attributes are a neutral construct that represent both simple and
47 * complex attribute data structures that might be found in SAML assertions
48 * or obtained from other sources.
50 * <p>Attributes consist of an id/name that is locally unique (that is, unique to a
51 * configuration at any given point in time) and zero or more values. Values can
52 * be of any type or structure, but will generally be made available to applications
53 * only if a serialized string form exists. More complex values can be used with
54 * access control plugins and other components that understand them, however.
56 class SHIBSP_API Attribute
58 MAKE_NONCOPYABLE(Attribute);
63 * @param ids array with primary identifier in first position, followed by any aliases
65 Attribute(const std::vector<std::string>& ids);
68 * Constructs based on a remoted Attribute.
70 * <p>This allows Attribute objects to be recreated after marshalling.
71 * The DDF supplied must be a struct containing a single list member named
72 * with the Attribute's "id" and containing the values.
74 * @param in input object containing marshalled Attribute
79 * Maintains a copy of serialized attribute values, when possible.
81 * <p>Implementations should maintain the array when values are added or removed.
83 mutable std::vector<std::string> m_serialized;
89 * Returns the Attribute identifier.
91 * @return the Attribute identifier
93 const char* getId() const;
96 * Returns all of the effective names for the Attribute.
98 * @return immutable array of identifiers, with the primary ID in the first position
100 const std::vector<std::string>& getAliases() const;
103 * Returns all of the effective names for the Attribute.
105 * @return mutable array of identifiers, with the primary ID in the first position
107 std::vector<std::string>& getAliases();
110 * Sets whether case sensitivity should apply to basic value comparisons.
112 * @param caseSensitive true iff value comparisons should be case sensitive
114 void setCaseSensitive(bool caseSensitive);
117 * Sets whether the attribute should be exported for CGI use.
119 * @param internal true iff the attribute should <strong>NOT</strong> be exported
121 void setInternal(bool internal);
124 * Indicates whether case sensitivity should apply to basic value comparisons.
126 * @return true iff value comparisons should be case sensitive
128 bool isCaseSensitive() const;
131 * Indicates whether the attribute should be exported for CGI use.
133 * @return true iff the attribute should <strong>NOT</strong> be exported
135 bool isInternal() const;
138 * Returns the number of values.
140 * @return number of values
142 virtual size_t valueCount() const;
145 * Returns serialized Attribute values encoded as UTF-8 strings.
147 * @return an immutable vector of values
149 virtual const std::vector<std::string>& getSerializedValues() const;
152 * Informs the Attribute that values have changed and any serializations
155 virtual void clearSerializedValues()=0;
158 * Gets the string equivalent of the value at the specified position (starting from zero).
160 * @param index position of value
161 * @return the specified value in its "string" form, or nullptr if undefined
163 virtual const char* getString(size_t index) const;
166 * Gets the "scope" of the value at the specified position (starting from zero).
168 * @param index position of value
169 * @return the specified value's "scope", or nullptr if attribute is unscoped
171 virtual const char* getScope(size_t index) const;
174 * Removes the value at the specified position (starting from zero).
176 * @param index position of value to remove
178 virtual void removeValue(size_t index);
181 * Marshalls an Attribute for remoting.
183 * <p>This allows Attribute objects to be communicated across process boundaries
184 * without excess XML parsing. The DDF returned must be a struct containing
185 * a single list member named with the Attribute's "id". The name of the struct
186 * should contain the registered name of the Attribute implementation.
188 virtual DDF marshall() const;
191 * Unmarshalls a remoted Attribute.
193 * @param in remoted Attribute data
194 * @return a resolved Attribute of the proper subclass
196 static Attribute* unmarshall(DDF& in);
198 /** A function that unmarshalls remoted data into the proper Attribute subclass. */
199 typedef Attribute* AttributeFactory(DDF& in);
202 * Registers an AttributeFactory function for a given attribute "type".
204 * @param type string used at the root of remoted Attribute structures
205 * @param factory factory function
207 static void registerFactory(const char* type, AttributeFactory* factory);
210 * Deregisters an AttributeFactory function for a given attribute "type".
212 * @param type string used at the root of remoted Attribute structures
214 static void deregisterFactory(const char* type);
217 * Clears the map of factories.
219 static void deregisterFactories();
222 static std::map<std::string,AttributeFactory*> m_factoryMap;
223 std::vector<std::string> m_id;
224 bool m_caseSensitive,m_internal;
227 #if defined (_MSC_VER)
228 #pragma warning( pop )
231 /** Registers built-in Attribute types into the runtime. */
232 void registerAttributeFactories();
236 #endif /* __shibsp_attribute_h__ */