Merge branch 'upstream' into bug/init
[shibboleth/sp.git] / shibsp / attribute / resolver / AttributeResolver.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/resolver/AttributeResolver.h
19  *
20  * A service that transforms or resolves additional attributes for a particular subject.
21  */
22
23 #ifndef __shibsp_resolver_h__
24 #define __shibsp_resolver_h__
25
26 #include <shibsp/base.h>
27
28 #include <string>
29 #include <vector>
30 #include <xmltooling/Lockable.h>
31
32 namespace opensaml {
33     class SAML_API Assertion;
34     namespace saml2 {
35         class SAML_API NameID;
36     };
37     namespace saml2md {
38         class SAML_API EntityDescriptor;
39     };
40 };
41
42 namespace shibsp {
43
44     class SHIBSP_API Application;
45     class SHIBSP_API Attribute;
46     class SHIBSP_API Session;
47     class SHIBSP_API ResolutionContext;
48
49 #if defined (_MSC_VER)
50     #pragma warning( push )
51     #pragma warning( disable : 4250 4251 )
52 #endif
53
54     /**
55      * The service that resolves the attributes for a particular subject.
56      */
57     class SHIBSP_API AttributeResolver : public virtual xmltooling::Lockable
58     {
59         MAKE_NONCOPYABLE(AttributeResolver);
60     protected:
61         AttributeResolver();
62     public:
63         virtual ~AttributeResolver();
64
65         /**
66          * Creates a ResolutionContext based on session bootstrap material.
67          *
68          * <p>This enables resolution to occur ahead of session creation so that
69          * Attributes can be supplied while creating the session.
70          *
71          * @param application       reference to Application that owns the eventual Session
72          * @param issuer            issuing metadata of assertion issuer, if known
73          * @param protocol          protocol used to establish Session
74          * @param nameid            principal identifier, normalized to SAML 2, if any
75          * @param authncontext_class    method/category of authentication event, if known
76          * @param authncontext_decl specifics of authentication event, if known
77          * @param tokens            assertions initiating the Session, if any
78          * @param attributes        array of previously resolved attributes, if any
79          * @return  newly created ResolutionContext, owned by caller
80          */
81         virtual ResolutionContext* createResolutionContext(
82             const Application& application,
83             const opensaml::saml2md::EntityDescriptor* issuer,
84             const XMLCh* protocol,
85             const opensaml::saml2::NameID* nameid=NULL,
86             const XMLCh* authncontext_class=NULL,
87             const XMLCh* authncontext_decl=NULL,
88             const std::vector<const opensaml::Assertion*>* tokens=NULL,
89             const std::vector<Attribute*>* attributes=NULL
90             ) const=0;
91
92         /**
93          * Creates a ResolutionContext for an existing Session.
94          *
95          * @param application   reference to Application that owns the Session
96          * @param session       reference to Session
97          * @return  newly created ResolutionContext, owned by caller
98          */
99         virtual ResolutionContext* createResolutionContext(const Application& application, const Session& session) const=0;
100
101
102         /**
103          * Resolves attributes for a given subject and returns them in the supplied context.
104          *
105          * @param ctx           resolution context to use to resolve attributes
106          *
107          * @throws AttributeResolutionException thrown if there is a problem resolving the attributes for the subject
108          */
109         virtual void resolveAttributes(ResolutionContext& ctx) const=0;
110
111         /**
112          * Populates an array with the set of Attribute IDs that might be generated.
113          *
114          * @param attributes    array to populate
115          */
116         virtual void getAttributeIds(std::vector<std::string>& attributes) const=0;
117     };
118
119 #if defined (_MSC_VER)
120     #pragma warning( pop )
121 #endif
122
123     /**
124      * Registers AttributeResolver classes into the runtime.
125      */
126     void SHIBSP_API registerAttributeResolvers();
127
128     /** AttributeResolver based on SAML queries to an IdP during SSO. */
129     #define QUERY_ATTRIBUTE_RESOLVER "Query"
130
131     /** AttributeResolver based on free-standing SAML queries to additional AAs. */
132     #define SIMPLEAGGREGATION_ATTRIBUTE_RESOLVER "SimpleAggregation"
133
134     /** AttributeResolver based on chaining together other resolvers. */
135     #define CHAINING_ATTRIBUTE_RESOLVER "Chaining"
136 };
137
138 #endif /* __shibsp_resolver_h__ */