1 /* 2 * Copyright (c) 2022-2023 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 #ifndef IAM_CONTEXT_FACTORY_H 17 #define IAM_CONTEXT_FACTORY_H 18 19 #include <cstdint> 20 #include <map> 21 #include <memory> 22 #include <string> 23 24 #include "singleton.h" 25 #include "authentication_impl.h" 26 #include "enrollment_impl.h" 27 #include "context.h" 28 #include "context_callback.h" 29 #include "identification_impl.h" 30 #include "remote_auth_context.h" 31 #include "remote_auth_invoker_context.h" 32 33 namespace OHOS { 34 namespace UserIam { 35 namespace UserAuth { 36 class ContextFactory : public DelayedSingleton<ContextFactory> { 37 public: 38 struct AuthProfile { 39 int32_t pinSubType {0}; 40 std::string sensorInfo {""}; 41 int32_t remainTimes {0}; 42 int32_t freezingTime {0}; 43 }; 44 45 struct AuthWidgetContextPara { 46 int32_t userId {INVALID_USER_ID}; 47 int32_t sdkVersion {0}; 48 uint32_t tokenId {0}; 49 std::string callerName {""}; 50 std::vector<uint8_t> challenge {}; 51 std::vector<AuthType> authTypeList {}; 52 AuthTrustLevel atl {ATL1}; 53 WidgetParam widgetParam {}; 54 std::map<AuthType, AuthProfile> authProfileMap {}; 55 int32_t callerType {0}; 56 bool isPinExpired {false}; 57 std::string callingAppID {""}; 58 bool isOsAccountVerified {false}; 59 }; 60 61 static std::shared_ptr<Context> CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶, 62 const std::shared_ptr<ContextCallback> &callback); 63 static std::shared_ptr<Context> CreateRemoteAuthContext(const Authentication::AuthenticationPara ¶, 64 RemoteAuthContextParam &remoteAuthContextParam, const std::shared_ptr<ContextCallback> &callback); 65 static std::shared_ptr<Context> CreateRemoteAuthInvokerContext(AuthParamInner authParam, 66 RemoteAuthInvokerContextParam param, std::shared_ptr<ContextCallback> callback); 67 static std::shared_ptr<Context> CreateIdentifyContext(const Identification::IdentificationPara ¶, 68 const std::shared_ptr<ContextCallback> &callback); 69 static std::shared_ptr<Context> CreateEnrollContext(const Enrollment::EnrollmentPara ¶, 70 const std::shared_ptr<ContextCallback> &callback); 71 static std::shared_ptr<Context> CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback); 72 static std::shared_ptr<Context> CreateWidgetContext(const AuthWidgetContextPara ¶, 73 std::shared_ptr<ContextCallback> callback); 74 static std::shared_ptr<Context> CreateScheduleHolderContext(std::shared_ptr<ScheduleNode> scheduleNode); 75 }; 76 } // namespace UserAuth 77 } // namespace UserIam 78 } // namespace OHOS 79 #endif // IAM_CONTEXT_FACTORY_H