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; }
192#define UserIntf_constructor(o, getPwd) (o)->getPwdFp = getPwd
194#define UserIntf_getPwd(o, username) (o)->getPwdFp(o, username)
197inline UserIntf::UserIntf(
199 UserIntf_constructor(
this, getPwd);
205typedef struct AuthUserList
219BA_API
int AuthUserList_createOrCheck(
struct AuthInfo* info,
225typedef DoubleListEnumerator AuthUserListEnumerator;
226#define AuthUserListEnumerator_constructor(e, o) \
227 DoubleListEnumerator_constructor(e, &(o)->list)
229AuthUserListEnumerator_getElement(DoubleListEnumerator* o);
231AuthUserListEnumerator_nextElement(DoubleListEnumerator* o);
232void AuthUserList_termIfEmpty(AuthUserList* o);
315 void logout(
bool all=
false);
329 AuthUserList* authUserList;
330 const char* derivedType;
339 const char* derivedType,
345#define AuthenticatedUser_getName(o) \
346 ((o) && (o)->authUserList && (o)->authUserList->username ? \
347 (o)->authUserList->username : 0)
348#define AuthenticatedUser_getDerivedType(o) (o)->derivedType
349#define AuthenticatedUser_getSession(o) \
350 HttpSessionAttribute_getSession((HttpSessionAttribute*)o)
351#define AuthenticatedUser_getPassword(o) \
352 ((o) && (o)->authUserList && (o)->authUserList->password ? \
353 (o)->authUserList->password : 0)
360 return AuthenticatedUser_get1(request); }
362 return AuthenticatedUser_get2(session); }
364 return AuthenticatedUser_getName(
this); }
366 return AuthenticatedUser_getSession(
this); }
368 return AuthenticatedUser_getPassword(
this); }
370 AuthenticatedUser_logout(
this, all ? TRUE : FALSE); }
372 return AuthenticatedUser_getType(
this); }
374 return AuthenticatedUser_getAnonymous(); }
418#define AuthenticatorIntf_authenticate(o, relPath, cmd) \
419 (o)->authenticateCB(o, relPath, cmd)
421BA_API
void AuthenticatorIntf_constructor(
426inline AuthenticatorIntf::AuthenticatorIntf(
432 return AuthenticatorIntf_authenticate(
this, relPath, cmd);
471#define LoginRespIntf_constructor(o, service) (o)->serviceFp=service
474 LoginRespIntf_constructor(
this, service); }
543 AuthUserList* authUserList;
595#define AuthInfo_constructor(o, trackerMA, cmdMA, typeMA) do {\
596 memset(o, 0, sizeof(AuthInfo));\
597 (o)->tracker=trackerMA;\
601 (o)->ct=AuthInfoCT_Password;\
684#define LoginTrackerIntf_constructor(\
685 o, validateMA, loginMA, loginFailedMA, terminateNodeMA) do {\
686 (o)->validate=validateMA;\
688 (o)->loginFailed=loginFailedMA;\
689 (o)->terminateNode=terminateNodeMA;\
691#define LoginTrackerIntf_validate(o, request, node) \
692 (o)->validate(o, request, node)
693#define LoginTrackerIntf_login(o, request, user) \
694 (o)->login(o, request, user)
695#define LoginTrackerIntf_loginFailed(o, node, loginName) \
696 (o)->loginFailed(o, node, loginName)
697#define LoginTrackerIntf_terminateNode(o, node) \
698 (o)->terminateNode(o, node)
706 LoginTrackerIntf_constructor(
this,validate,login,loginFailed,terminateNode);
755#define LoginTrackerNode_getCounter(o) (o)->loginCounter
756#define LoginTrackerNode_getAuxCounter(o) (o)->auxCounter
757#define LoginTrackerNode_setAuxCounter(o, count) (o)->auxCounter=count
758#define LoginTrackerNode_getAddr(o) (&(o)->addr)
759#define LoginTrackerNode_setUserData(o, data) (o)->userData=data
760#define LoginTrackerNode_getUserData(o) (o)->userData
761#define LoginTrackerNode_getTime(o) (o)->t
765 return LoginTrackerNode_getCounter(
this);
768 return LoginTrackerNode_getAuxCounter(
this);
772 LoginTrackerNode_setAuxCounter(
this, count);
776 return LoginTrackerNode_getAddr(
this);
779 LoginTrackerNode_setUserData(
this, data);
782 return LoginTrackerNode_getUserData(
this);
785 return LoginTrackerNode_getTime(
this);
846 DoubleList dInUseList;
847 DoubleList dFreeList;
850 U32 noOfLoginTrackerNodes;
859 U32 noOfLoginTrackerNodes,
868BA_API
void LoginTracker_loginFailed(
877 LoginTracker_constructor(
this, noOfLoginTrackerNodes, intf, allocator);
880 LoginTracker_clearCache(
this);
883 return LoginTracker_getFirstNode(
this);
886 return LoginTracker_getNextNode(
this,n);
889 return LoginTracker_find(
this,request);
898 const char* realm,
const char* uname,
const char* pwd, U8 hexbuf[33]);
struct UserIntf UserIntf
Interface class used by the Authentication classes.
AuthInfoCT
AuthInfo Credential Type can optionally be used by the UserIntf_GetPwd callback function.
Definition: AuthenticatedUser.h:481
LoginTrackerNode * find(HttpRequest *request)
Find LoginTrackerNode in cache by using the IP address from the request object.
Definition: AuthenticatedUser.h:888
HttpSession * getSession()
Get the session object.
Definition: AuthenticatedUser.h:365
static AuthenticatedUser * getAnonymous()
non public
Definition: AuthenticatedUser.h:373
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.
Definition: AuthenticatedUser.h:367
AuthenticatedUser *(* AuthenticatorIntf_Authenticate)(struct AuthenticatorIntf *super, const char *relPath, HttpCommand *cmd)
The authenticator callback method for the abstract class AuthenticatorIntf.
Definition: AuthenticatedUser.h:385
U32 getCounter()
Returns the number of login attempts.
Definition: AuthenticatedUser.h:764
LoginTrackerIntf(LoginTrackerIntf_Validate validate, LoginTrackerIntf_Login login, LoginTrackerIntf_LoginFailed loginFailed, LoginTrackerIntf_TerminateNode terminateNode)
Create a LoginTrackerIntf.
Definition: AuthenticatedUser.h:701
void(* LoginTrackerIntf_Login)(struct LoginTrackerIntf *o, AuthInfo *info, struct LoginTrackerNode *node)
Prototype for the Login tracker method.
Definition: AuthenticatedUser.h:627
BaTime getTime()
Returns the time for the latest login attempt.
Definition: AuthenticatedUser.h:784
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:885
void * getUserData()
Fetch stored application data in this node.
Definition: AuthenticatedUser.h:781
AuthenticatedUserType getType()
Returns the authenticator type that was used to authenticate this user.
Definition: AuthenticatedUser.h:371
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:613
AuthenticatedUser * authenticate(const char *relPath, HttpCommand *cmd)
Authenticate the user.
Definition: AuthenticatedUser.h:430
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 user's name.
Definition: AuthenticatedUser.h:363
LoginTrackerNode * getFirstNode()
Return first LoginTrackerNode in the cache or NULL if cache empty.
Definition: AuthenticatedUser.h:882
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:369
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:448
void(* UserIntf_GetPwd)(struct UserIntf *intf, struct AuthInfo *info)
The GetPwd callback function searches for info->username and sets AuthInfo::password if found and/or ...
Definition: AuthenticatedUser.h:168
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:359
void setUserData(void *data)
Store application data in this node.
Definition: AuthenticatedUser.h:778
void clearCache()
Clear the LoginTrackerNode cache.
Definition: AuthenticatedUser.h:879
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:644
U32 getAuxCounter()
Get auxiliary counter.
Definition: AuthenticatedUser.h:767
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:775
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:655
void setAuxCounter(U32 count)
Set auxiliary counter.
Definition: AuthenticatedUser.h:771
LoginTracker(U32 noOfLoginTrackerNodes, LoginTrackerIntf *intf, AllocatorIntf *allocator=AllocatorIntf::getDefault())
Create a LoginTracker instance.
Definition: AuthenticatedUser.h:874
@ AuthInfoCT_Invalid
Set when getpwd callback failed comparing AuthInfo::upwd with stored password.
Definition: AuthenticatedUser.h:496
@ AuthInfoCT_Valid
Set when getpwd callback successfully compared AuthInfo::upwd with stored password.
Definition: AuthenticatedUser.h:491
@ AuthInfoCT_HA1
The password is returned as a HA1 hash, which is: MD5(username ":" realm ":" password)
Definition: AuthenticatedUser.h:487
@ AuthInfoCT_Password
The default.
Definition: AuthenticatedUser.h:483
void(* HttpSessionAttribute_Destructor)(struct HttpSessionAttribute *o)
HttpSessionAttribute termination callback function.
Definition: HttpServer.h:1881
HttpMethod
HTTP method types.
Definition: HttpServer.h:772
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:505
const char * username
The user name if the client sends login information.
Definition: AuthenticatedUser.h:513
const char * upwd
The password provided by the user, if any.
Definition: AuthenticatedUser.h:516
AuthInfoCT ct
The ct parameter can optionally be set by the UserIntf_GetPwd function.
Definition: AuthenticatedUser.h:536
BaBool recycle
Force another client to log out.
Definition: AuthenticatedUser.h:580
int maxUsers
Max number of concurrent logins for this user.
Definition: AuthenticatedUser.h:562
struct LoginTracker * tracker
The tracker object if any.
Definition: AuthenticatedUser.h:507
U8 password[100]
Must be set by UserIntf_GetPwd if the user is found.
Definition: AuthenticatedUser.h:592
BaTime maxInactiveInterval
This variable specifies the time, in seconds, between client requests before the user is automaticall...
Definition: AuthenticatedUser.h:553
HttpCommand * cmd
The request/response container object.
Definition: AuthenticatedUser.h:510
AuthenticatedUser * user
The authenticated user object if the user is authenticated.
Definition: AuthenticatedUser.h:520
int loginAttempts
Shows the number of login attempts if the LoginTracker is active.
Definition: AuthenticatedUser.h:567
BaBool denied
Flag set if the user is denied access by the LoginTracker.
Definition: AuthenticatedUser.h:572
void * userObj
An object that can be set by the callbacks for exchanging information.
Definition: AuthenticatedUser.h:541
AuthenticatedUserType type
The AuthenticatedUser type.
Definition: AuthenticatedUser.h:528
Abstract base class implemented by BasicAuthUser, FormAuthUser and DigestAuthUser.
Definition: AuthenticatedUser.h:243
Abstract interface class implemented by DigestAuthenticator, FormAuthenticator and DigestAuthenticato...
Definition: AuthenticatedUser.h:395
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:1818
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:808
The Web Server.
Definition: HttpServer.h:2864
The interface to an HttpSession attribute.
Definition: HttpServer.h:1912
Provides a way to identify a user across more than one page request or visit to a web site,...
Definition: HttpServer.h:1959
The LoginRespIntf is an abstract class, which must be implemented when using one of DigestAuthenticat...
Definition: AuthenticatedUser.h:460
The interface between the LoginTracker and the application code.
Definition: AuthenticatedUser.h:665
A LoginTrackerNode keeps track of how many times a user using a specific IP address has attempted to ...
Definition: AuthenticatedUser.h:716
The LoginTracker class is an optional security enhancement that can be installed in an instance of on...
Definition: AuthenticatedUser.h:812
Interface class used by the Authentication classes.
Definition: AuthenticatedUser.h:174