More work on SAML code
[mech_eap.git] / resolver.h
1 /*
2  *  Copyright 2010 Project Moonshot
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 shibresolver/resolver.h
19  *
20  * An embeddable component interface to Shibboleth SP attribute processing.
21  */
22
23 #ifndef __shibresolver_h__
24 #define __shibresolver_h__
25
26 #if 0
27 #include <shibresolver/base.h>
28 #else
29 #define SHIBRESOLVER_API SHIBSP_API
30 #endif
31
32 #include <string>
33 #include <vector>
34
35 namespace xmltooling {
36     class XMLTOOL_API XMLObject;
37 };
38
39 namespace opensaml {
40     namespace saml2 {
41         class SAML_API Assertion;
42         class SAML_API NameID;
43     };
44 };
45
46 namespace shibsp {
47     class SHIBSP_API Attribute;
48 };
49
50 namespace shibresolver {
51
52 #if defined (_MSC_VER)
53     #pragma warning( push )
54     #pragma warning( disable : 4250 4251 )
55 #endif
56
57     /**
58      * An embeddable component interface to Shibboleth SP attribute processing.
59      */
60     class SHIBRESOLVER_API ShibbolethResolver
61     {
62         MAKE_NONCOPYABLE(ShibbolethResolver);
63     protected:
64         ShibbolethResolver() {}
65     public:
66         ~ShibbolethResolver() {}
67
68         /**
69          * Sets the application ID to use for resolution.
70          *
71          * @param appID identifies an application in the SP configuration
72          */
73         void setApplicationID(const char* appID) {}
74
75         /**
76          * Sets the identity issuer to use for resolution.
77          *
78          * @param issuer    entityID of the identity "source", if known
79          */
80         void setIssuer(const char* issuer) {}
81
82         /**
83          * Adds a SAML token as input to the resolver.
84          * <p>The caller retains ownership of the object.
85          *
86          * @param token an input token to evaluate
87          */
88         void addToken(
89 #ifdef SHIBSP_LITE
90             const xmltooling::XMLObject* token
91 #else
92             const opensaml::saml2::Assertion* token
93 #endif
94             ) {}
95
96         /**
97          * Adds an Attribute as input to the resolver.
98          * <p>The caller retains ownership of the object, but it MAY be modified
99          * during the resolution process.
100          *
101          * @param attr  an input attribute
102          */
103         void addAttribute(shibsp::Attribute* attr) {}
104
105         /**
106          * Resolves attributes and returns them in the supplied array.
107          * <p>The caller is responsible for freeing them.
108          *
109          * @param attrs array to populate
110          */
111         void resolveAttributes(std::vector<shibsp::Attribute*>& attrs) {}
112
113         /**
114          * Initializes SP runtime objects based on an XML configuration string or a configuration pathname.
115          * <p>Each process using the library MUST call this function exactly once before using any library classes.
116          *
117          * @param config    a snippet of XML to parse (it <strong>MUST</strong> contain a type attribute) or a pathname
118          * @param rethrow   true iff caught exceptions should be rethrown instead of just returning the status
119          * @return true iff initialization was successful
120          */
121         static bool init(const char* config=NULL, bool rethrow=false) { return true; }
122
123         /**
124          * Shuts down runtime.
125          *
126          * Each process using the library SHOULD call this function exactly once before terminating itself.
127          */
128         static void term() {}
129
130         /**
131          * Returns a ShibbolethResolver instance.
132          *
133          * @return  a ShibbolethResolver instance, must be freed by the caller.
134          */
135         static ShibbolethResolver* create() { return new ShibbolethResolver(); }
136
137     protected:
138         /** Application ID. */
139         std::string m_appID;
140
141         /** Source of identity, if known. */
142         std::string m_issuer;
143
144         /** Input tokens. */
145 #ifdef SHIBSP_LITE
146         std::vector<const xmltooling::XMLObject*> m_tokens;
147 #else
148         std::vector<const opensaml::saml2::Assertion*> m_tokens;
149 #endif
150         /** Input attributes. */
151         std::vector<shibsp::Attribute*> m_attributes;
152     };
153
154 #if defined (_MSC_VER)
155     #pragma warning( pop )
156 #endif
157
158 };
159
160 #endif /* __shibresolver_h__ */