1 /* 2 * Copyright (c) 2022-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 #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 WidgetParamInner widgetParam {}; 54 std::map<AuthType, AuthProfile> authProfileMap {}; 55 int32_t callerType {0}; 56 std::string callingAppID {""}; 57 bool isPinExpired {false}; 58 bool isOsAccountVerified {false}; 59 bool isBackgroundApplication {false}; 60 }; 61 62 static std::shared_ptr<Context> CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶, 63 const std::shared_ptr<ContextCallback> &callback, bool needSubscribeAppState); 64 static std::shared_ptr<Context> CreateRemoteAuthContext(const Authentication::AuthenticationPara ¶, 65 RemoteAuthContextParam &remoteAuthContextParam, const std::shared_ptr<ContextCallback> &callback); 66 static std::shared_ptr<Context> CreateRemoteAuthInvokerContext(AuthParamInner authParam, 67 RemoteAuthInvokerContextParam param, std::shared_ptr<ContextCallback> callback); 68 static std::shared_ptr<Context> CreateIdentifyContext(const Identification::IdentificationPara ¶, 69 const std::shared_ptr<ContextCallback> &callback); 70 static std::shared_ptr<Context> CreateEnrollContext(const Enrollment::EnrollmentPara ¶, 71 const std::shared_ptr<ContextCallback> &callback, bool needSubscribeAppState); 72 static std::shared_ptr<Context> CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback); 73 static std::shared_ptr<Context> CreateWidgetContext(const AuthWidgetContextPara ¶, 74 std::shared_ptr<ContextCallback> callback); 75 static std::shared_ptr<Context> CreateScheduleHolderContext(std::shared_ptr<ScheduleNode> scheduleNode); 76 }; 77 } // namespace UserAuth 78 } // namespace UserIam 79 } // namespace OHOS 80 #endif // IAM_CONTEXT_FACTORY_H