#include <Pt/Http/Authorizer.h>
Server-side authorization. More...
Inherits NonCopyable.
Inherited by BasicAuthorizer.
Public Member Functions | |
| Authorizer (const std::string &realm) | |
| Construct for a realm. | |
| Authorizer (const char *realm) | |
| Construct for a realm. | |
| virtual | ~Authorizer () |
| Destructor. | |
| const std::string & | realm () const |
| Returns the realm. | |
| Authorization * | beginAuthorize (const Request &req, Reply &reply, bool &granted) |
| Begin authorization for a reply. | |
| bool | endAuthorization (Authorization *auth) |
| End authorization. | |
| void | cancelAuthorization (Authorization *auth) |
| Cancel a running authorization. | |
Protected Member Functions | |
| virtual Authorization * | onBeginAuthorize (const Request &req, Reply &reply, bool &granted)=0 |
| Begin authorization for a reply. | |
| virtual void | onReleaseAuthorization (Authorization *auth)=0 |
| Release authorization operation. | |
Authorizer is the access check in the server model. It is attached to a Servlet, not to the server as a whole, and the same authorizer may be shared by several servlets. It is not the client-side Authenticator. The realm is passed to the constructor and returned by realm().
beginAuthorize() starts the check for a request and reply. When the result is already known, granted is set and a null pointer is returned. When the check needs I/O, an Authorization object is returned; endAuthorization() completes it, and cancelAuthorization() aborts it. The authorizer releases that object in onReleaseAuthorization().
BasicAuthorizer implements HTTP Basic authentication. A derived class implements onAuthorizeCredentials() and either sets granted immediately or returns an Authorization for later completion. BasicUserListAuthorizer is that check against an in-memory user list.
The example grants or denies access from credentials in one step, so it returns a null pointer and does not need to release an authorization object.