Use shibboleth-sp as package name for compatibility.
[shibboleth/cpp-sp.git] / shibsp / attribute / AttributeDecoder.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/AttributeDecoder.h
23  *
24  * Decodes SAML NameID/Attribute objects into resolved Attributes.
25  */
26
27 #ifndef __shibsp_attrdecoder_h__
28 #define __shibsp_attrdecoder_h__
29
30 #include <shibsp/base.h>
31
32 #include <string>
33 #include <vector>
34
35 namespace xmltooling {
36     class XMLTOOL_API GenericRequest;
37     class XMLTOOL_API QName;
38     class XMLTOOL_API XMLObject;
39 };
40
41 namespace shibsp {
42
43     class SHIBSP_API Attribute;
44
45     /**
46      * Decodes XML objects into resolved Attributes.
47      */
48     class SHIBSP_API AttributeDecoder
49     {
50         MAKE_NONCOPYABLE(AttributeDecoder);
51     protected:
52         /**
53          * Constructor.
54          *
55          * @param e root of DOM to configure the decoder
56          */
57         AttributeDecoder(const xercesc::DOMElement* e);
58
59         /** Flag for case sensitivity of decoded attributes. */
60         bool m_caseSensitive;
61
62         /** Flag for hiding attributes from CGI export. */
63         bool m_internal;
64
65         /** Flag for language aware decoding. */
66         bool m_langAware;
67
68         /** Hash algorithm to apply to decoded values. */
69         std::string m_hashAlg;
70
71         /**
72          * Helper method to handle base class decoding housekeeping.
73          *
74          * @param attr  the new Attribute object being created
75          * @return  the attr parameter
76          */
77         virtual Attribute* _decode(Attribute* attr) const;
78
79         /**
80          * Helper method that returns a range of objects the decoder should operate on,
81          * based on the language settings of the decoder and the client request.
82          *
83          * @param request   the client request, if any
84          * @param objects   the objects to examine
85          * @return  a pair of iterators representing the range of objects to examine
86          */
87         virtual std::pair<std::vector<xmltooling::XMLObject*>::const_iterator,std::vector<xmltooling::XMLObject*>::const_iterator> valueRange(
88             const xmltooling::GenericRequest* request, const std::vector<xmltooling::XMLObject*>& objects
89             ) const;
90
91     public:
92         virtual ~AttributeDecoder();
93
94         /**
95          * Decodes an XMLObject into a resolved Attribute.
96          *
97          * @param request           request triggering the decode, if any
98          * @param ids               array containing primary identifier in first position, followed by any aliases
99          * @param xmlObject         XMLObject to decode
100          * @param assertingParty    name of the party asserting the attribute
101          * @param relyingParty      name of the party relying on the attribute
102          * @return a resolved Attribute, or nullptr
103          */
104         virtual Attribute* decode(
105             const xmltooling::GenericRequest* request,
106             const std::vector<std::string>& ids,
107             const xmltooling::XMLObject* xmlObject,
108             const char* assertingParty=nullptr,
109             const char* relyingParty=nullptr
110             ) const;
111
112         /**
113          * @deprecated
114          * Decodes an XMLObject into a resolved Attribute.
115          *
116          * @param ids               array containing primary identifier in first position, followed by any aliases
117          * @param xmlObject         XMLObject to decode
118          * @param assertingParty    name of the party asserting the attribute
119          * @param relyingParty      name of the party relying on the attribute
120          * @return a resolved Attribute, or nullptr
121          */
122         virtual Attribute* decode(
123             const std::vector<std::string>& ids,
124             const xmltooling::XMLObject* xmlObject,
125             const char* assertingParty=nullptr,
126             const char* relyingParty=nullptr
127             ) const;
128     };
129
130
131     /** Decodes into a SimpleAttribute. */
132     extern SHIBSP_API xmltooling::QName StringAttributeDecoderType;
133
134     /** Decodes scoped and NameID attributes into a ScopedAttribute. */
135     extern SHIBSP_API xmltooling::QName ScopedAttributeDecoderType;
136
137     /** Decodes NameID information into a NameIDAttribute. */
138     extern SHIBSP_API xmltooling::QName NameIDAttributeDecoderType;
139
140     /** Decodes scoped attributes into a NameIDAttribute. */
141     extern SHIBSP_API xmltooling::QName NameIDFromScopedAttributeDecoderType;
142
143     /** Decodes KeyInfo information into a SimpleAttribute. */
144     extern SHIBSP_API xmltooling::QName KeyInfoAttributeDecoderType;
145
146     /** Decodes arbitrary DOM information into an ExtensibleAttribute. */
147     extern SHIBSP_API xmltooling::QName DOMAttributeDecoderType;
148
149     /** Decodes arbitrary XML into an XMLAttribute. */
150     extern SHIBSP_API xmltooling::QName XMLAttributeDecoderType;
151
152     /** Decodes base64-encoded data into a SimpleAttribute. */
153     extern SHIBSP_API xmltooling::QName Base64AttributeDecoderType;
154
155     /** Registers built-in AttributeDecoders into the runtime. */
156     void registerAttributeDecoders();
157 };
158
159 #endif /* __shibsp_attrdecoder_h__ */