7684972a | /* Copyright (C) CJ Affiliate * * You may use, distribute and modify this code under the * terms of the GNU General Public License version 2 or * later. * * You should have received a copy of the license with this * file. If not, you will find a copy in the "LICENSE" file * at https://github.com/cjdev/dual-control. */ |
f757e35b | #include <string> |
28855478 | #include <vector> |
f757e35b | #include "validator.h" |
ee12703f | namespace { |
28855478 | class impl : public validator_ifc { private: directory directory_; |
e064ffa9 | tokens tokens_; |
28855478 | public: impl (const directory &directory, |
e064ffa9 | const tokens tokens) : |
28855478 | directory_ (directory), |
e064ffa9 | tokens_ (tokens) {} |
6ff7d0a7 | bool validate (const std::string &requester_user_name, const std::string &authorizer_user_name, |
044b2625 | const std::string &token, const std::string &reason) override |
28855478 | { |
6ff7d0a7 | std::vector<user> found_user = directory_.find_user (authorizer_user_name); |
044b2625 | if (reason.empty()) { return false; } |
39b6d4a1 | if (requester_user_name.empty()) { return false; } |
6ff7d0a7 | if (requester_user_name == authorizer_user_name) { return false; } |
28855478 | if (found_user.empty()) { return false; |
ee12703f | } |
e064ffa9 | std::string user_token = tokens_.token (found_user[0]); |
28855478 | return user_token == token; } }; |
ee12703f | } |
da1b9b25 | validator validator::create (const directory &directory, |
e064ffa9 | const tokens &tokens) |
cdf7fd74 | { |
28855478 | std::shared_ptr<validator_ifc> delegate (new impl (directory, |
e064ffa9 | tokens)); |
28855478 | return validator (delegate); |
f757e35b | } |