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
22 #define LOG_TAG "USER_ACCESS_CTRL_SDK"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
VerifyTokenCallbackService(const std::shared_ptr<VerifyTokenCallback> & impl)27 VerifyTokenCallbackService::VerifyTokenCallbackService(
28 const std::shared_ptr<VerifyTokenCallback> &impl) : verifyTokenCallback_(impl)
29 {
30 CallbackManager::CallbackAction action = [impl]() {
31 if (impl != nullptr) {
32 IAM_LOGI("user access ctrl service death, return default verify token result to caller");
33 Attributes extraInfo;
34 impl->OnResult(GENERAL_ERROR, extraInfo);
35 }
36 };
37 CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
38 }
39
~VerifyTokenCallbackService()40 VerifyTokenCallbackService::~VerifyTokenCallbackService()
41 {
42 CallbackManager::GetInstance().RemoveCallback(reinterpret_cast<uintptr_t>(this));
43 }
44
OnVerifyTokenResult(int32_t result,const Attributes & attributes)45 void VerifyTokenCallbackService::OnVerifyTokenResult(int32_t result, const Attributes &attributes)
46 {
47 IAM_LOGI("start, verify token result: %{public}d", result);
48 if (verifyTokenCallback_ == nullptr) {
49 IAM_LOGE("verifyTokenCallback is nullptr");
50 return;
51 }
52
53 verifyTokenCallback_->OnResult(result, attributes);
54 }
55 } // namespace UserAuth
56 } // namespace UserIam
57 } // namespace OHOS