7ae16342f883fafd26f7b555455d2d982b2f92b6
[shibboleth/cpp-sp-resolver.git] / src / shibresolver / resolver.h
1 /*
2  *  Copyright 2010-2011 JANET(UK)
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 #include <shibresolver/base.h>
27
28 #include <shibsp/RequestMapper.h>
29 #include <shibsp/SPConfig.h>
30
31 #include <string>
32 #include <vector>
33
34 #ifdef SHIBRESOLVER_HAVE_GSSGNU
35 # include <gss.h>
36 #elif defined SHIBRESOLVER_HAVE_GSSMIT
37 # include <gssapi/gssapi.h>
38 # include <gssapi/gssapi_generic.h>
39 #else
40 # include <gssapi.h>
41 #endif
42
43 namespace xmltooling {
44     class XMLTOOL_API XMLObject;
45 };
46
47 namespace shibsp {
48     class SHIBSP_API Attribute;
49     class SHIBSP_API SPRequest;
50 };
51
52 namespace shibresolver {
53
54 #if defined (_MSC_VER)
55     #pragma warning( push )
56     #pragma warning( disable : 4250 4251 )
57 #endif
58
59     /**
60      * An embeddable component interface to Shibboleth SP attribute processing.
61      */
62     class SHIBRESOLVER_API ShibbolethResolver
63     {
64         MAKE_NONCOPYABLE(ShibbolethResolver);
65     protected:
66         ShibbolethResolver();
67     public:
68         virtual ~ShibbolethResolver();
69
70         /**
71          * Sets the calling service request, making the Shibboleth SP responsible for
72          * mapping the service to an Application instance.
73          *
74          * @param request identifies the service request performing attribute resolution
75          */
76         void setRequest(const shibsp::SPRequest* request);
77
78         /**
79          * Sets the application ID to use for resolution, bypassing the mapping
80          * function of the Shibboleth SP.
81          *
82          * @param appID identifies an application in the SP configuration
83          */
84         void setApplicationID(const char* appID);
85
86         /**
87          * Sets the identity issuer to use for resolution.
88          *
89          * @param issuer    entityID of the identity "source", if known
90          */
91         void setIssuer(const char* issuer);
92
93         /**
94          * Adds an XML token as input to the resolver, generally a SAML assertion.
95          * <p>The caller retains ownership of the object.
96          *
97          * @param token an input token to evaluate
98          */
99         void addToken(const xmltooling::XMLObject* token);
100
101 #ifdef SHIBRESOLVER_HAVE_GSSAPI
102         /**
103          * Adds a GSS-API security context as input to the resolver.
104          * <p>The caller loses ownership of the context.
105          *
106          * @param ctx an input context to evaluate
107          */
108         void addToken(gss_ctx_id_t* ctx);
109
110         /**
111          * Adds a GSS-API exported security context as input to
112          * the resolver.
113          * <p>The caller retains ownership of the buffer.
114          *
115          * @param ctx an input exported security context to evaluate
116          */
117         void addToken(gss_buffer_t token);
118 #endif
119
120         /**
121          * Adds an Attribute as input to the resolver.
122          * <p>The caller retains ownership of the object.
123          *
124          * @param attr  an input Attribute
125          */
126         void addAttribute(shibsp::Attribute* attr);
127
128         /**
129          * Resolves Attributes and attaches them to the resolver object.
130          * <p>The caller is responsible for transferring any Attributes it wishes to
131          * retain out of the resolver.
132          */
133         virtual void resolve();
134
135         /**
136          * Returns a modifiable array of resolved Attribute objects.
137          * <p>The caller may take ownership of any or all by removing them
138          * from the array.
139          *
140          * @return  array of resolved Attributes
141          */
142         std::vector<shibsp::Attribute*>& getResolvedAttributes();
143
144         /**
145          * Returns mapped PropertySet and AccessControl objects, if any.
146          *
147          * @return  mapped PropertySet/AccesssControl pair
148          */
149         shibsp::RequestMapper::Settings getSettings() const;
150
151         /**
152          * Initializes SP runtime objects based on an XML configuration string or a configuration pathname.
153          * <p>Each process using the library MUST call this function exactly once before using any library classes.
154          *
155          * @param features  bitmask of SP components to enable
156          * @param config    a snippet of XML to parse (it <strong>MUST</strong> contain a type attribute) or a pathname
157          * @param rethrow   true iff caught exceptions should be rethrown instead of just returning a true/false result
158          * @return true iff initialization was successful
159          */
160         static bool init(
161 #ifdef SHIBSP_LITE
162             unsigned long features = (shibsp::SPConfig::Listener|shibsp::SPConfig::InProcess),
163 #else
164             unsigned long features = shibsp::SPConfig::OutOfProcess,
165 #endif
166             const char* config = NULL,
167             bool rethrow = false
168             );
169
170         /**
171          * Shuts down runtime.
172          *
173          * Each process using the library SHOULD call this function exactly once before terminating itself.
174          */
175         static void term();
176
177         /**
178          * Returns a ShibbolethResolver instance.
179          *
180          * @return  a ShibbolethResolver instance, must be freed by the caller.
181          */
182         static ShibbolethResolver* create();
183
184     protected:
185         /** Service request. */
186         const shibsp::SPRequest* m_request;
187
188         /** Application ID. */
189         std::string m_appID;
190
191         /** Source of identity, if known. */
192         std::string m_issuer;
193
194         /** Input tokens. */
195         std::vector<const xmltooling::XMLObject*> m_tokens;
196
197         /** Input attributes. */
198         std::vector<shibsp::Attribute*> m_inputAttributes;
199
200     private:
201         shibsp::ServiceProvider* m_sp;
202 #ifdef SHIBRESOLVER_HAVE_GSSAPI
203         xmltooling::XMLObject* m_gsswrapper;
204 #endif
205         std::vector<shibsp::Attribute*> m_resolvedAttributes;
206     };
207
208 #if defined (_MSC_VER)
209     #pragma warning( pop )
210 #endif
211
212 };
213
214 #endif /* __shibresolver_h__ */