mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-11-26 17:31:26 +00:00
commit
c906b55412
@ -44,6 +44,8 @@ public:
|
||||
uint64_t GetContextId() const override;
|
||||
std::shared_ptr<ScheduleNode> GetScheduleNode(uint64_t scheduleId) const override;
|
||||
int32_t GetUserId() const override;
|
||||
int32_t GetAuthType() const override;
|
||||
std::string GetCallerName() const override;
|
||||
|
||||
void OnScheduleStarted() override;
|
||||
void OnScheduleProcessed(ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg) override;
|
||||
|
@ -58,6 +58,8 @@ public:
|
||||
virtual uint32_t GetTokenId() const = 0;
|
||||
virtual int32_t GetLatestError() const = 0;
|
||||
virtual int32_t GetUserId() const = 0;
|
||||
virtual int32_t GetAuthType() const = 0;
|
||||
virtual std::string GetCallerName() const = 0;
|
||||
|
||||
protected:
|
||||
virtual void SetLatestError(int32_t error) = 0;
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
uint32_t GetTokenId() const override;
|
||||
int32_t GetLatestError() const override;
|
||||
int32_t GetUserId() const override;
|
||||
int32_t GetAuthType() const override;
|
||||
std::string GetCallerName() const override;
|
||||
|
||||
protected:
|
||||
void SetLatestError(int32_t error) override;
|
||||
|
@ -38,6 +38,8 @@ public:
|
||||
ContextType GetContextType() const override;
|
||||
uint32_t GetTokenId() const override;
|
||||
int32_t GetUserId() const override;
|
||||
int32_t GetAuthType() const override;
|
||||
std::string GetCallerName() const override;
|
||||
|
||||
protected:
|
||||
bool OnStart() override;
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
uint32_t GetTokenId() const override;
|
||||
int32_t GetLatestError() const override;
|
||||
int32_t GetUserId() const override;
|
||||
int32_t GetAuthType() const override;
|
||||
std::string GetCallerName() const override;
|
||||
|
||||
// WidgetScheduleNodeCallback API
|
||||
bool LaunchWidget() override;
|
||||
|
@ -66,6 +66,16 @@ int32_t BaseContext::GetUserId() const
|
||||
return INVALID_USER_ID;
|
||||
}
|
||||
|
||||
int32_t BaseContext::GetAuthType() const
|
||||
{
|
||||
return INVALID_AUTH_TYPE;
|
||||
}
|
||||
|
||||
std::string BaseContext::GetCallerName() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool BaseContext::Start()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
|
@ -60,11 +60,35 @@ public:
|
||||
bool DeregisterContextPoolListener(const std::shared_ptr<ContextPoolListener> &listener) override;
|
||||
|
||||
private:
|
||||
void CheckPreemptContext(const std::shared_ptr<Context> &context);
|
||||
mutable std::recursive_mutex poolMutex_;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<Context>> contextMap_;
|
||||
std::set<std::shared_ptr<ContextPoolListener>> listenerSet_;
|
||||
};
|
||||
|
||||
void ContextPoolImpl::CheckPreemptContext(const std::shared_ptr<Context> &context)
|
||||
{
|
||||
if (context->GetContextType() != ContextType::CONTEXT_SIMPLE_AUTH) {
|
||||
return;
|
||||
}
|
||||
for (auto iter = contextMap_.begin(); iter != contextMap_.end(); iter++) {
|
||||
if (iter->second == nullptr) {
|
||||
IAM_LOGE("context is nullptr");
|
||||
break;
|
||||
}
|
||||
if (iter->second->GetCallerName() == context->GetCallerName() &&
|
||||
iter->second->GetAuthType() == context->GetAuthType() &&
|
||||
iter->second->GetUserId() == context->GetUserId()) {
|
||||
IAM_LOGE("contextId:%{public}hx is preempted, newContextId:%{public}hx, mapSize:%{public}zu,"
|
||||
"callerName:%{public}s, userId:%{public}d, authType:%{public}d", static_cast<uint16_t>(iter->first),
|
||||
static_cast<uint16_t>(context->GetContextId()), contextMap_.size(), context->GetCallerName().c_str(),
|
||||
context->GetUserId(), context->GetAuthType());
|
||||
iter->second->Stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ContextPoolImpl::Insert(const std::shared_ptr<Context> &context)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
@ -76,6 +100,7 @@ bool ContextPoolImpl::Insert(const std::shared_ptr<Context> &context)
|
||||
IAM_LOGE("context pool is full");
|
||||
return false;
|
||||
}
|
||||
CheckPreemptContext(context);
|
||||
uint64_t contextId = context->GetContextId();
|
||||
auto result = contextMap_.try_emplace(contextId, context);
|
||||
if (!result.second) {
|
||||
|
@ -50,6 +50,18 @@ ContextType ScheduleHolderContext::GetContextType() const
|
||||
return ContextType::SCHEDULE_HOLDER_CONTEXT;
|
||||
}
|
||||
|
||||
int32_t ScheduleHolderContext::GetAuthType() const
|
||||
{
|
||||
IAM_LOGE("not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ScheduleHolderContext::GetCallerName() const
|
||||
{
|
||||
IAM_LOGE("not implemented");
|
||||
return "";
|
||||
}
|
||||
|
||||
std::shared_ptr<ScheduleNode> ScheduleHolderContext::GetScheduleNode(uint64_t scheduleId) const
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(scheduleNode_ != nullptr, nullptr);
|
||||
|
@ -110,6 +110,18 @@ int32_t SimpleAuthContext::GetUserId() const
|
||||
return auth_->GetUserId();
|
||||
}
|
||||
|
||||
int32_t SimpleAuthContext::GetAuthType() const
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(auth_ != nullptr, INVALID_AUTH_TYPE);
|
||||
return auth_->GetAuthType();
|
||||
}
|
||||
|
||||
std::string SimpleAuthContext::GetCallerName() const
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback_ != nullptr, "");
|
||||
return callback_->GetCallerName();
|
||||
}
|
||||
|
||||
bool SimpleAuthContext::OnStart()
|
||||
{
|
||||
IAM_LOGI("%{public}s start", GetDescription());
|
||||
|
@ -118,6 +118,16 @@ int32_t WidgetContext::GetUserId() const
|
||||
return para_.userId;
|
||||
}
|
||||
|
||||
int32_t WidgetContext::GetAuthType() const
|
||||
{
|
||||
return INVALID_AUTH_TYPE;
|
||||
}
|
||||
|
||||
std::string WidgetContext::GetCallerName() const
|
||||
{
|
||||
return para_.callerName;
|
||||
}
|
||||
|
||||
int32_t WidgetContext::GetLatestError() const
|
||||
{
|
||||
return latestError_;
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
virtual uint32_t GetAccessTokenId() const = 0;
|
||||
virtual int32_t GetLatestError() const = 0;
|
||||
virtual int32_t GetUserId() const = 0;
|
||||
virtual int32_t GetAuthType() const = 0;
|
||||
|
||||
protected:
|
||||
virtual void SetLatestError(int32_t error) = 0;
|
||||
|
@ -80,6 +80,11 @@ int32_t AuthenticationImpl::GetUserId() const
|
||||
return authPara_.userId;
|
||||
}
|
||||
|
||||
int32_t AuthenticationImpl::GetAuthType() const
|
||||
{
|
||||
return authPara_.authType;
|
||||
}
|
||||
|
||||
std::vector<Authentication::AuthExecutorMsg> AuthenticationImpl::GetAuthExecutorMsgs() const
|
||||
{
|
||||
return authExecutorMsgs_;
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
uint32_t GetAccessTokenId() const override;
|
||||
int32_t GetLatestError() const override;
|
||||
int32_t GetUserId() const override;
|
||||
int32_t GetAuthType() const override;
|
||||
|
||||
protected:
|
||||
void SetLatestError(int32_t error) override;
|
||||
|
@ -61,6 +61,10 @@ public:
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
int32_t GetAuthType() const
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
void OnContextPoolInsert(const std::shared_ptr<Context> &context){};
|
||||
void OnContextPoolDelete(const std::shared_ptr<Context> &context){};
|
||||
};
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
MOCK_CONST_METHOD0(GetAccessTokenId, uint32_t());
|
||||
MOCK_CONST_METHOD0(GetLatestError, int32_t());
|
||||
MOCK_CONST_METHOD0(GetUserId, int32_t());
|
||||
MOCK_CONST_METHOD0(GetAuthType, int32_t());
|
||||
|
||||
protected:
|
||||
MOCK_METHOD1(SetLatestError, void(int32_t error));
|
||||
|
@ -73,6 +73,8 @@ public:
|
||||
MOCK_CONST_METHOD0(GetLatestError, int32_t());
|
||||
MOCK_CONST_METHOD0(GetTokenId, uint32_t());
|
||||
MOCK_CONST_METHOD0(GetUserId, int32_t());
|
||||
MOCK_CONST_METHOD0(GetAuthType, int32_t());
|
||||
MOCK_CONST_METHOD0(GetCallerName, std::string());
|
||||
|
||||
static std::shared_ptr<Context> CreateWithContextId(uint64_t contextId)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user