casbin / casbin-cpp

An authorization library that supports access control models like ACL, RBAC, ABAC in C/C++
https://casbin.org
Apache License 2.0
218 stars 61 forks source link

fix: add StringAdapter for Enforcer to pass policy as string #204

Closed cs1137195420 closed 1 year ago

cs1137195420 commented 2 years ago

fix: #200

Description

I added void LoadPolicy(std::string policy) for Enforcer to pass policy to Adapter as a sting buffer, which could be called as the following code:

casbin::Enforcer e("./path/to/model.conf");
std::string policy = "p, alice, data1, read\np, bob, data2, write";
e.LoadPolicy(policy);

Since c++ doesn't support overloaded functions with the same number and type of parameters, I didn't add a constructor like Enforcer(const std::string& model_path, const std::string &policy) in issue #200, that conflicts with Enforcer(const std::string& model_path, const std::string& policy_file)

casbin-bot commented 2 years ago

@EmperorYP7 @divy9881 @noob20000405 @sheny1xuan please review

hsluoyz commented 2 years ago

@cs1137195420 fix all errors:

image

cs1137195420 commented 2 years ago

@hsluoyz I modified the code referring to the implementation of StringAdapter in golang. Is this PR OK now?

hsluoyz commented 2 years ago

@sheny1xuan plz review

cs1137195420 commented 1 year ago

@sheny1xuan I've modified the code, could you plz review it again?

hsluoyz commented 1 year ago

@MaximAxelrodFirebolt plz review

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.50.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: