• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SERVICES_INCLUDE_ACCESSTOKEN_ADAPTER_H
16 #define SERVICES_INCLUDE_ACCESSTOKEN_ADAPTER_H
17 
18 #include <memory>
19 #include <mutex>
20 #include "access_token.h"
21 #include "accesstoken_kit.h"
22 #include "singleton.h"
23 namespace OHOS {
24 namespace WallpaperMgrService {
25 class AccessTokenAdapter {
26 public:
27     virtual ~AccessTokenAdapter() = default;
28     virtual int VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID, const std::string &permissionName) = 0;
29 };
30 
31 class AccessTokenProxy {
32 public:
33     virtual ~AccessTokenProxy() = default;
34     static void Set(std::shared_ptr<AccessTokenAdapter> accessTokenAdapter);
35     static int VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID, const std::string &permissionName);
36 
37 private:
38     static std::shared_ptr<AccessTokenAdapter> accessToken_;
39     static std::mutex mtx;
40 };
41 
42 class AccessTokenImpl : public AccessTokenAdapter {
43 public:
44     AccessTokenImpl() = default;
45     ~AccessTokenImpl() override;
46 
47     int VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID, const std::string &permissionName) override;
48 };
49 } // namespace WallpaperMgrService
50 } // namespace OHOS
51 #endif