Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casbin.net Breaking changes while migrating from V1.13.0 to V2.9.1 - Enforcer class #366

Open
shrey-shah opened this issue Sep 6, 2024 · 7 comments
Assignees
Labels
new feature New feature will be provided or request question Further information is requested

Comments

@shrey-shah
Copy link

I am trying to migrate Casbin.net package from V1.13.0 to V2.9.1. My Enforcer class used to look like this in the previous version.

public class CustomEnforcer : Enforcer
    {
        public CustomEnforcer() : this("", "")
        {
        }
        public CustomEnforcer(string modelContent, string policyContent) : this(NewModel(modelContent), new DefaultFileContentAdapter(policyContent))
        {

        }

        public CustomEnforcer(Model m, IAdapter adapter)
        {
            SetAdapter(adapter);
            SetWatcher(null, false);
            SetModel(m);
            FunctionMap.LoadFunctionMap();
            EnforcerOptions enforcerOptions = new EnforcerOptions() 
            { 
            
            };
            Initialize(enforcerOptions);
            if (this.adapter != null)
            {
                LoadPolicy();
            }
        }
    }

I have changed it like this.

public class CustomEnforcer : Enforcer
    {
        public CustomEnforcer() : this("", "")
        {
        }
        public CustomEnforcer(string modelContent, string policyContent)
        {
            Model = DefaultModel.CreateFromText(modelContent);
            Adapter = new FileAdapter(policyContent);
        }

    }

is this correct? Do I need to do anything else? earlier version had a separate class with the implementation of DefaultFileContentAdapter. Do we need this in the latest version?

@casbin-bot
Copy link
Member

@casbin-bot casbin-bot added the question Further information is requested label Sep 6, 2024
@sagilio sagilio self-assigned this Sep 6, 2024
@hsluoyz
Copy link
Member

hsluoyz commented Sep 6, 2024

@shrey-shah why create two issues? #367

@sagilio
Copy link
Member

sagilio commented Sep 6, 2024

@shrey-shah why create two issues? #367

It looks like two different issues

@sagilio
Copy link
Member

sagilio commented Sep 6, 2024

Here is a sample for this issue.

public class CustomEnforcer : Enforcer
{
    public CustomEnforcer(string modelText, string policyText)
        : base(DefaultModel.CreateFromText(modelText),
            new FileAdapter(ReadPolicyText(policyText)))
    {

    }

    private static MemoryStream ReadPolicyText(string policyText)
    {
        return new MemoryStream(Encoding.UTF8.GetBytes(policyText));
    }
}

@shrey-shah
Copy link
Author

my model and policy are like this: #367 (comment)
it gets passed in the string format itself. also, do we need the DefaultFileContentAdapter class now?

@shrey-shah
Copy link
Author

any update here?

@sagilio
Copy link
Member

sagilio commented Sep 21, 2024

my model and policy are like this: #367 (comment) it gets passed in the string format itself. also, do we need the DefaultFileContentAdapter class now?

It need not now. we will add new API for it.

@sagilio sagilio added the new feature New feature will be provided or request label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature will be provided or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants