Kea 2.7.6
basic_auth_config.h
Go to the documentation of this file.
1// Copyright (C) 2020-2022 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef HTTP_BASIC_AUTH_CONFIG_H
8#define HTTP_BASIC_AUTH_CONFIG_H
9
10#include <http/auth_config.h>
11#include <http/basic_auth.h>
12#include <list>
13#include <unordered_map>
14
15namespace isc {
16namespace http {
17
23typedef std::unordered_map<std::string, std::string> BasicHttpAuthMap;
24
28public:
29
35 BasicHttpAuthClient(const std::string& user,
36 const std::string& password,
37 const isc::data::ConstElementPtr& user_context);
38
48 BasicHttpAuthClient(const std::string& user,
49 const std::string& user_file,
50 const std::string& password,
51 const std::string& password_file,
52 bool password_file_only,
53 const isc::data::ConstElementPtr& user_context);
54
58 const std::string& getUser() const {
59 return (user_);
60 }
61
65 const std::string& getUserFile() const {
66 return (user_file_);
67 }
68
72 const std::string& getPassword() const {
73 return (password_);
74 }
75
79 const std::string& getPasswordFile() const {
80 return (password_file_);
81 }
82
86 bool getPasswordFileOnly() const {
87 return (password_file_only_);
88 }
89
93 virtual isc::data::ElementPtr toElement() const;
94
95private:
96
98 std::string user_;
99
101 std::string user_file_;
102
104 std::string password_;
105
107 std::string password_file_;
108
110 bool password_file_only_;
111};
112
114typedef std::list<BasicHttpAuthClient> BasicHttpAuthClientList;
115
118public:
121
132 void add(const std::string& user,
133 const std::string& user_file,
134 const std::string& password,
135 const std::string& password_file,
136 bool password_file_only = false,
138
143 virtual bool empty() const;
144
146 virtual void clear();
147
152 std::string getFileContent(const std::string& file_name) const;
153
158 return (list_);
159 }
160
165 return (map_);
166 }
167
173 void parse(const isc::data::ConstElementPtr& config);
174
178 virtual isc::data::ElementPtr toElement() const;
179
187 const isc::http::HttpRequestPtr& request) const;
188
189private:
190
193
195 BasicHttpAuthMap map_;
196};
197
199typedef boost::shared_ptr<BasicHttpAuthConfig> BasicHttpAuthConfigPtr;
200
201} // end of namespace isc::http
202} // end of namespace isc
203
204#endif // endif HTTP_BASIC_AUTH_CONFIG_H
Basic HTTP authentication client configuration.
const std::string & getPassword() const
Returns the password.
const std::string & getUserFile() const
Returns the user id file.
const std::string & getPasswordFile() const
Returns the password file.
bool getPasswordFileOnly() const
Returns the password file only flag.
const std::string & getUser() const
Returns the user id.
BasicHttpAuthClient(const std::string &user, const std::string &password, const isc::data::ConstElementPtr &user_context)
Constructor (legacy).
virtual isc::data::ElementPtr toElement() const
Unparses basic HTTP authentication client configuration.
Basic HTTP authentication configuration.
std::string getFileContent(const std::string &file_name) const
Get the content of {directory}/{file-name} regular file.
const BasicHttpAuthClientList & getClientList() const
Returns the list of client configuration.
virtual isc::data::ElementPtr toElement() const
Unparses basic HTTP authentication configuration.
void add(const std::string &user, const std::string &user_file, const std::string &password, const std::string &password_file, bool password_file_only=false, const isc::data::ConstElementPtr &user_context=isc::data::ConstElementPtr())
Add a client configuration.
void parse(const isc::data::ConstElementPtr &config)
Parses basic HTTP authentication configuration.
virtual isc::http::HttpResponseJsonPtr checkAuth(const isc::http::HttpResponseCreator &creator, const isc::http::HttpRequestPtr &request) const
Validate HTTP request.
virtual void clear()
Clear configuration.
virtual ~BasicHttpAuthConfig()
Destructor.
virtual bool empty() const
Empty predicate.
const BasicHttpAuthMap & getCredentialMap() const
Returns the credential and user id map.
Base type of HTTP authentication configuration.
Definition auth_config.h:23
Specifies an interface for classes creating HTTP responses from HTTP requests.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::unordered_map< std::string, std::string > BasicHttpAuthMap
Type of basic HTTP authentication credential and user id map, e.g.
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
std::list< BasicHttpAuthClient > BasicHttpAuthClientList
Type of basic HTTP authentication client configuration list.
boost::shared_ptr< BasicHttpAuthConfig > BasicHttpAuthConfigPtr
Type of shared pointers to basic HTTP authentication configuration.
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
Definition request.h:30
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.