1 /* 2 * Copyright (c) 2021-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 16 #include "account_permission_manager.h" 17 18 #include "accesstoken_kit.h" 19 #include "account_log_wrapper.h" 20 #include "ipc_skeleton.h" 21 22 using namespace OHOS::Security::AccessToken; 23 24 namespace OHOS { 25 namespace AccountSA { 26 const std::string AccountPermissionManager::DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC"; 27 const std::string AccountPermissionManager::GET_ALL_APP_ACCOUNTS = "ohos.permission.GET_ALL_APP_ACCOUNTS"; 28 const std::string AccountPermissionManager::MANAGE_LOCAL_ACCOUNTS = "ohos.permission.MANAGE_LOCAL_ACCOUNTS"; 29 const std::string AccountPermissionManager::INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION = 30 "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION"; 31 const std::string AccountPermissionManager::INTERACT_ACROSS_LOCAL_ACCOUNTS = 32 "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; 33 const std::string AccountPermissionManager::ACCESS_USER_AUTH_INTERNAL = "ohos.permission.ACCESS_USER_AUTH_INTERNAL"; 34 const std::string AccountPermissionManager::MANAGE_USER_IDM = "ohos.permission.MANAGE_USER_IDM"; 35 const std::string AccountPermissionManager::USE_USER_IDM = "ohos.permission.USE_USER_IDM"; 36 AccountPermissionManager()37AccountPermissionManager::AccountPermissionManager() 38 {} 39 ~AccountPermissionManager()40AccountPermissionManager::~AccountPermissionManager() 41 {} 42 VerifyPermission(const std::string & permissionName)43ErrCode AccountPermissionManager::VerifyPermission(const std::string &permissionName) 44 { 45 AccessTokenID callingToken = IPCSkeleton::GetCallingTokenID(); 46 ErrCode result = AccessTokenKit::VerifyAccessToken(callingToken, permissionName); 47 if (result == TypePermissionState::PERMISSION_DENIED) { 48 return ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR; 49 } 50 return ERR_OK; 51 } 52 } // namespace AccountSA 53 } // namespace OHOS 54