From a13b9158427639e3a8ff72e8474a474d8229dc84 Mon Sep 17 00:00:00 2001 From: wangxu43 Date: Thu, 21 Aug 2025 15:37:57 +0800 Subject: [PATCH] add attribute ATTR_TOKEN_FROM_LOCAL_DEVICE Signed-off-by: wangxu43 Change-Id: I59c77c23670a62947b5be3ee19cfb2c82e6be620 --- .../native/common/attributes/src/attributes.cpp | 14 ++++++++++++++ interfaces/inner_api/attributes.h | 12 ++++++++++++ .../context/src/remote_auth_invoker_context.cpp | 2 ++ 3 files changed, 28 insertions(+) diff --git a/frameworks/native/common/attributes/src/attributes.cpp b/frameworks/native/common/attributes/src/attributes.cpp index a8939c0cd..4560fe4cc 100644 --- a/frameworks/native/common/attributes/src/attributes.cpp +++ b/frameworks/native/common/attributes/src/attributes.cpp @@ -71,6 +71,7 @@ public: bool GetAttributesValue(AttributeKey key, Impl &array) const; std::vector Serialize() const; std::vector GetKeys() const; + bool HasAttribute(AttributeKey key) const; static bool EncodeUint32Value(uint32_t src, std::vector &dst); static bool DecodeUint32Value(const std::vector &src, uint32_t &dst); @@ -674,6 +675,11 @@ std::vector Attributes::Impl::GetKeys() const return keys; } +bool Attributes::Impl::HasAttribute(AttributeKey key) const +{ + return (map_.find(key) != map_.end()); +} + bool Attributes::Impl::EncodeBoolValue(bool src, std::vector &dst) { std::vector out(1); // only 1 @@ -1384,6 +1390,14 @@ std::vector Attributes::GetKeys() const } return impl_->GetKeys(); } + +bool Attributes::HasAttribute(AttributeKey key) const +{ + if (!impl_) { + return false; + } + return impl_->HasAttribute(key); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/attributes.h b/interfaces/inner_api/attributes.h index a1eea5065..5fa2ebc34 100644 --- a/interfaces/inner_api/attributes.h +++ b/interfaces/inner_api/attributes.h @@ -205,6 +205,11 @@ public: ATTR_TOKEN_TIME_INTERVAL = 100091, /* credential length, the value type is uint32_t. */ ATTR_CREDENTIAL_LENGTH = 100092, + /* + * Is token in attribute generated by remote device, if not setted indicate token generated by local device. + * The value type is bool. + */ + ATTR_TOKEN_FROM_REMOTE_DEVICE = 100093, }; /** @@ -525,6 +530,13 @@ public: */ std::vector GetKeys() const; + /** + * @brief Is specific attribute setted. + * + * @return Return is specific attribute setted. + */ + bool HasAttribute(AttributeKey key) const; + private: class Impl; std::unique_ptr impl_ {nullptr}; diff --git a/services/context/src/remote_auth_invoker_context.cpp b/services/context/src/remote_auth_invoker_context.cpp index 266ba6fd8..89d8166a7 100644 --- a/services/context/src/remote_auth_invoker_context.cpp +++ b/services/context/src/remote_auth_invoker_context.cpp @@ -359,6 +359,8 @@ int32_t RemoteAuthInvokerContext::ProcAuthResultMsgInner(Attributes &message, in if (resultCode == ResultCode::SUCCESS) { bool setTokenRet = attr.SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authResultInfo.token); IF_FALSE_LOGE_AND_RETURN_VAL(setTokenRet, ResultCode::GENERAL_ERROR); + bool setTokenFromRemoteDevice = attr.SetBoolValue(Attributes::ATTR_TOKEN_FROM_REMOTE_DEVICE, true); + IF_FALSE_LOGE_AND_RETURN_VAL(setTokenFromRemoteDevice, ResultCode::GENERAL_ERROR); bool setUserId = attr.SetInt32Value(Attributes::ATTR_USER_ID, authResultInfo.userId); IF_FALSE_LOGE_AND_RETURN_VAL(setUserId, ResultCode::GENERAL_ERROR); } -- Gitee