1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_SERVICE_PERMISSION_PERMIT_DELEGATE_H 16 #define OHOS_DISTRIBUTED_DATA_SERVICES_SERVICE_PERMISSION_PERMIT_DELEGATE_H 17 #include <cstdint> 18 #include <map> 19 #include <string> 20 #include "concurrent_map.h" 21 #include "lru_bucket.h" 22 #include "metadata/store_meta_data.h" 23 #include "store_errno.h" 24 #include "types_export.h" 25 #include "visibility.h" 26 27 namespace OHOS::DistributedData { 28 using Status = OHOS::DistributedKv::Status; 29 using CheckParam = DistributedDB::PermissionCheckParam; 30 using CondParam = DistributedDB::PermissionConditionParam; 31 using ActiveParam = DistributedDB::ActivationCheckParam; 32 33 class PermitDelegate { 34 public: 35 API_EXPORT static PermitDelegate &GetInstance(); 36 API_EXPORT void Init(); 37 API_EXPORT bool SyncActivate(const ActiveParam ¶m); 38 API_EXPORT bool VerifyPermission(const CheckParam ¶m, uint8_t flag); 39 API_EXPORT void DelCache(const std::string &key); 40 API_EXPORT static bool VerifyPermission(const std::string &permission, 41 uint32_t callerTokenId); 42 43 private: 44 PermitDelegate(); 45 ~PermitDelegate(); 46 bool VerifyExtraCondition(const std::map<std::string, std::string> &cond) const; 47 Status VerifyStrategy(const StoreMetaData &data, const std::string &rmdevId) const; 48 Status LoadStoreMeta(const std::string &prefix, const CheckParam ¶m, StoreMetaData &data) const; 49 std::map<std::string, std::string> GetExtraCondition(const CondParam ¶m); 50 51 ConcurrentMap<std::string, std::string> appId2BundleNameMap_; 52 LRUBucket<std::string, StoreMetaData> metaDataBucket_ {32}; 53 static constexpr const char *DEFAULT_USER = "0"; 54 }; 55 } // namespace OHOS::DistributedData 56 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_SERVICE_PERMISSION_PERMIT_DELEGATE_H 57