识别 capnproto RPC 中的调用方
identifying caller in capnproto RPC
我正在CapnProto中实现一项服务。该服务遵循以下步骤(大致(:
- 在服务器上进行身份验证 通过
- 身份验证后通过服务接口(对象功能(执行操作。
我想实现如下目标:
interface Authorization {
login @0 (userName :User) -> (result :Service);
}
interface Service {
# doOperation needs userName in order to operate, as an implicit
# parameter, when the RPC arrives. I do not want to use an explicit
# userName parameter. Otherwise, a user could claim to
# be someone else in a function parameter. To achieve this I need
# to know who is the userName that holds this capability from inside
# doOperation. I want to avoid token authentication
# for each operation.
# Thus, the RPC I am implementing is stateful.
doOperation @0 (param1 :A);
#...
}
我想要的是,从doOperation中,我可以识别正在使用该功能的用户(我想知道她的用户名(。即:
我解决的是,已知使用服务功能的用户具有该权限(因为服务是调用登录的结果(
问题是我有很多这样的用户,对于每个用户,我想在第一步中对服务功能的用户和她的登录进行匹配。
事实证明,这很简单。
在代码中创建服务接口时,只需传递身份验证信息并将其保存在 Service 对象中,如下所示:
class ServiceImpl : public Service::Server {
string userId_;
public:
explicit ServiceImpl(string userId) : userId_(move(userId)) {}
protected:
kj::Promise<void> doOperatoration(DoOperationContext ctx) override {
//use userId_ here
}
};
class AuthorizationImpl : public Authorization::Server {
protected:
kj::Promise<void> login(LoginContext ctx) override {
std::string user = ctx.getParams().getUserName();
//Here I forward the authentication state to the service
ctx.getResults().setService(kj::heap<ServiceImpl>(user);
//..
}
};
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 函数调用中参数的顺序重要吗
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在c++类上调用void函数
- 为什么 std::unique 不调用 std::sort?
- 调用专用模板时出错"no matching function for call to [...]"
- 选择要调用的构造函数
- C++为什么尽管我调用了void函数,它却不起作用
- 构造函数正在调用一个使用当前类类型的函数
- 变量没有改变?通过向量的函数调用
- 没有为自己的结构调用列表推回方法
- 调用'begin(int [n])'没有匹配函数
- 什么时候调用析构函数
- 如何用参数值调用函数(仅在运行时已知)
- std::cout.imbue()多重调用
- 识别 capnproto RPC 中的调用方