/* 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. */ #include #include #include "validator.h" namespace { class impl : public validator_ifc { private: directory directory_; user_token_supplier user_token_supplier_; public: impl (const directory &directory, const user_token_supplier user_token_supplier) : directory_ (directory), user_token_supplier_ (user_token_supplier) {} bool validate (const std::string &requester_user_name, const std::string &authorizer_user_name, const std::string &token) { std::vector found_user = directory_.find_user (authorizer_user_name); if (requester_user_name.empty()) { return false; } if (requester_user_name == authorizer_user_name) { return false; } if (found_user.empty()) { return false; } std::string user_token = user_token_supplier_.token (found_user[0]); return user_token == token; } }; } validator validator::create (const directory &directory, const user_token_supplier &user_token_supplier) { std::shared_ptr delegate (new impl (directory, user_token_supplier)); return validator (delegate); }