Kea  2.3.5-git
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 
15 namespace isc {
16 namespace http {
17 
23 typedef std::unordered_map<std::string, std::string> BasicHttpAuthMap;
24 
28 public:
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 
95 private:
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 
114 typedef std::list<BasicHttpAuthClient> BasicHttpAuthClientList;
115 
118 public:
120  virtual ~BasicHttpAuthConfig() { }
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 
157  const BasicHttpAuthClientList& getClientList() const {
158  return (list_);
159  }
160 
164  const BasicHttpAuthMap& getCredentialMap() const {
165  return (map_);
166  }
167 
173  void parse(const isc::data::ConstElementPtr& config);
174 
178  virtual isc::data::ElementPtr toElement() const;
179 
186  checkAuth(const isc::http::HttpResponseCreator& creator,
187  const isc::http::HttpRequestPtr& request) const;
188 
189 private:
190 
192  BasicHttpAuthClientList list_;
193 
195  BasicHttpAuthMap map_;
196 };
197 
199 typedef 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
const std::string & getUserFile() const
Returns the user id file.
const std::string & getUser() const
Returns the user id.
Basic HTTP authentication configuration.
const std::string & getPassword() const
Returns the password.
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
Definition: response_json.h:24
Base class for user context.
Definition: user_context.h:22
virtual isc::data::ElementPtr toElement() const
Unparses basic HTTP authentication client configuration.
Specifies an interface for classes creating HTTP responses from HTTP requests.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
Base type of HTTP authentication configuration.
Definition: auth_config.h:22
std::unordered_map< std::string, std::string > BasicHttpAuthMap
Type of basic HTTP authentication credential and user id map, e.g.
BasicHttpAuthClient(const std::string &user, const std::string &password, const isc::data::ConstElementPtr &user_context)
Constructor (legacy).
bool getPasswordFileOnly() const
Returns the password file only flag.
const BasicHttpAuthClientList & getClientList() const
Returns the list of client configuration.
Abstract class for configuration Cfg_* classes.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
const std::string & getPasswordFile() const
Returns the password file.
Defines the logger used by the top-level component of kea-lfc.
virtual ~BasicHttpAuthConfig()
Destructor.
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.
const BasicHttpAuthMap & getCredentialMap() const
Returns the credential and user id map.
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
Definition: request.h:27
Basic HTTP authentication client configuration.