Imported Upstream version 2.2.1+dfsg
[shibboleth/sp.git] / shibsp / attribute / AttributeDecoder.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/AttributeDecoder.h
19  *
20  * Decodes SAML NameID/Attribute objects into resolved Attributes.
21  */
22
23 #ifndef __shibsp_attrdecoder_h__
24 #define __shibsp_attrdecoder_h__
25
26 #include <shibsp/attribute/Attribute.h>
27 #include <xmltooling/XMLObject.h>
28
29 namespace shibsp {
30
31     /**
32      * Decodes XML objects into resolved Attributes.
33      */
34     class SHIBSP_API AttributeDecoder
35     {
36         MAKE_NONCOPYABLE(AttributeDecoder);
37     protected:
38         /**
39          * Constructor.
40          *
41          * @param e root of DOM to configure the decoder
42          */
43         AttributeDecoder(const xercesc::DOMElement* e);
44
45         /** Flag for case sensitivity of decoded attributes. */
46         bool m_caseSensitive;
47
48         /** Flag for hiding attributes from CGI export. */
49         bool m_internal;
50
51         /**
52          * Helper method to handle base class decoding housekeeping.
53          *
54          * @param attr  the new Attribute object being created
55          * @return  the attr parameter
56          */
57         virtual Attribute* _decode(Attribute* attr) const {
58             attr->setCaseSensitive(m_caseSensitive);
59             attr->setInternal(m_internal);
60             return attr;
61         }
62
63     public:
64         virtual ~AttributeDecoder() {}
65
66         /**
67          * Decodes an XMLObject into a resolved Attribute.
68          *
69          * @param ids               array containing primary identifier in first position, followed by any aliases
70          * @param xmlObject         XMLObject to decode
71          * @param assertingParty    name of the party asserting the attribute
72          * @param relyingParty      name of the party relying on the attribute
73          * @return a resolved Attribute, or NULL
74          */
75         virtual Attribute* decode(
76             const std::vector<std::string>& ids,
77             const xmltooling::XMLObject* xmlObject,
78             const char* assertingParty=NULL,
79             const char* relyingParty=NULL
80             ) const=0;
81     };
82
83
84     /** Decodes into a SimpleAttribute. */
85     extern SHIBSP_API xmltooling::QName StringAttributeDecoderType;
86
87     /** Decodes scoped and NameID attributes into a ScopedAttribute. */
88     extern SHIBSP_API xmltooling::QName ScopedAttributeDecoderType;
89
90     /** Decodes NameID information into a NameIDAttribute. */
91     extern SHIBSP_API xmltooling::QName NameIDAttributeDecoderType;
92
93     /** Decodes scoped attributes into a NameIDAttribute. */
94     extern SHIBSP_API xmltooling::QName NameIDFromScopedAttributeDecoderType;
95
96     /** Decodes KeyInfo information into a SimpleAttribute. */
97     extern SHIBSP_API xmltooling::QName KeyInfoAttributeDecoderType;
98
99     /** Decodes arbitrary DOM information into an ExtensibleAttribute. */
100     extern SHIBSP_API xmltooling::QName DOMAttributeDecoderType;
101
102     /** Decodes arbitrary XML into an XMLAttribute. */
103     extern SHIBSP_API xmltooling::QName XMLAttributeDecoderType;
104
105     /** Registers built-in AttributeDecoders into the runtime. */
106     void registerAttributeDecoders();
107 };
108
109 #endif /* __shibsp_attrdecoder_h__ */