38#ifndef __AuthenticatedUser_h
39#define __AuthenticatedUser_h
41#include <HttpServer.h>
42#include <BaServerLib.h>
43#include <DoubleList.h>
62extern const char BasicAuthUser_derivedType[];
63extern const char DigestAuthUser_derivedType[];
64extern const char FormAuthUser_derivedType[];
83 AuthenticatedUserType_Unknown,
84 AuthenticatedUserType_Digest,
85 AuthenticatedUserType_Basic,
86 AuthenticatedUserType_Form
134#define AuthorizerIntf_constructor(o, authorize) (o)->authorizeFP=authorize
135#define AuthorizerIntf_authorize(o, user, method, path) \
136 (o)->authorizeFP(o, user, method, path)
141 AuthorizerIntf_constructor(
this,
authorize); }
146 return AuthorizerIntf_authorize(
this,user,method,path) ? true :
false; }
195#define UserIntf_constructor(o, getPwd) (o)->getPwdFp = getPwd
197#define UserIntf_getPwd(o, username) (o)->getPwdFp(o, username)
200inline UserIntf::UserIntf(
202 UserIntf_constructor(
this, getPwd);
208typedef struct AuthUserList
222BA_API
int AuthUserList_createOrCheck(
struct AuthInfo* info,
228typedef DoubleListEnumerator AuthUserListEnumerator;
229#define AuthUserListEnumerator_constructor(e, o) \
230 DoubleListEnumerator_constructor(e, &(o)->list)
232AuthUserListEnumerator_getElement(DoubleListEnumerator* o);
234AuthUserListEnumerator_nextElement(DoubleListEnumerator* o);
235void AuthUserList_termIfEmpty(AuthUserList* o);
318 void logout(
bool all=
false);
332 AuthUserList* authUserList;
333 const char* derivedType;
342 const char* derivedType,
348#define AuthenticatedUser_getName(o) \
349 ((o) && (o)->authUserList && (o)->authUserList->username ? \
350 (o)->authUserList->username : 0)
351#define AuthenticatedUser_getDerivedType(o) (o)->derivedType
352#define AuthenticatedUser_getSession(o) \
353 HttpSessionAttribute_getSession((HttpSessionAttribute*)o)
354#define AuthenticatedUser_getPassword(o) \
355 ((o) && (o)->authUserList && (o)->authUserList->password ? \
356 (o)->authUserList->password : 0)
363 return AuthenticatedUser_get1(request); }
365 return AuthenticatedUser_get2(session); }
367 return AuthenticatedUser_getName(
this); }
369 return AuthenticatedUser_getSession(
this); }
371 return AuthenticatedUser_getPassword(
this); }
373 AuthenticatedUser_logout(
this, all ? TRUE : FALSE); }
375 return AuthenticatedUser_getType(
this); }
377 return AuthenticatedUser_getAnonymous(); }
421#define AuthenticatorIntf_authenticate(o, relPath, cmd) \
422 (o)->authenticateCB(o, relPath, cmd)
424BA_API
void AuthenticatorIntf_constructor(
429inline AuthenticatorIntf::AuthenticatorIntf(
435 return AuthenticatorIntf_authenticate(
this, relPath, cmd);
474#define LoginRespIntf_constructor(o, service) (o)->serviceFp=service
477 LoginRespIntf_constructor(
this, service); }
546 AuthUserList* authUserList;
598#define AuthInfo_constructor(o, trackerMA, cmdMA, typeMA) do {\
599 memset(o, 0, sizeof(AuthInfo));\
600 (o)->tracker=trackerMA;\
604 (o)->ct=AuthInfoCT_Password;\
687#define LoginTrackerIntf_constructor(\
688 o, validateMA, loginMA, loginFailedMA, terminateNodeMA) do {\
689 (o)->validate=validateMA;\
691 (o)->loginFailed=loginFailedMA;\
692 (o)->terminateNode=terminateNodeMA;\
694#define LoginTrackerIntf_validate(o, request, node) \
695 (o)->validate(o, request, node)
696#define LoginTrackerIntf_login(o, request, user) \
697 (o)->login(o, request, user)
698#define LoginTrackerIntf_loginFailed(o, node, loginName) \
699 (o)->loginFailed(o, node, loginName)
700#define LoginTrackerIntf_terminateNode(o, node) \
701 (o)->terminateNode(o, node)
709 LoginTrackerIntf_constructor(
this,validate,login,loginFailed,terminateNode);
758#define LoginTrackerNode_getCounter(o) (o)->loginCounter
759#define LoginTrackerNode_getAuxCounter(o) (o)->auxCounter
760#define LoginTrackerNode_setAuxCounter(o, count) (o)->auxCounter=count
761#define LoginTrackerNode_getAddr(o) (&(o)->addr)
762#define LoginTrackerNode_setUserData(o, data) (o)->userData=data
763#define LoginTrackerNode_getUserData(o) (o)->userData
764#define LoginTrackerNode_getTime(o) (o)->t
768 return LoginTrackerNode_getCounter(
this);
771 return LoginTrackerNode_getAuxCounter(
this);
775 LoginTrackerNode_setAuxCounter(
this, count);
779 return LoginTrackerNode_getAddr(
this);
782 LoginTrackerNode_setUserData(
this, data);
785 return LoginTrackerNode_getUserData(
this);
788 return LoginTrackerNode_getTime(
this);
843 DoubleList dInUseList;
844 DoubleList dFreeList;
847 U32 noOfLoginTrackerNodes;
856 U32 noOfLoginTrackerNodes,
865BA_API
void LoginTracker_loginFailed(
874 LoginTracker_constructor(
this, noOfLoginTrackerNodes, intf, allocator);
877 LoginTracker_clearCache(
this);
880 return LoginTracker_getFirstNode(
this);
883 return LoginTracker_getNextNode(
this,n);
886 return LoginTracker_find(
this,request);
895 const char* realm,
const char* uname,
const char* pwd, U8 hexbuf[33]);
struct UserIntf UserIntf
User database interface used by the authentication classes.
AuthInfoCT
AuthInfo Credential Type can optionally be used by the UserIntf_GetPwd callback function.
Definition: AuthenticatedUser.h:484
LoginTrackerNode * find(HttpRequest *request)
Find LoginTrackerNode in cache by using the IP address from the request object.
Definition: AuthenticatedUser.h:885
HttpSession * getSession()
Get the session object associated with this authenticated user.
Definition: AuthenticatedUser.h:368
static AuthenticatedUser * getAnonymous()
Returns the shared anonymous user object used internally.
Definition: AuthenticatedUser.h:376
bool authorize(struct AuthenticatedUser *user, HttpMethod method, const char *path)
Returns TRUE if user is authorized.
Definition: AuthenticatedUser.h:143
const char * getPassword()
Returns the user's password or password hash as provided by the authenticator.
Definition: AuthenticatedUser.h:370
AuthenticatedUser *(* AuthenticatorIntf_Authenticate)(struct AuthenticatorIntf *super, const char *relPath, HttpCommand *cmd)
The authenticator callback method for the abstract class AuthenticatorIntf.
Definition: AuthenticatedUser.h:388
U32 getCounter()
Returns the number of login attempts.
Definition: AuthenticatedUser.h:767
LoginTrackerIntf(LoginTrackerIntf_Validate validate, LoginTrackerIntf_Login login, LoginTrackerIntf_LoginFailed loginFailed, LoginTrackerIntf_TerminateNode terminateNode)
Create a LoginTrackerIntf.
Definition: AuthenticatedUser.h:704
void(* LoginTrackerIntf_Login)(struct LoginTrackerIntf *o, AuthInfo *info, struct LoginTrackerNode *node)
Prototype for the Login tracker method.
Definition: AuthenticatedUser.h:630
BaTime getTime()
Returns the time for the latest login attempt.
Definition: AuthenticatedUser.h:787
struct AuthorizerIntf AuthorizerIntf
An abstract class, which you must implement, provides a method of authorizing an authenticated user.
LoginTrackerNode * getNextNode(LoginTrackerNode *n)
Return the next LoginTrackerNode in the cache or NULL if no more nodes.
Definition: AuthenticatedUser.h:882
void * getUserData()
Fetch stored application data in this node.
Definition: AuthenticatedUser.h:784
AuthenticatedUserType getType()
Returns the authenticator type that was used to authenticate this user.
Definition: AuthenticatedUser.h:374
struct AuthenticatorIntf AuthenticatorIntf
Abstract interface class implemented by DigestAuthenticator, FormAuthenticator and DigestAuthenticato...
BaBool(* LoginTrackerIntf_Validate)(struct LoginTrackerIntf *o, AuthInfo *info, struct LoginTrackerNode *node)
Prototype for the validate callback method.
Definition: AuthenticatedUser.h:616
AuthenticatedUser * authenticate(const char *relPath, HttpCommand *cmd)
Authenticate the user.
Definition: AuthenticatedUser.h:433
struct LoginTrackerNode LoginTrackerNode
A LoginTrackerNode keeps track of how many times a user using a specific IP address has attempted to ...
const char * getName()
Returns the authenticated user's name.
Definition: AuthenticatedUser.h:366
LoginTrackerNode * getFirstNode()
Return first LoginTrackerNode in the cache or NULL if cache empty.
Definition: AuthenticatedUser.h:879
AuthenticatedUserType
The authenticator types.
Definition: AuthenticatedUser.h:82
struct LoginRespIntf LoginRespIntf
The LoginRespIntf is an abstract class, which must be implemented when using one of DigestAuthenticat...
void logout(bool all=false)
Logout user and terminate the session object.
Definition: AuthenticatedUser.h:372
struct LoginTrackerIntf LoginTrackerIntf
The interface between the LoginTracker and the application code.
void(* LoginRespIntf_Service)(struct LoginRespIntf *intf, struct AuthInfo *info)
This callback function is called if the user failed to authenticate with one of DigestAuthenticator,...
Definition: AuthenticatedUser.h:451
void(* UserIntf_GetPwd)(struct UserIntf *intf, struct AuthInfo *info)
User database callback used by authenticators.
Definition: AuthenticatedUser.h:170
static AuthenticatedUser * get(HttpRequest *request)
Returns a pointer to an instance of class AuthenticatedUser if a session object exists and if the use...
Definition: AuthenticatedUser.h:362
void setUserData(void *data)
Store application data in this node.
Definition: AuthenticatedUser.h:781
void clearCache()
Clear the LoginTrackerNode cache.
Definition: AuthenticatedUser.h:876
struct LoginTracker LoginTracker
The LoginTracker class is an optional security enhancement that can be installed in an instance of on...
void(* LoginTrackerIntf_LoginFailed)(struct LoginTrackerIntf *o, AuthInfo *info, struct LoginTrackerNode *node)
Prototype for the LoginFailed callback method.
Definition: AuthenticatedUser.h:647
U32 getAuxCounter()
Get auxiliary counter.
Definition: AuthenticatedUser.h:770
struct AuthInfo AuthInfo
An instance of the AuthInfo struct is created on the stack in the Barracuda authenticators and is use...
HttpSockaddr * getAddr()
Return the HttpSockaddr.
Definition: AuthenticatedUser.h:778
BaBool(* AuthorizerIntf_Authorize)(struct AuthorizerIntf *intf, struct AuthenticatedUser *user, HttpMethod httpMethod, const char *path)
Prototype for the Authorize callback method.
Definition: AuthenticatedUser.h:102
struct AuthenticatedUser AuthenticatedUser
Abstract base class implemented by BasicAuthUser, FormAuthUser and DigestAuthUser.
void(* LoginTrackerIntf_TerminateNode)(struct LoginTrackerIntf *o, struct LoginTrackerNode *node)
Prototype for the TerminateNode callback method.
Definition: AuthenticatedUser.h:658
void setAuxCounter(U32 count)
Set auxiliary counter.
Definition: AuthenticatedUser.h:774
LoginTracker(U32 noOfLoginTrackerNodes, LoginTrackerIntf *intf, AllocatorIntf *allocator=AllocatorIntf::getDefault())
Create a LoginTracker instance.
Definition: AuthenticatedUser.h:871
@ AuthInfoCT_Invalid
Set when getpwd callback failed comparing AuthInfo::upwd with stored password.
Definition: AuthenticatedUser.h:499
@ AuthInfoCT_Valid
Set when getpwd callback successfully compared AuthInfo::upwd with stored password.
Definition: AuthenticatedUser.h:494
@ AuthInfoCT_HA1
The password is returned as a HA1 hash, which is: MD5(username ":" realm ":" password)
Definition: AuthenticatedUser.h:490
@ AuthInfoCT_Password
The default.
Definition: AuthenticatedUser.h:486
void(* HttpSessionAttribute_Destructor)(struct HttpSessionAttribute *o)
HttpSessionAttribute termination callback function.
Definition: HttpServer.h:1887
HttpMethod
HTTP method types.
Definition: HttpServer.h:780
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:10 GMT – i....
Definition: GenPrimT.h:93
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
static AllocatorIntf * getDefault(void)
Returns a pointer to a predefined AllocatorIntf class.
Definition: AllocatorIntf.h:156
An instance of the AuthInfo struct is created on the stack in the Barracuda authenticators and is use...
Definition: AuthenticatedUser.h:508
const char * username
The user name if the client sends login information.
Definition: AuthenticatedUser.h:516
const char * upwd
The password provided by the user, if any.
Definition: AuthenticatedUser.h:519
AuthInfoCT ct
The ct parameter can optionally be set by the UserIntf_GetPwd function.
Definition: AuthenticatedUser.h:539
BaBool recycle
Force another client to log out.
Definition: AuthenticatedUser.h:583
int maxUsers
Max number of concurrent logins for this user.
Definition: AuthenticatedUser.h:565
struct LoginTracker * tracker
The tracker object if any.
Definition: AuthenticatedUser.h:510
U8 password[100]
Must be set by UserIntf_GetPwd if the user is found.
Definition: AuthenticatedUser.h:595
BaTime maxInactiveInterval
This variable specifies the time, in seconds, between client requests before the user is automaticall...
Definition: AuthenticatedUser.h:556
HttpCommand * cmd
The request/response container object.
Definition: AuthenticatedUser.h:513
AuthenticatedUser * user
The authenticated user object if the user is authenticated.
Definition: AuthenticatedUser.h:523
int loginAttempts
Shows the number of login attempts if the LoginTracker is active.
Definition: AuthenticatedUser.h:570
BaBool denied
Flag set if the user is denied access by the LoginTracker.
Definition: AuthenticatedUser.h:575
void * userObj
An object that can be set by the callbacks for exchanging information.
Definition: AuthenticatedUser.h:544
AuthenticatedUserType type
The AuthenticatedUser type.
Definition: AuthenticatedUser.h:531
Abstract base class implemented by BasicAuthUser, FormAuthUser and DigestAuthUser.
Definition: AuthenticatedUser.h:246
Abstract interface class implemented by DigestAuthenticator, FormAuthenticator and DigestAuthenticato...
Definition: AuthenticatedUser.h:398
An abstract class, which you must implement, provides a method of authorizing an authenticated user.
Definition: AuthenticatedUser.h:112
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:1824
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:816
The Web Server.
Definition: HttpServer.h:2867
The interface to an HttpSession attribute.
Definition: HttpServer.h:1918
Provides a way to identify a user across more than one page request or visit to a web site,...
Definition: HttpServer.h:1965
The LoginRespIntf is an abstract class, which must be implemented when using one of DigestAuthenticat...
Definition: AuthenticatedUser.h:463
The interface between the LoginTracker and the application code.
Definition: AuthenticatedUser.h:668
A LoginTrackerNode keeps track of how many times a user using a specific IP address has attempted to ...
Definition: AuthenticatedUser.h:719
The LoginTracker class is an optional security enhancement that can be installed in an instance of on...
Definition: AuthenticatedUser.h:809
User database interface used by the authentication classes.
Definition: AuthenticatedUser.h:177