/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "context_factory.h" #include "context_callback_impl.h" #include "context_pool.h" #include "enroll_context.h" #include "iam_check.h" #include "iam_logger.h" #include "iam_ptr.h" #include "identify_context.h" #include "simple_auth_context.h" #include "schedule_holder_context.h" #include "widget_context.h" #include "remote_msg_util.h" #define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { namespace UserAuth { std::shared_ptr ContextFactory::CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); auto auth = Common::MakeShared(newContextId, para); IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr); auth->SetChallenge(para.challenge); auth->SetAccessTokenId(para.tokenId); auth->SetEndAfterFirstFail(para.endAfterFirstFail); return Common::MakeShared(newContextId, auth, callback); } std::shared_ptr ContextFactory::CreateIdentifyContext(const Identification::IdentificationPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); auto identify = Common::MakeShared(newContextId, para.authType); IF_FALSE_LOGE_AND_RETURN_VAL(identify != nullptr, nullptr); identify->SetChallenge(para.challenge); identify->SetAccessTokenId(para.tokenId); return Common::MakeShared(newContextId, identify, callback); } std::shared_ptr ContextFactory::CreateEnrollContext(const Enrollment::EnrollmentPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); auto enroll = Common::MakeShared(para); IF_FALSE_LOGE_AND_RETURN_VAL(enroll != nullptr, nullptr); enroll->SetAuthToken(para.token); enroll->SetAccessTokenId(para.tokenId); enroll->SetPinSubType(para.pinType); enroll->SetIsUpdate(para.isUpdate); return Common::MakeShared(newContextId, enroll, callback); } std::shared_ptr ContextFactory::CreateWidgetAuthContext(std::shared_ptr callback) { return nullptr; } std::shared_ptr ContextFactory::CreateWidgetContext(const AuthWidgetContextPara ¶, std::shared_ptr callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); return Common::MakeShared(newContextId, para, callback); } std::shared_ptr ContextFactory::CreateRemoteAuthContext(const Authentication::AuthenticationPara ¶, RemoteAuthContextParam &remoteAuthContextParam, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); auto auth = Common::MakeShared(newContextId, para); IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr); auth->SetChallenge(para.challenge); auth->SetAccessTokenId(para.tokenId); if (remoteAuthContextParam.connectionName == "") { bool getConnectionNameRet = RemoteMsgUtil::GetConnectionName(newContextId, remoteAuthContextParam.connectionName); IF_FALSE_LOGE_AND_RETURN_VAL(getConnectionNameRet, nullptr); } return Common::MakeShared(newContextId, auth, remoteAuthContextParam, callback); } std::shared_ptr ContextFactory::CreateRemoteAuthInvokerContext(AuthParamInner authParam, RemoteAuthInvokerContextParam param, std::shared_ptr callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); bool getConnectionNameRet = RemoteMsgUtil::GetConnectionName(newContextId, param.connectionName); IF_FALSE_LOGE_AND_RETURN_VAL(getConnectionNameRet, nullptr); return Common::MakeShared(newContextId, authParam, param, callback); } std::shared_ptr ContextFactory::CreateScheduleHolderContext(std::shared_ptr scheduleNode) { uint64_t newContextId = ContextPool::GetNewContextId(); return Common::MakeShared(newContextId, scheduleNode); } } // namespace UserAuth } // namespace UserIam } // namespace OHOS