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 #include "accesstoken_adapter.h"
17 #include "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace WallpaperMgrService {
21 std::shared_ptr<AccessTokenAdapter> AccessTokenProxy::accessToken_ = nullptr;
22 std::mutex AccessTokenProxy::mtx;
Set(std::shared_ptr<AccessTokenAdapter> accessTokenAdapter)23 void AccessTokenProxy::Set(std::shared_ptr<AccessTokenAdapter> accessTokenAdapter)
24 {
25 HILOG_INFO("AccessTokenProxy Set.");
26 std::lock_guard<std::mutex> lock(mtx);
27 accessToken_ = accessTokenAdapter;
28 }
29
VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID,const std::string & permissionName)30 int AccessTokenProxy::VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID, const std::string &permissionName)
31 {
32 std::lock_guard<std::mutex> lock(mtx);
33 if (accessToken_ == nullptr) {
34 accessToken_ = std::make_shared<AccessTokenImpl>();
35 }
36 return accessToken_->VerifyAccessToken(tokenID, permissionName);
37 }
38
~AccessTokenImpl()39 AccessTokenImpl::~AccessTokenImpl()
40 {
41 }
42
VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID,const std::string & permissionName)43 int AccessTokenImpl::VerifyAccessToken(Security::AccessToken::AccessTokenID tokenID, const std::string &permissionName)
44 {
45 HILOG_INFO("Enter VerifyAccessToken.");
46 return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenID, permissionName);
47 }
48 } // namespace WallpaperMgrService
49 } // namespace OHOS
50