Skip to content

Broken enforce with json string in 2.0 #210

Closed
@Guara92

Description

Upgrading from version 1.1.3 to 2.0.2 I need to adapt this piece of code that works fine on 1.1.3

  let request_subject_string = serde_json::to_string(&request_subject)?;	    
  let request_object_string = serde_json::to_string(&object)?;	   
  let is_allowed =
            Enforcer::global().enforce(&[&request_subject_string, &request_object_string])?;

to

  let request_subject_string = serde_json::to_string(&request_subject)?;	    
  let request_object_string = serde_json::to_string(&object)?;	   
  let is_allowed =
             Enforcer::global().enforce(vec![request_subject_string, request_object_string])?;

this code compile with 2.0.2 but lead to a runtime error

    RhaiError(ErrorDotExpr("Unknown property \'user\' for string, or it is write-only",1:9,),)

with simple ABAC authorization

[matchers]
m = ((r.sub.user == r.obj.user && r.sub.domain == r.obj.domain) || (r.sub.admin && r.sub.domain == r.obj.domain)) && (r.sub.active)

To make 2.0.2 work I derived also Hash on the original serializable struct and used a tuple to call the enforcer

let is_allowed = Enforcer::global().enforce((request_subject, object))?;

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions