• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "user_access_ctrl_callback_service.h"
17 
18 #include "callback_manager.h"
19 #include "iam_logger.h"
20 #include "iam_ptr.h"
21 #include "iam_common_defines.h"
22 
23 #define LOG_TAG "USER_ACCESS_CTRL_SDK"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
VerifyTokenCallbackService(const std::shared_ptr<VerifyTokenCallback> & impl)28 VerifyTokenCallbackService::VerifyTokenCallbackService(
29     const std::shared_ptr<VerifyTokenCallback> &impl) : verifyTokenCallback_(impl)
30 {
31     CallbackManager::CallbackAction action = [impl]() {
32         if (impl != nullptr) {
33             IAM_LOGI("user access ctrl service death, return default verify token result to caller");
34             Attributes extraInfo;
35             impl->OnResult(GENERAL_ERROR, extraInfo);
36         }
37     };
38     CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
39 }
40 
~VerifyTokenCallbackService()41 VerifyTokenCallbackService::~VerifyTokenCallbackService()
42 {
43     CallbackManager::GetInstance().RemoveCallback(reinterpret_cast<uintptr_t>(this));
44 }
45 
OnVerifyTokenResult(int32_t resultCode,const std::vector<uint8_t> & extraInfo)46 int32_t VerifyTokenCallbackService::OnVerifyTokenResult(int32_t resultCode, const std::vector<uint8_t> &extraInfo)
47 {
48     IAM_LOGI("start, verify token result: %{public}d", resultCode);
49     if (verifyTokenCallback_ == nullptr) {
50         IAM_LOGE("verifyTokenCallback is nullptr");
51         return GENERAL_ERROR;
52     }
53     Attributes attributes(extraInfo);
54     verifyTokenCallback_->OnResult(resultCode, attributes);
55     return SUCCESS;
56 }
57 
CallbackEnter(uint32_t code)58 int32_t VerifyTokenCallbackService::CallbackEnter([[maybe_unused]] uint32_t code)
59 {
60     IAM_LOGI("start, code:%{public}u", code);
61     return SUCCESS;
62 }
63 
CallbackExit(uint32_t code,int32_t result)64 int32_t VerifyTokenCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
65 {
66     IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result);
67     return SUCCESS;
68 }
69 } // namespace UserAuth
70 } // namespace UserIam
71 } // namespace OHOS