diff --git a/README_ZH.md b/README_ZH.md index 0ea3e87..8b00e6c 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -49,7 +49,7 @@ | 接口名 | 描述 | | ------ | -------------------------------- | -| getAuthInfo(callback : AsyncCallback>,authType? : AuthType) : void; | 信息查询 接口,支持查询用户录入的一类或全部类型认证凭据 | +| getAuthInfo(callback : AsyncCallback>,authType? : AuthType) : void; | 信息查询接口,支持查询用户录入的一类或全部类型认证凭据 | ### 使用说明 diff --git a/interfaces/innerkits/include/iuser_idm.h b/interfaces/innerkits/include/iuser_idm.h index 1fcd017..308e541 100644 --- a/interfaces/innerkits/include/iuser_idm.h +++ b/interfaces/innerkits/include/iuser_idm.h @@ -24,17 +24,100 @@ namespace UserIDM { class IUserIDM : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.useridm.IUserIDM"); + + /* + * start an IDM operation to obtain challenge value, a challenge value of 0 indicates that opensession failed. + * + * return uint8Array is success or fail. + */ virtual uint64_t OpenSession() = 0; + + /* + * end an IDM operation. + */ virtual void CloseSession() = 0; + + /* + * get authentication information. + * + * param authType credential type. + * param callback returns all registered credential information of this type for the current user. + */ virtual int32_t GetAuthInfo(AuthType authType, const sptr& callback) = 0; + + /* + * get authentication information. + * + * param userId current user id. + * param authType credential type. + * param callback returns all registered credential information of this type for the current user. + */ virtual int32_t GetAuthInfo(int32_t userId, AuthType authType, const sptr& callback) = 0; + + /* + * get user security ID. + * + * param userId current user id. + * param callback returns all registered security information for the current user. + */ virtual int32_t GetSecInfo(int32_t userId, const sptr& callback) = 0; + + /** + * add user credential information, pass in credential addition method and credential information + * (credential type, subtype, if adding user's non password credentials, pass in password authentication token), + * and get the result / acquireinfo callback. + * + * param credInfo Incoming credential addition method and credential information + * (credential type, subtype, password authentication token). + * param callback get results / acquireinfo callback. + */ virtual void AddCredential(AddCredInfo& credInfo, const sptr& callback) = 0; + + /* + * update user credential information. + * + * param credInfo Incoming credential addition method and credential information + * (credential type, subtype, password authentication token). + * param callback update results / acquireinfo callback. + */ virtual void UpdateCredential(AddCredInfo& credInfo, const sptr& callback) = 0; + + /* + * Cancel entry and pass in challenge value. + * + * param challenge challenge value. + */ virtual int32_t Cancel(uint64_t challenge) = 0; + + /* + * enforce delete the user credential information, pass in the user password authentication token and callback, + * and obtain the deletion result through the callback. + * + * param authToken user password authentication token. + * param callback get deletion result through callback. + */ virtual int32_t EnforceDelUser(int32_t userId, const sptr& callback) = 0; + + /* + * delete the user credential information, pass in the user password authentication token and callback, + * and obtain the deletion result through the callback. + * + * param authToken user password authentication token. + * param callback get deletion result through callback. + */ virtual void DelUser(std::vector authToken, const sptr& callback) = 0; - virtual void DelCred(uint64_t credentialId, std::vector authToken, const sptr& callback) = 0; + + /* + * delete the user credential information, pass in the credential id, password authentication token and callback, + * and obtain the deletion result through the callback. + * Only deleting non password credentials is supported. + * + * param credentialId credential index. + * param authToken password authentication token. + * param callback get deletion result through callback. + */ + virtual void DelCred(uint64_t credentialId, std::vector authToken, + const sptr& callback) = 0; enum { USERIDM_OPEN_SESSION = 0, diff --git a/interfaces/innerkits/include/iuseridm_callback.h b/interfaces/innerkits/include/iuseridm_callback.h index b35f043..f9ebc34 100644 --- a/interfaces/innerkits/include/iuseridm_callback.h +++ b/interfaces/innerkits/include/iuseridm_callback.h @@ -24,6 +24,9 @@ namespace UserIAM { namespace UserIDM { class IGetInfoCallback : public IRemoteBroker { public: + /* + * return all registered credential information. + */ virtual void OnGetInfo(std::vector &info) = 0; enum { @@ -35,6 +38,9 @@ public: class IGetSecInfoCallback : public IRemoteBroker { public: + /* + * return all registered security information. + */ virtual void OnGetSecInfo(SecInfo &info) = 0; enum { @@ -46,7 +52,15 @@ public: class IIDMCallback : public IRemoteBroker { public: + + /* + * return result code and additional information through callback. + */ virtual void OnResult(int32_t result, RequestResult reqRet) = 0; + + /* + * return result code and additional information through acquireinfo. + */ virtual void OnAcquireInfo(int32_t module, int32_t acquire, RequestResult reqRet) = 0; enum { diff --git a/interfaces/kits/napi/include/auth_common.h b/interfaces/kits/napi/include/auth_common.h index c10ecc6..d8751c1 100644 --- a/interfaces/kits/napi/include/auth_common.h +++ b/interfaces/kits/napi/include/auth_common.h @@ -31,7 +31,7 @@ public: static std::vector GetNamedAttribute(napi_env env, napi_value obj); static napi_status JudgeObjectType(napi_env env, napi_callback_info info, AsyncCallbackContext* asyncCallbackContext); - static std::vector JudgeArryType(napi_env env, size_t argc, napi_value* argv); + static std::vector JudgeArrayType(napi_env env, size_t argc, napi_value* argv); static void JudgeDelUserType(napi_env env, napi_callback_info info, AsyncCallbackContext* asyncCallbackContext); static void JudgeDelCredType(napi_env env, napi_callback_info info, AsyncCallbackContext* asyncCallbackContext); static void SaveCallback(napi_env env, size_t argc, napi_value* argv, AsyncCallbackContext* asyncCallbackContext); diff --git a/interfaces/kits/napi/src/auth_common.cpp b/interfaces/kits/napi/src/auth_common.cpp index 04666e9..4151480 100644 --- a/interfaces/kits/napi/src/auth_common.cpp +++ b/interfaces/kits/napi/src/auth_common.cpp @@ -197,9 +197,9 @@ void AuthCommon::JudgeDelUserType(napi_env env, napi_callback_info info, AsyncCa USERIDM_HILOGE(MODULE_JS_NAPI, "napi_get_cb_info failed"); return; } - asyncCallbackContext->token = JudgeArryType(env, ZERO_PARAMETER, argv); + asyncCallbackContext->token = JudgeArrayType(env, ZERO_PARAMETER, argv); if (asyncCallbackContext->token.empty()) { - USERIDM_HILOGE(MODULE_JS_NAPI, "JudgeArryType token failed"); + USERIDM_HILOGE(MODULE_JS_NAPI, "JudgeArrayType token failed"); asyncCallbackContext->token.push_back(0); } SaveCallback(env, ONE_PARAMETER, argv, asyncCallbackContext); @@ -216,20 +216,20 @@ void AuthCommon::JudgeDelCredType(napi_env env, napi_callback_info info, AsyncCa USERIDM_HILOGE(MODULE_JS_NAPI, "napi_get_cb_info failed"); return; } - asyncCallbackContext->credentialId = JudgeArryType(env, ZERO_PARAMETER, argv); + asyncCallbackContext->credentialId = JudgeArrayType(env, ZERO_PARAMETER, argv); if (asyncCallbackContext->credentialId.empty()) { - USERIDM_HILOGE(MODULE_JS_NAPI, "JudgeArryType credentialId failed"); + USERIDM_HILOGE(MODULE_JS_NAPI, "JudgeArrayType credentialId failed"); return; } - asyncCallbackContext->token = JudgeArryType(env, ONE_PARAMETER, argv); + asyncCallbackContext->token = JudgeArrayType(env, ONE_PARAMETER, argv); if (asyncCallbackContext->token.empty()) { - USERIDM_HILOGE(MODULE_JS_NAPI, "JudgeArryType token failed"); + USERIDM_HILOGE(MODULE_JS_NAPI, "JudgeArrayType token failed"); return; } SaveCallback(env, TWO_PARAMETER, argv, asyncCallbackContext); } -std::vector AuthCommon::JudgeArryType(napi_env env, size_t argc, napi_value* argv) +std::vector AuthCommon::JudgeArrayType(napi_env env, size_t argc, napi_value* argv) { USERIDM_HILOGI(MODULE_JS_NAPI, "%{public}s, start", __func__); std::vector retNull = {0}; diff --git a/interfaces/kits/napi/src/useridentity_manager.cpp b/interfaces/kits/napi/src/useridentity_manager.cpp index eda5f71..c06c219 100644 --- a/interfaces/kits/napi/src/useridentity_manager.cpp +++ b/interfaces/kits/napi/src/useridentity_manager.cpp @@ -47,6 +47,9 @@ napi_value UserIdentityManager::NAPI_OpenSession(napi_env env, napi_callback_inf } napi_value ret = OpenSessionWrap(env, info, asyncInfo); if (ret == nullptr) { + if (asyncInfo->callback != nullptr) { + napi_delete_reference(env, asyncInfo->callback); + } if (asyncInfo != nullptr) { delete asyncInfo; asyncInfo = nullptr; @@ -377,7 +380,7 @@ napi_value UserIdentityManager::NAPI_Cancel(napi_env env, napi_callback_info inf syncCancelContext->env = env; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - syncCancelContext->challenge = AuthCommon::JudgeArryType(env, ZERO_PARAMETER, argv); + syncCancelContext->challenge = AuthCommon::JudgeArrayType(env, ZERO_PARAMETER, argv); if (syncCancelContext->challenge.empty() || syncCancelContext->challenge.size() < sizeof(uint64_t)) { USERIDM_HILOGE(MODULE_JS_NAPI, "syncCancelContext->challenge is null or size is wrong!"); delete syncCancelContext; @@ -565,6 +568,9 @@ napi_value UserIdentityManager::NAPI_GetAuthInfo(napi_env env, napi_callback_inf napi_value ret = GetAuthInfoWrap(env, info, asyncHolder); if (ret == nullptr) { USERIDM_HILOGE(MODULE_JS_NAPI, "NAPI_GetAuthInfo GetAuthInfoWrap fail"); + if (asyncGetAuthInfo->callback != nullptr) { + napi_delete_reference(env, asyncGetAuthInfo->callback); + } delete asyncGetAuthInfo; if (asyncHolder->asyncWork != nullptr) { napi_delete_async_work(env, asyncHolder->asyncWork); @@ -710,7 +716,7 @@ extern "C" __attribute__((constructor)) void RegisterModule(void) .nm_filename = nullptr, .nm_register_func = Init, .nm_modname = "UserIDM", - .nm_priv = (reinterpret_cast(0)), + .nm_priv = nullptr, .reserved = {0} }; napi_module_register(&module); diff --git a/services/include/useridm_adapter.h b/services/include/useridm_adapter.h index db86af5..3aedc1b 100644 --- a/services/include/useridm_adapter.h +++ b/services/include/useridm_adapter.h @@ -29,7 +29,7 @@ public: void CloseEditSession(); int32_t QueryCredential(int32_t userId, AuthType authType, std::vector& credInfos); int32_t GetSecureUid(int32_t userId, uint64_t& secureUid, std::vector& enrolledInfos); - int32_t InitSchedulation(std::vector autoToken, int32_t userId, AuthType authType, + int32_t InitSchedule(std::vector autoToken, int32_t userId, AuthType authType, AuthSubType authSubType, uint64_t& sessionId); int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector authToken, CredentialInfo& credInfo); diff --git a/services/src/useridm_adapter.cpp b/services/src/useridm_adapter.cpp index 86a80d6..5f1b7b8 100644 --- a/services/src/useridm_adapter.cpp +++ b/services/src/useridm_adapter.cpp @@ -92,10 +92,10 @@ int32_t UserIDMAdapter::GetSecureUid(int32_t userId, uint64_t& secureUid, return ret; } -int32_t UserIDMAdapter::InitSchedulation(std::vector autoToken, int32_t userId, AuthType authType, +int32_t UserIDMAdapter::InitSchedule(std::vector autoToken, int32_t userId, AuthType authType, AuthSubType authSubType, uint64_t& sessionId) { - USERIDM_HILOGD(MODULE_SERVICE, "UserIDMAdapter InitSchedulation start"); + USERIDM_HILOGD(MODULE_SERVICE, "UserIDMAdapter InitSchedule start"); int32_t ret = OHOS::UserIAM::UserIDM::Hal::InitSchedulation(autoToken, userId, authType, authSubType, sessionId); USERIDM_HILOGI(MODULE_SERVICE, "Call TA info: GetScheduleId: %{public}d", ret); return ret; diff --git a/services/src/useridm_controller.cpp b/services/src/useridm_controller.cpp index 50fc907..ddf1843 100644 --- a/services/src/useridm_controller.cpp +++ b/services/src/useridm_controller.cpp @@ -160,12 +160,12 @@ int32_t UserIDMController::AddCredentialCtrl(int32_t userId, uint64_t callerID, innerkitsCallback->OnResult(BUSY, reqRet); return BUSY; } - int32_t ret = UserIDMAdapter::GetInstance().InitSchedulation(credInfo.token, userId, credInfo.authType, + int32_t ret = UserIDMAdapter::GetInstance().InitSchedule(credInfo.token, userId, credInfo.authType, credInfo.authSubType, scheduleId); if (ret == SUCCESS) { ret = AddCredentialCallCoauth(callerID, credInfo, innerkitsCallback, challenge, scheduleId); } else { - USERIDM_HILOGE(MODULE_SERVICE, "call TA info: InitSchedulation failed"); + USERIDM_HILOGE(MODULE_SERVICE, "call TA info: InitSchedule failed"); RequestResult reqRet; innerkitsCallback->OnResult(FAIL, reqRet); } @@ -197,10 +197,10 @@ int32_t UserIDMController::UpdateCredentialCtrl(int32_t userId, uint64_t callerI innerkitsCallback->OnResult(BUSY, reqRet); return BUSY; } - int32_t ret = UserIDMAdapter::GetInstance().InitSchedulation(credInfo.token, userId, credInfo.authType, + int32_t ret = UserIDMAdapter::GetInstance().InitSchedule(credInfo.token, userId, credInfo.authType, credInfo.authSubType, scheduleId); if (ret == SUCCESS) { - USERIDM_HILOGI(MODULE_SERVICE, "InitSchedulation SUCCESS"); + USERIDM_HILOGI(MODULE_SERVICE, "InitSchedule SUCCESS"); data_->InsertScheduleId(scheduleId); std::shared_ptr coAuthCallback = std::make_shared(MODIFY_CRED, challenge, scheduleId, data_, innerkitsCallback); @@ -213,7 +213,7 @@ int32_t UserIDMController::UpdateCredentialCtrl(int32_t userId, uint64_t callerI paramInfo.SetCallerUid(callerID); CoAuth::CoAuth::GetInstance().BeginSchedule(scheduleId, paramInfo, coAuthCallback); } else { - USERIDM_HILOGE(MODULE_SERVICE, "call TA info: InitSchedulation failed"); + USERIDM_HILOGE(MODULE_SERVICE, "call TA info: BeginSchedule failed"); RequestResult reqRet; innerkitsCallback->OnResult(FAIL, reqRet); }