f397e270bf85670536f5561d6308f6d36c06a2a6
[shibboleth/cpp-sp.git] / shibsp / handler / Handler.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/handler/Handler.h
19  * 
20  * Pluggable runtime functionality that implement protocols and services.
21  */
22
23 #ifndef __shibsp_handler_h__
24 #define __shibsp_handler_h__
25
26 #include <shibsp/util/PropertySet.h>
27
28 #ifndef SHIBSP_LITE
29 namespace opensaml {
30     namespace saml2md {
31         class SAML_API SPSSODescriptor;
32     };
33 };
34 #endif
35
36 namespace shibsp {
37
38     class SHIBSP_API SPRequest;
39
40     /**
41      * Pluggable runtime functionality that implement protocols and services
42      */
43     class SHIBSP_API Handler : public virtual PropertySet
44     {
45         MAKE_NONCOPYABLE(Handler);
46     protected:
47         Handler();
48     public:
49         virtual ~Handler();
50
51         /**
52          * Executes handler functionality as an incoming request.
53          * 
54          * <p>Handlers can be run either directly by incoming web requests
55          * or indirectly/implicitly during other SP processing.
56          * 
57          * @param request   SP request context
58          * @param isHandler true iff executing in the context of a direct handler invocation
59          * @return  a pair containing a "request completed" indicator and a server-specific response code
60          */
61         virtual std::pair<bool,long> run(SPRequest& request, bool isHandler=true) const=0;
62
63 #ifndef SHIBSP_LITE
64         /**
65          * Generates and/or modifies metadata reflecting the Handler.
66          *
67          * <p>The default implementation does nothing.
68          *
69          * @param role          metadata role to decorate
70          * @param handlerURL    base location of handler's endpoint
71          */
72         virtual void generateMetadata(opensaml::saml2md::SPSSODescriptor& role, const char* handlerURL) const {
73         }
74
75         /**
76          * Returns the "type" of the Handler plugin.
77          *
78          * @return  a Handler type
79          */
80         virtual const char* getType() const;
81 #endif
82     };
83     
84     /** Registers Handler implementations. */
85     void SHIBSP_API registerHandlers();
86
87     /** Handler for metadata generation. */
88     #define METADATA_GENERATOR_HANDLER "MetadataGenerator"
89
90     /** Handler for status information. */
91     #define STATUS_HANDLER "Status"
92
93     /** Handler for session diagnostic information. */
94     #define SESSION_HANDLER "Session"
95 };
96
97 #endif /* __shibsp_handler_h__ */