/* * 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 "authentication_impl.h" #include "context_callback_impl.h" #include "context_pool.h" #include "enroll_context.h" #include "enrollment_impl.h" #include "iam_check.h" #include "iam_logger.h" #include "iam_ptr.h" #include "identification_impl.h" #include "identify_context.h" #include "simple_auth_context.h" #include "widget_context.h" #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA namespace OHOS { namespace UserIam { namespace UserAuth { std::shared_ptr ContextFactory::CreateSimpleAuthContext(const AuthContextPara ¶, 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.userId, para.authType, para.atl); 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 IdentifyContextPara ¶, 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 EnrollContextPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); auto enroll = Common::MakeShared(para.userId, para.authType); 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); } } // namespace UserAuth } // namespace UserIam } // namespace OHOS