• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "context_factory.h"
16 
17 #include "authentication_impl.h"
18 #include "context_callback_impl.h"
19 #include "context_pool.h"
20 #include "enroll_context.h"
21 #include "enrollment_impl.h"
22 #include "iam_check.h"
23 #include "iam_logger.h"
24 #include "iam_ptr.h"
25 #include "identification_impl.h"
26 #include "identify_context.h"
27 #include "simple_auth_context.h"
28 
29 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
30 
31 namespace OHOS {
32 namespace UserIam {
33 namespace UserAuth {
CreateSimpleAuthContext(const AuthContextPara & para,const std::shared_ptr<ContextCallback> & callback)34 std::shared_ptr<Context> ContextFactory::CreateSimpleAuthContext(const AuthContextPara &para,
35     const std::shared_ptr<ContextCallback> &callback)
36 {
37     IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
38     uint64_t newContextId = ContextPool::GetNewContextId();
39     auto auth = Common::MakeShared<AuthenticationImpl>(newContextId, para.userId, para.authType, para.atl);
40     IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr);
41     auth->SetChallenge(para.challenge);
42     auth->SetAccessTokenId(para.tokenId);
43     return Common::MakeShared<SimpleAuthContext>(newContextId, auth, callback);
44 }
45 
CreateIdentifyContext(const IdentifyContextPara & para,const std::shared_ptr<ContextCallback> & callback)46 std::shared_ptr<Context> ContextFactory::CreateIdentifyContext(const IdentifyContextPara &para,
47     const std::shared_ptr<ContextCallback> &callback)
48 {
49     IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
50     uint64_t newContextId = ContextPool::GetNewContextId();
51     auto identify = Common::MakeShared<IdentificationImpl>(newContextId, para.authType);
52     IF_FALSE_LOGE_AND_RETURN_VAL(identify != nullptr, nullptr);
53     identify->SetChallenge(para.challenge);
54     identify->SetAccessTokenId(para.tokenId);
55     return Common::MakeShared<IdentifyContext>(newContextId, identify, callback);
56 }
57 
CreateEnrollContext(const EnrollContextPara & para,const std::shared_ptr<ContextCallback> & callback)58 std::shared_ptr<Context> ContextFactory::CreateEnrollContext(const EnrollContextPara &para,
59     const std::shared_ptr<ContextCallback> &callback)
60 {
61     IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
62     uint64_t newContextId = ContextPool::GetNewContextId();
63     auto enroll = Common::MakeShared<EnrollmentImpl>(para.userId, para.authType);
64     IF_FALSE_LOGE_AND_RETURN_VAL(enroll != nullptr, nullptr);
65     enroll->SetAuthToken(para.token);
66     enroll->SetAccessTokenId(para.tokenId);
67     enroll->SetPinSubType(para.pinType);
68     return Common::MakeShared<EnrollContext>(newContextId, enroll, callback);
69 }
70 
CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback)71 std::shared_ptr<Context> ContextFactory::CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback)
72 {
73     return nullptr;
74 }
75 } // namespace UserAuth
76 } // namespace UserIam
77 } // namespace OHOS
78