Authorizer Class Referenceabstract

#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.
AuthorizationbeginAuthorize (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 AuthorizationonBeginAuthorize (const Request &req, Reply &reply, bool &granted)=0
 Begin authorization for a reply.
virtual void onReleaseAuthorization (Authorization *auth)=0
 Release authorization operation.

Detailed Description

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.

class AccessAuthorizer : public Pt::Http::BasicAuthorizer
{
public:
explicit AccessAuthorizer(const std::string& realm)
{}
protected:
const Pt::Http::Credential& cred, bool& granted)
{
granted = checkCredentials(cred.user(), cred.password());
return 0;
}
{}
};
AccessAuthorizer auth("some-realm");
HelloService hello;
Pt::Http::MapUrl mapHello("/hello", hello, auth);
server.addServlet(mapHello);
Asynchronous HTTP authorization operation.
Definition Authorizer.h:52
const std::string & realm() const
Returns the realm.
virtual void onReleaseAuthorization(Authorization *auth)=0
Release authorization operation.
Server-side basic HTTP authorization.
Definition Authorizer.h:194
virtual Authorization * onAuthorizeCredentials(const Credential &cred, bool &granted)=0
Begin authorization using client credentials.
Credentials for authorization and authentication.
Definition Credentials.h:45
std::string & password()
Returns the password.
Definition Credentials.h:94
std::string & user()
Returns the user name.
Definition Credentials.h:84
HTTP clients and servers.
Core module.
Definition Allocator.h:33