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 16 #ifndef ACCESSTOKEN_TOKEN_REMOTE_TOKEN_MANAGER_H 17 #define ACCESSTOKEN_TOKEN_REMOTE_TOKEN_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <vector> 22 23 #include "access_token.h" 24 #include "hap_token_info.h" 25 #include "hap_token_info_inner.h" 26 #include "nocopyable.h" 27 #include "rwlock.h" 28 29 namespace OHOS { 30 namespace Security { 31 namespace AccessToken { 32 class AccessTokenRemoteDevice final { 33 public: 34 std::string deviceID_; // networkID 35 std::map<AccessTokenID, AccessTokenID> MappingTokenIDPairMap_; 36 }; 37 38 class AccessTokenRemoteTokenManager final { 39 public: 40 static AccessTokenRemoteTokenManager& GetInstance(); 41 ~AccessTokenRemoteTokenManager(); 42 AccessTokenID MapRemoteDeviceTokenToLocal(const std::string& deviceID, AccessTokenID remoteID); 43 int GetDeviceAllRemoteTokenID(const std::string& deviceID, std::vector<AccessTokenID>& mapIDs); 44 AccessTokenID GetDeviceMappingTokenID(const std::string& deviceID, AccessTokenID remoteID); 45 int RemoveDeviceMappingTokenID(const std::string& deviceID, AccessTokenID remoteID); 46 47 private: 48 AccessTokenRemoteTokenManager(); 49 DISALLOW_COPY_AND_MOVE(AccessTokenRemoteTokenManager); 50 51 OHOS::Utils::RWLock remoteDeviceLock_; 52 std::map<std::string, AccessTokenRemoteDevice> remoteDeviceMap_; 53 }; 54 } // namespace AccessToken 55 } // namespace Security 56 } // namespace OHOS 57 #endif // ACCESSTOKEN_TOKEN_REMOTE_TOKEN_MANAGER_H 58 59