| 16 | enum class AccessUpdateType { UpdateUgi = 0, UpdateAuth, UpdateMax }; |
| 17 | |
| 18 | class AccessEntry { |
| 19 | public: |
| 20 | // Provide the object for server related with access control. |
| 21 | explicit AccessEntry(const std::string& auth_policy); |
| 22 | virtual ~AccessEntry() {} |
| 23 | |
| 24 | AccessUpdater& GetAccessUpdater() { return *access_updater_; } |
| 25 | |
| 26 | // Support for verify identity & check permissions |
| 27 | template <class Request, class Response> |
| 28 | bool VerifyAndAuthorize(const Request* const req, Response* res) { |
| 29 | if (auth_policy_type_ == AuthPolicyType::kNoneAuthPolicy) { |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | if (!req->has_identity_info()) { |
| 34 | // TODO: true just for compatibility with old sdk |
| 35 | // Will return false in future |
| 36 | return true; |
| 37 | } |
| 38 | IdentityInfo identity_info = req->identity_info(); |
| 39 | |
| 40 | // InternalGroup means master=>ts rpc |
| 41 | if (identity_info.name() == kInternalGroup) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | if (identity_info.auth_policy_type() != auth_policy_type_) { |
| 46 | std::string policy; |
| 47 | AccessUtils::GetAuthPolicy(identity_info.auth_policy_type(), &policy); |
| 48 | |
| 49 | std::string auth_policy; |
| 50 | AccessUtils::GetAuthPolicy(auth_policy_type_, &auth_policy); |
| 51 | |
| 52 | LOG(ERROR) << "Not the same auth policy between sdk[" << policy << "] with master/ts[" |
| 53 | << auth_policy << "]"; |
| 54 | res->set_status(kMismatchAuthType); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | RoleList roles; |
| 59 | if (!Verify(identity_info, &roles) || !Authorize(roles)) { |
| 60 | res->set_status(kNotPermission); |
| 61 | return false; |
| 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | bool Verify(const IdentityInfo& identity_info, RoleList* roles); |
| 68 | bool Authorize(const RoleList& roles); |
| 69 | |
| 70 | private: |
| 71 | std::string auth_policy_; |
| 72 | AuthPolicyType auth_policy_type_; |
| 73 | std::shared_ptr<Verification> verification_; |
| 74 | std::unique_ptr<AccessUpdater> access_updater_; |
| 75 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected