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 USER_AUTH_SERVICE_H 17 #define USER_AUTH_SERVICE_H 18 19 #include "user_auth_stub.h" 20 21 #include <string> 22 #include <system_ability.h> 23 #include <system_ability_definition.h> 24 25 #include "context_callback.h" 26 #include "context_factory.h" 27 #include "context_pool.h" 28 #include "resource_node_pool.h" 29 #include "user_idm_database.h" 30 31 namespace OHOS { 32 namespace UserIam { 33 namespace UserAuth { 34 class UserAuthService : public SystemAbility, public UserAuthStub, public NoCopyable { 35 public: 36 DECLARE_SYSTEM_ABILITY(UserAuthService); 37 explicit UserAuthService(int32_t systemAbilityId, bool runOnCreate = false); 38 ~UserAuthService() override = default; 39 int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override; 40 void GetProperty(int32_t userId, AuthType authType, 41 const std::vector<Attributes::AttributeKey> &keys, 42 sptr<GetExecutorPropertyCallbackInterface> &callback) override; 43 void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, 44 sptr<SetExecutorPropertyCallbackInterface> &callback) override; 45 uint64_t AuthUser(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType, 46 AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override; 47 uint64_t Auth(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType, 48 AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override; 49 uint64_t AuthWidget(int32_t apiVersion, const AuthParam &authParam, 50 const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback) override; 51 uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType, 52 sptr<UserAuthCallbackInterface> &callback) override; 53 int32_t CancelAuthOrIdentify(uint64_t contextId) override; 54 int32_t GetVersion(int32_t &version) override; 55 int32_t Notice(NoticeType noticeType, const std::string &eventData) override; 56 int32_t RegisterWidgetCallback(int32_t version, sptr<WidgetCallbackInterface> &callback) override; 57 58 protected: 59 void OnStart() override; 60 void OnStop() override; 61 62 private: 63 std::shared_ptr<ContextCallback> GetAuthContextCallback(const std::vector<uint8_t> &challenge, AuthType authType, 64 AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback); 65 std::shared_ptr<ContextCallback> GetAuthContextCallback(const AuthParam &authParam, 66 const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback); 67 ResultCode CheckNorthPermission(AuthType authType); 68 ResultCode CheckServicePermission(AuthType authType); 69 ResultCode CheckWidgetNorthPermission(); 70 ResultCode CheckAuthWidgetParam(const AuthParam &authParam, const WidgetParam &widgetParam); 71 bool Insert2ContextPool(const std::shared_ptr<Context> &context); 72 bool CheckCallerIsSystemApp(); 73 ResultCode CheckParam(const AuthParam &authParam, const WidgetParam &widgetParam); 74 }; 75 } // namespace UserAuth 76 } // namespace UserIam 77 } // namespace OHOS 78 #endif // USER_AUTH_SERVICE_H