![]() |
zeep::http::security_context — class that manages security in a HTTP scope
// In header: <zeep/http/security.hpp> class security_context { public: // member classes/structs/unions struct rule { // public data members m_pattern; m_roles; }; // construct/copy/destruct (, user_service &, = ); (security_context &) = ; security_context & (security_context &) = ; // public member functions template<typename PWEncoder> (); (, ); (, ); (request &) ; (reply &, ); (reply &, user_details); (, , reply &); user_service & () ; (request &); (); () ; };
Add this to a HTTP server and it will check authentication. Access to certain paths can be limited by specifying which 'roles' are allowed.
The authentication mechanism used is based on JSON Web Tokens, JWT in short.
security_context
public
construct/copy/destruct( secret, user_service & users, defaultAccessAllowed = );constructor taking a validator
Create a security context for server s with validator validator and a flag defaultAccessAllowed indicating if non-matched uri's should be allowed
(security_context &) = ;
security_context & (security_context &) = ;
security_context
public member functionstemplate<typename PWEncoder> ();register a custom password encoder
The password encoder should derive from the abstract password encoder class above and also implement the name() method.
( glob_pattern, role);Add a new rule for access.
A new rule will be added to the list, allowing access to glob_pattern to users having role role
glob_pattern should start with a slash
( glob_pattern, roles);Add a new rule for access.
A new rule will be added to the list, allowing access to glob_pattern to users having a role in roles
If roles is empty, access is allowed to anyone.
glob_pattern should start with a slash
(request & req) ;Validate the request req against the stored rules.
This method will validate the request in req agains the stored rules and will throw an exception if access is not allowed. The request req will be updated with the credentials for further use. If the validate CSRF is set, the CSRF token will also be validated.
(reply & rep, username);Add e.g. headers to reply for an authorized request.
When validation succeeds, a HTTP reply is send to the user and this routine will be called to augment the reply with additional information.
Parameters: |
|
(reply & rep, user_details user);Add e.g. headers to reply for an authorized request.
When validation succeeds, a HTTP reply is send to the user and this routine will be called to augment the reply with additional information.
Parameters: |
|
( username, password, reply & rep);verify the username/password combination and set a cookie in the reply in case of success
When validation succeeds, add_authorization_headers is called, otherwise an exception is thrown.
Parameters: |
|
user_service & () ;return reference to the
user_service
object (request & req);Get or create a CSRF token for the current request.
Return a CSRF token. If this was not present in the request, a new will be generated
Parameters: |
|
||
Returns: |
A std::pair containing the CSRF token and a flag indicating the token is new |
( validate);To automatically validate CSRF tokens, set this flag.
() ;