Skip to content

[Question] Does Casbin-cpp support passing requests in JSON format? #255

@zzy-KI

Description

@zzy-KI

I want to pass a complex access request to Enforce() in JSON format.

       casbin::DataMap request = {
            // Access Request Entity
            {"sub", std::make_shared<nlohmann::json>(nlohmann::json{
                {"ID", "zk"},
                {"proxy", "vpn"},
                {"Department", "nlp"},
                {"month", "Jan"},
                {"week", "Mon"},
                {"time", "morning"},
                {"Longitude", "123"},
                {"Latitude", "456"},
                {"Altitude", "789"},
                {"OS", "HarmonyOS"},
                {"CPU", "XeonPlatinum8480+"},
                {"NetworkType", "WLan"},
                {"ProtocolType", "Bluetooth"},
                {"EncryptionType", "3DES"},
                {"ESecurityProtocol", "HTTPS"}
            })},

            // Object attributes
            {"obj", std::make_shared<nlohmann::json>(nlohmann::json{
                {"SecurityLevel", "3"},
                {"Source", "ISS"},
                {"DistributionMethod", "C"}

            })},
            // Action
            {"act", std::string("read")}
        };

However, during my debugging of the source code, I discovered that my access request (r.sub r.obj) was not registered to this → m_evalator → identifiers_.
I later found that the registration behavior here was commented out(in casbin-cpp-master/casbin/model/evaluator.cpp):

void ExprtkEvaluator::PushObjectJson(const std::string& target, const std::string& proprity, const nlohmann::json& var) {
    auto identifier = target + "." + proprity;
    // this->symbol_table.add_stringvar(identifier, const_cast<std::string&>(var));
}

Furthermore, it's also commented out in enforcer_test.cpp.

// TEST(TestEnforcer, JsonData) {
//     using json = nlohmann::json;
//     casbin::Scope scope = casbin::InitializeScope();
//     casbin::PushObject(scope, "r");

//     json myJson = {
//             {"DoubleCase", 3.141},
//             {"IntegerCase", 2},
//             {"BoolenCase", true},
//             {"StringCase", "Bob"},
//             // {"nothing", nullptr},
//             {"x", {
//                     {"y", {
//                         {"z", 1}
//                         }
//                     },
//                     {"x", 2
//                     }
//                 }
//             },
//         };

//     casbin::PushObjectPropFromJson(scope, myJson, "r");
//     std::string s1 = "r.DoubleCase == 3.141;";
//     std::string s2 = "r.IntegerCase == 2;";
//     std::string s3 = "r.BoolenCase == true;";
//     std::string s4 = "r.StringCase == \"Bob\";";
//     std::string s5 = "r.x.y.z == 1;";
//     std::string s6 = "r.x.x == 2;";
...

So I'd like to ask if casbin-cpp no ​​longer natively supports JSON input? Is it now only possible to use flat strings as request parameters?If that's the case, I might suggest to my superiors that the project use either the Go or Java version.

Thank you for taking the time to read. @EmperorYP7

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions