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