ba44eeb985ccf154d89fb9b0931010ea6b2ef435
[shibboleth/cpp-sp.git] / shibsp / attribute / resolver / AttributeExtractor.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/resolver/AttributeExtractor.h
23  *
24  * A service that extracts and decodes attributes from XML objects.
25  */
26
27 #ifndef __shibsp_extractor_h__
28 #define __shibsp_extractor_h__
29
30 #include <shibsp/base.h>
31
32 #include <string>
33 #include <vector>
34 #include <xmltooling/Lockable.h>
35
36 namespace xmltooling {
37     class XMLTOOL_API XMLObject;
38 };
39
40 namespace opensaml {
41     namespace saml2md {
42         class SAML_API RoleDescriptor;
43         class SAML_API SPSSODescriptor;
44     };
45 };
46
47 namespace shibsp {
48
49     class SHIBSP_API Application;
50     class SHIBSP_API Attribute;
51
52     /**
53      * A service that extracts and decodes attributes from XML objects.
54      */
55     class SHIBSP_API AttributeExtractor : public virtual xmltooling::Lockable
56     {
57         MAKE_NONCOPYABLE(AttributeExtractor);
58     protected:
59         AttributeExtractor();
60     public:
61         virtual ~AttributeExtractor();
62
63         /**
64          * Extracts the attributes found in an XMLObject.
65          *
66          * @param application   Application performing the extraction
67          * @param issuer        source of object, if known
68          * @param xmlObject     object to extract
69          * @param attributes    an array to populate with the extracted attributes
70          *
71          * @throws AttributeExtractionException thrown if there is a problem extracting attributes
72          */
73         virtual void extractAttributes(
74             const Application& application,
75             const opensaml::saml2md::RoleDescriptor* issuer,
76             const xmltooling::XMLObject& xmlObject,
77             std::vector<Attribute*>& attributes
78             ) const=0;
79
80         /**
81          * Populates an array with the set of Attribute IDs that might be generated.
82          *
83          * @param attributes    array to populate
84          */
85         virtual void getAttributeIds(std::vector<std::string>& attributes) const=0;
86
87         /**
88          * Generates and/or modifies metadata reflecting the extractor,
89          * typically attribute-related requirements.
90          *
91          * <p>The default implementation does nothing.
92          *
93          * @param role          metadata role to decorate
94          */
95         virtual void generateMetadata(opensaml::saml2md::SPSSODescriptor& role) const;
96     };
97
98     /**
99      * Registers AttributeExtractor classes into the runtime.
100      */
101     void SHIBSP_API registerAttributeExtractors();
102
103     /** AttributeExtractor based on an XML mapping schema. */
104     #define XML_ATTRIBUTE_EXTRACTOR "XML"
105
106     /** AttributeExtractor for DelegationRestriction information. */
107     #define DELEGATION_ATTRIBUTE_EXTRACTOR "Delegation"
108
109     /** AttributeExtractor for KeyInfo information. */
110     #define KEYDESCRIPTOR_ATTRIBUTE_EXTRACTOR "KeyDescriptor"
111
112     /** AttributeExtractor based on chaining together other extractors. */
113     #define CHAINING_ATTRIBUTE_EXTRACTOR "Chaining"
114 };
115
116 #endif /* __shibsp_extractor_h__ */