Web framework C++  2.0.0
Simple web framework on c++ designed to easily create web pages, etc
Public Member Functions | List of all members
AuthorizedHandler Class Reference

Proxy handler template to control access to another handlers. More...

#include <authorized_handler.h>

Inheritance diagram for AuthorizedHandler:
Inheritance graph
Collaboration diagram for AuthorizedHandler:
Collaboration graph

Public Member Functions

 AuthorizedHandler (Handler *realHandler, const char *middlewareID, std::function< bool(Entity *)> checkAccess=nullptr)
 
 ~AuthorizedHandler () override
 
void exec () override
 
void setAccessCheck (std::function< bool(Entity *)> checkAccess)
 
void setNext (Handler *next) override
 
void add (Handler *handler) override
 
- Public Member Functions inherited from Handler
 Handler (const char *route=nullptr, HTTP::Method method=HTTP::Method::ANY, Handler *next=nullptr)
 
virtual ~Handler ()
 
bool isRouted ()
 
std::string getRoute ()
 
HTTP::Method getMethod ()
 
void setContext (Context *context)
 
void handleRequest ()
 

Additional Inherited Members

- Protected Member Functions inherited from Handler
ContextgetContext ()
 

Detailed Description

Proxy handler template to control access to another handlers.

Any handlers or chain of handlers could be wrapped by this handler. All that you need is to create an example of this class and pass a concrete handler, which should be controlled, and function, which checks if current user could access such resource. Could substitute passed handlers with 403 or 401 error pages

Constructor & Destructor Documentation

AuthorizedHandler::AuthorizedHandler ( Handler realHandler,
const char *  middlewareID,
std::function< bool(Entity *)>  checkAccess = nullptr 
)

Create proxy handler, which wraps passed one

Parameters
realHandlerhandler and other handlers connected after it, which should be wrapped
middlewareIDID of AuthMiddleware, added to application
checkAccessfunction, that checks, if current user could see such resource. If not, user should see 403 forbidden error page, if there are no user authenticated - 401 unauthenticated error page
AuthorizedHandler::~AuthorizedHandler ( )
override

destructs inner oblects

Member Function Documentation

void AuthorizedHandler::add ( Handler handler)
overridevirtual

Add handler to tail of wrapped handler chain of responsibility

Parameters
handlerhandler object

Reimplemented from Handler.

void AuthorizedHandler::exec ( )
overridevirtual

Execute real handler, if user has access

Implements Handler.

void AuthorizedHandler::setAccessCheck ( std::function< bool(Entity *)>  checkAccess)

Set function, that checks if user could access resource

Parameters
checkAccessfunction that return true if user has access
void AuthorizedHandler::setNext ( Handler next)
overridevirtual

Set next handler after wrapped handler

Parameters
nexthandler object

Reimplemented from Handler.


The documentation for this class was generated from the following file: