Qore HttpServerUtil Module Reference  0.3.11.2
 All Classes Namespaces Functions Variables Groups Pages
HttpServer::AbstractAuthenticator Class Reference

abstract base class for external authentication More...

Inheritance diagram for HttpServer::AbstractAuthenticator:

Public Member Functions

 authenticate (string user, string pass="")
 called to authenticate a user for a connection More...
 
 authenticateByIP (string ip, reference user)
 called when the connection requires authentication, but no authentication credentials were supplied, to try to authenticate the connection based on the source IP address More...
 
*hash authenticateRequest (HttpListenerInterface listener, hash hdr, reference cx)
 primary method called to authenticate each request More...
 
string getRealm ()
 returns the authentication realm as a string More...
 
bool requiresAuthentication ()
 called to check if the connection requires authentication More...
 

Detailed Description

abstract base class for external authentication

This class should be inherited by a class providing real authentication

Member Function Documentation

HttpServer::AbstractAuthenticator::authenticate ( string  user,
string  pass = "" 
)

called to authenticate a user for a connection

This method will only be called if requiresAuthentication() returns True

Parameters
userthe username to authenticate
passthe password for the user
Exceptions
AUTHENTICATION-ERRORsubclasses should throw this exception if the user cannot be authenticated (must be overridden in child classes; this parent method will never throw any exceptions; all connections are accepted by default)
HttpServer::AbstractAuthenticator::authenticateByIP ( string  ip,
reference  user 
)

called when the connection requires authentication, but no authentication credentials were supplied, to try to authenticate the connection based on the source IP address

This method will only be called if requiresAuthentication() returns True and no authentication credentials are supplied with the request

Parameters
ipthe IP address of the source connection
usera reference to a string that will be populated with the username to use if the request can be authenticated based on the source IP address (this method returns the string "admin")
Exceptions
AUTHENTICATION-ERRORsubclasses should throw this exception if the user cannot be authenticated (however this base class method as implemented here will never throw any exceptions
*hash HttpServer::AbstractAuthenticator::authenticateRequest ( HttpListenerInterface  listener,
hash  hdr,
reference  cx 
)

primary method called to authenticate each request

Parameters
listeneran HttpListenerInterface object for the listener serving the request for logging purposes
hdra hash of request headers
cxa reference to the call context hash; set the "user" key to the user name if a user was identified and authorized
Returns
returns NOTHING if there were no errors, otherwise returns a hash with the following keys to indicate an authentication or authorization error:
  • "code": the HTTP response code
  • "body": the error message body
  • "hdr": an optional hash of headers for the error response
string HttpServer::AbstractAuthenticator::getRealm ( )

returns the authentication realm as a string

Returns
the authentication realm as a string (default: "Default Authentication Realm")
bool HttpServer::AbstractAuthenticator::requiresAuthentication ( )

called to check if the connection requires authentication

Returns
True if authentication is enabled, False if not (False is the default value returned)