mirror of
https://github.com/openharmony/useriam_user_auth.git
synced 2026-07-19 14:23:34 -04:00
@@ -45,6 +45,15 @@ AuthApiCallback::AuthApiCallback(ExecuteInfo *executeInfo)
|
||||
|
||||
AuthApiCallback::~AuthApiCallback()
|
||||
{
|
||||
if (authInfo_ != nullptr) {
|
||||
delete authInfo_;
|
||||
}
|
||||
if (userInfo_ != nullptr) {
|
||||
delete userInfo_;
|
||||
}
|
||||
if (executeInfo_ != nullptr) {
|
||||
delete executeInfo_;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value AuthApiCallback::Uint8ArrayToNapi(napi_env env, std::vector<uint8_t> value)
|
||||
|
||||
@@ -32,14 +32,12 @@ ResultConvert::~ResultConvert()
|
||||
napi_value ResultConvert::Uint64ToUint8Napi(napi_env env, uint64_t value)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "ResultConvert Uint64ToUint8Napi uint64_t %{public}" PRIu64 "", value);
|
||||
size_t length = sizeof(value);
|
||||
void *data = nullptr;
|
||||
napi_value arrayBuffer = nullptr;
|
||||
size_t bufferSize = length;
|
||||
NAPI_CALL(env, napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer));
|
||||
memcpy_s(data, bufferSize, reinterpret_cast<const void *>(&value), bufferSize);
|
||||
NAPI_CALL(env, napi_create_arraybuffer(env, sizeof(value), &data, &arrayBuffer));
|
||||
(void)memcpy_s(data, sizeof(value), reinterpret_cast<const void *>(&value), sizeof(value));
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, bufferSize, arrayBuffer, 0, &result));
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, sizeof(value), arrayBuffer, 0, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,16 @@ namespace UserAuth {
|
||||
napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "%{public}s, start.", __func__);
|
||||
std::shared_ptr<UserAuthImpl> userAuthImpl;
|
||||
userAuthImpl.reset(new UserAuthImpl());
|
||||
UserAuthImpl *userAuthImpl = new (std::nothrow) UserAuthImpl();
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "%{public}s, get nullptr", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = ARGS_ONE;
|
||||
napi_value argv[ARGS_ONE] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
|
||||
NAPI_CALL(env, napi_wrap(env, thisVar, userAuthImpl.get(),
|
||||
NAPI_CALL(env, napi_wrap(env, thisVar, userAuthImpl,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
UserAuthImpl *userAuthImpl = static_cast<UserAuthImpl *>(data);
|
||||
if (userAuthImpl != nullptr) {
|
||||
@@ -58,13 +61,17 @@ napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value GetVersion(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, GetVersion");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, GetVersion");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, GetVersion get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->GetVersion(env, info);
|
||||
}
|
||||
|
||||
@@ -77,13 +84,17 @@ napi_value GetVersion(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value GetAvailableStatus(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, getAvailableStatus");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, getAvailableStatus");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, getAvailableStatus get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->GetAvailableStatus(env, info);
|
||||
}
|
||||
|
||||
@@ -96,13 +107,17 @@ napi_value GetAvailableStatus(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value GetProperty(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, GetProperty");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, GetProperty");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, GetProperty get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->GetProperty(env, info);
|
||||
}
|
||||
|
||||
@@ -115,13 +130,17 @@ napi_value GetProperty(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value SetProperty(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, SetProperty");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, SetProperty");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, SetProperty get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->SetProperty(env, info);
|
||||
}
|
||||
|
||||
@@ -135,25 +154,33 @@ napi_value SetProperty(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value Auth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, Auth");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, Auth");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, Auth get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->Auth(env, info);
|
||||
}
|
||||
|
||||
napi_value Execute(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, Execute");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, Execute");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, Execute get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->Execute(env, info);
|
||||
}
|
||||
|
||||
@@ -167,13 +194,17 @@ napi_value Execute(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value AuthUser(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, AuthUser");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, AuthUser");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, AuthUser get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->AuthUser(env, info);
|
||||
}
|
||||
|
||||
@@ -186,13 +217,17 @@ napi_value AuthUser(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
napi_value CancelAuth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, CancelAuth");
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
USERAUTH_HILOGI(MODULE_JS_NAPI, "UserAuthHelper, CancelAuth");
|
||||
if (userAuthImpl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "UserAuthHelper, CancelAuth get nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return userAuthImpl->CancelAuth(env, info);
|
||||
}
|
||||
|
||||
@@ -421,7 +456,8 @@ napi_value UserAuthInit(napi_env env, napi_value exports)
|
||||
DECLARE_NAPI_FUNCTION("constructor", UserAuth::Constructor),
|
||||
DECLARE_NAPI_FUNCTION("getAuthenticator", UserAuth::ConstructorForAPI6),
|
||||
};
|
||||
status = napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
status = napi_define_properties(env, exports,
|
||||
sizeof(exportFuncs) / sizeof(napi_property_descriptor), exportFuncs);
|
||||
if (status != napi_ok) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "napi_define_properties faild");
|
||||
}
|
||||
@@ -446,7 +482,7 @@ napi_value EnumExport(napi_env env, napi_value exports)
|
||||
DECLARE_NAPI_PROPERTY("FaceTipsCode", FaceTipsCodeConstructor(env)),
|
||||
DECLARE_NAPI_PROPERTY("FingerprintTips", FingerprintTipsConstructor(env)),
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors);
|
||||
napi_define_properties(env, exports, sizeof(descriptors) / sizeof(napi_property_descriptor), descriptors);
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,10 @@ napi_value UserAuthImpl::GetProperty(napi_env env, napi_callback_info info)
|
||||
if (ret == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "%{public}s GetPropertyWrap fail", __func__);
|
||||
delete getPropertyInfo;
|
||||
delete asyncHolder;
|
||||
if (asyncHolder->asyncWork != nullptr) {
|
||||
napi_delete_async_work(env, asyncHolder->asyncWork);
|
||||
}
|
||||
delete asyncHolder;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -231,10 +231,10 @@ napi_value UserAuthImpl::SetProperty(napi_env env, napi_callback_info info)
|
||||
if (ret == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_JS_NAPI, "%{public}s SetPropertyWrap fail", __func__);
|
||||
delete setPropertyInfo;
|
||||
delete asyncHolder;
|
||||
if (asyncHolder->asyncWork != nullptr) {
|
||||
napi_delete_async_work(env, asyncHolder->asyncWork);
|
||||
}
|
||||
delete asyncHolder;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -389,6 +389,14 @@ napi_value UserAuthImpl::BuildAuthInfo(napi_env env, AuthInfo *authInfo)
|
||||
|
||||
napi_value UserAuthImpl::DoExecute(ExecuteInfo* executeInfo)
|
||||
{
|
||||
bool isPromise = executeInfo->isPromise;
|
||||
napi_value result = nullptr;
|
||||
if (isPromise) {
|
||||
result = executeInfo->promise;
|
||||
} else {
|
||||
napi_get_null(executeInfo->env, &result);
|
||||
}
|
||||
|
||||
AuthApiCallback *object = new (std::nothrow) AuthApiCallback(executeInfo);
|
||||
if (object == nullptr) {
|
||||
delete executeInfo;
|
||||
@@ -407,14 +415,9 @@ napi_value UserAuthImpl::DoExecute(ExecuteInfo* executeInfo)
|
||||
delete executeInfo;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UserAuth::GetInstance().Auth(0, FACE, convertAuthTurstLevel[executeInfo->level], callback);
|
||||
if (executeInfo->isPromise) {
|
||||
return executeInfo->promise;
|
||||
} else {
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(executeInfo->env, napi_get_null(executeInfo->env, &result));
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::Execute(napi_env env, napi_callback_info info)
|
||||
|
||||
@@ -159,7 +159,7 @@ void UserAuthService::SetProperty(const SetPropertyRequest request, sptr<IUserAu
|
||||
}
|
||||
if (!CheckPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Permission check failed");
|
||||
AuthResult extraInfo;
|
||||
AuthResult extraInfo = {};
|
||||
callback->onResult(E_CHECK_PERMISSION_FAILED, extraInfo);
|
||||
return;
|
||||
}
|
||||
@@ -271,7 +271,7 @@ uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challeng
|
||||
uint64_t contextID = 0;
|
||||
AuthSolution authSolutionParam;
|
||||
CoAuthInfo coAuthInfo;
|
||||
AuthResult extraInfo;
|
||||
AuthResult extraInfo = {};
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> dr = new UserAuthServiceCallbackDeathRecipient(callback);
|
||||
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
|
||||
@@ -318,38 +318,30 @@ int32_t UserAuthService::GetControllerData(sptr<IUserAuthCallback>& callback, Au
|
||||
const AuthTurstLevel authTurstLevel, uint64_t &callerID,
|
||||
std::string &callerName, uint64_t &contextID)
|
||||
{
|
||||
int ret = SUCCESS;
|
||||
int result = SUCCESS;
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser IUserAuthCallback is NULL!");
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
return FAIL;
|
||||
}
|
||||
if (ATL4 < authTurstLevel || authTurstLevel < ATL1) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser AuthTurstLevel is NOT SUPPORT!");
|
||||
callback->onResult(TRUST_LEVEL_NOT_SUPPORT, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
callerID = this->GetCallingUid();
|
||||
callerName = std::to_string(callerID);
|
||||
|
||||
result = userauthController_.GenerateContextID(contextID);
|
||||
if (result != SUCCESS) {
|
||||
if (userauthController_.GenerateContextID(contextID) != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GenerateContextID is ERROR!");
|
||||
callback->onResult(GENERAL_ERROR, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
return FAIL;
|
||||
}
|
||||
result = userauthController_.AddContextID(contextID);
|
||||
if (result != SUCCESS) {
|
||||
if (userauthController_.AddContextID(contextID) != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser AddContextID is ERROR!");
|
||||
callback->onResult(GENERAL_ERROR, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
return FAIL;
|
||||
}
|
||||
return ret;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthService::CancelAuth(const uint64_t contextId)
|
||||
|
||||
Reference in New Issue
Block a user