• 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 
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_pool.h"
27 #include "resource_node_pool.h"
28 #include "user_idm_database.h"
29 
30 namespace OHOS {
31 namespace UserIam {
32 namespace UserAuth {
33 class UserAuthService : public SystemAbility, public UserAuthStub, public NoCopyable {
34 public:
35     DECLARE_SYSTEM_ABILITY(UserAuthService);
36     explicit UserAuthService(int32_t systemAbilityId, bool runOnCreate = false);
37     ~UserAuthService() override = default;
38     void OnStart() override;
39     void OnStop() override;
40     int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override;
41     void GetProperty(int32_t userId, AuthType authType,
42         const std::vector<Attributes::AttributeKey> &keys,
43         sptr<GetExecutorPropertyCallbackInterface> &callback) override;
44     void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes,
45         sptr<SetExecutorPropertyCallbackInterface> &callback) override;
46     uint64_t AuthUser(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType,
47         AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override;
48     uint64_t Auth(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType,
49         AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override;
50     uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType,
51         sptr<UserAuthCallbackInterface> &callback) override;
52     int32_t CancelAuthOrIdentify(uint64_t contextId) override;
53     int32_t GetVersion(int32_t &version) override;
54 
55 private:
56     std::shared_ptr<ContextCallback> GetAuthContextCallback(const std::vector<uint8_t> &challenge, AuthType authType,
57         AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback);
58     bool CheckAuthPermission(bool isInnerCaller, AuthType authType);
59     ResultCode CheckNorthPermission(AuthType authType);
60     ResultCode CheckServicePermission(AuthType authType);
61 };
62 } // namespace UserAuth
63 } // namespace UserIam
64 } // namespace OHOS
65 #endif // USER_AUTH_SERVICE_H