{"id":269072,"date":"2021-01-09T23:04:15","date_gmt":"2021-01-09T15:04:15","guid":{"rendered":"http:\/\/4563.org\/?p=269072"},"modified":"2021-01-09T23:04:15","modified_gmt":"2021-01-09T15:04:15","slug":"%e8%ae%bf%e9%97%ae%e6%8e%a7%e5%88%b6%e6%a1%86%e6%9e%b6%e4%b9%8b-casbin-net-%e7%ae%80%e4%bb%8b","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=269072","title":{"rendered":"\u8bbf\u95ee\u63a7\u5236\u6846\u67b6\u4e4b Casbin.NET \u7b80\u4ecb"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bbf\u95ee\u63a7\u5236\u6846\u67b6\u4e4b Casbin.NET \u7b80\u4ecb               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : doukeya <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h1>\u8bbf\u95ee\u63a7\u5236\u6846\u67b6\u4e4b Casbin.NET \u7b80\u4ecb<\/h1>\n<p> <\/p>\n<h6>\u5b98\u7f51\uff1ahttps:\/\/casbin.org\/<\/h6>\n<h6>\u5f00\u6e90\u4ed3\u5e93\u6e90\u7801\uff1ahttps:\/\/github.com\/casbin<\/h6>\n<h6>QQ \u7fa4\uff1a546057381<\/h6>\n<h6>\u5b98\u65b9\u8bba\u575b\uff1ahttps:\/\/forum.casbin.com\/<\/h6>\n<p>Casbin.NET \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u3001\u6548\u7387\u9ad8\u7684.NET (C #)\u9879\u76ee\u7684\u5f00\u6e90\u8bbf\u95ee\u63a7\u5236\u5e93\uff0c\u662f Casbin \u7684\u5176\u4e2d\u4e00\u4e2a\u8bed\u8a00\u5206\u652f\u3002\u5b83\u652f\u6301\u57fa\u4e8e\u5404\u79cd\u8bbf\u95ee\u63a7\u5236\u6a21\u578b\u5b9e\u65bd\u6388\u6743\u3002<\/p>\n<p><strong>Casbin \u652f\u6301\u7684\u6240\u6709\u8bed\u8a00\uff1a<\/strong> <img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/01\/20210110_5ffad2739c99c.png\" alt=\"\u8bbf\u95ee\u63a7\u5236\u6846\u67b6\u4e4b Casbin.NET \u7b80\u4ecb\" \/><strong>\u652f\u6301\u7684\u6a21\u578b\uff1a<\/strong><\/p>\n<ol>\n<li>ACL(\u8bbf\u95ee\u63a7\u5236\u5217\u8868)\u3002<\/li>\n<li>ACL \u548c\u8d85\u7ea7\u7528\u6237\u3002<\/li>\n<li>\u6ca1\u6709\u7528\u6237\u7684 ACL:\u5bf9\u4e8e\u6ca1\u6709\u8eab\u4efd\u9a8c\u8bc1\u6216\u7528\u6237\u767b\u5f55\u7684\u7cfb\u7edf\u7279\u522b\u6709\u7528\u3002<\/li>\n<li>\u4e0d\u542b\u8d44\u6e90\u7684 ACL:\u6709\u4e9b\u573a\u666f\u53ef\u80fd\u4f1a\u901a\u8fc7\u4f7f\u7528\u8bf8\u5982==write-article==\u3001==read-log==\u7b49\u6743\u9650\u6765\u9488\u5bf9\u67d0\u79cd\u7c7b\u578b\u7684\u8d44\u6e90\uff0c\u800c\u4e0d\u662f\u5355\u4e2a\u8d44\u6e90\u3002\u5b83\u4e0d\u63a7\u5236\u5bf9\u7279\u5b9a\u6587\u7ae0\u6216\u65e5\u5fd7\u7684\u8bbf\u95ee\u3002<\/li>\n<li>RBAC(\u57fa\u4e8e\u89d2\u8272\u7684\u8bbf\u95ee\u63a7\u5236)\u3002<\/li>\n<li>\u5177\u6709\u8d44\u6e90\u89d2\u8272\u7684 RBAC:\u7528\u6237\u548c\u8d44\u6e90\u90fd\u53ef\u4ee5\u540c\u65f6\u5177\u6709\u89d2\u8272(\u6216\u7ec4)\u3002<\/li>\n<li>\u5e26\u57df \/\u79df\u6237\u7684 RBAC:\u7528\u6237\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u57df \/\u79df\u6237\u62e5\u6709\u4e0d\u540c\u7684\u89d2\u8272\u96c6\u3002<\/li>\n<li>ABAC(\u57fa\u4e8e\u5c5e\u6027\u7684\u8bbf\u95ee\u63a7\u5236):\u7c7b\u4f3c\u4e8e resource \u7684\u8bed\u6cd5\u7cd6\u3002Owner \u53ef\u7528\u4e8e\u83b7\u53d6\u8d44\u6e90\u7684\u5c5e\u6027\u3002<\/li>\n<li>RESTful:\u652f\u6301 \/res\/*\u3001\/res\/:id \u7b49\u8def\u5f84\uff0c\u652f\u6301 HTTP \u65b9\u6cd5 GET \u3001POST \u3001PUT \u3001DELETE \u7b49\u3002<\/li>\n<li>deny -override:\u540c\u65f6\u652f\u6301 allow \u548c deny \u6388\u6743\uff0cdeny \u8986\u76d6 allow \u3002<\/li>\n<li>\u4f18\u5148\u7ea7:\u7b56\u7565\u89c4\u5219\u53ef\u4ee5\u50cf\u9632\u706b\u5899\u89c4\u5219\u4e00\u6837\u8fdb\u884c\u4f18\u5148\u7ea7\u6392\u5e8f\u3002<\/li>\n<\/ol>\n<p><strong>\u539f\u7406\uff1a<\/strong><\/p>\n<p>\u5728 Casbin \u4e2d\uff0c\u4e00\u4e2a\u8bbf\u95ee\u63a7\u5236\u6a21\u578b\u57fa\u4e8e PERM \u5143\u6a21\u578b(\u7b56\u7565\u3001\u6548\u679c\u3001\u8bf7\u6c42\u3001Matchers)\u62bd\u8c61\u5230\u4e00\u4e2a CONF \u6587\u4ef6\u4e2d\u3002\u56e0\u6b64\uff0c\u5207\u6362\u6216\u5347\u7ea7\u9879\u76ee\u7684\u6388\u6743\u673a\u5236\u5c31\u50cf\u4fee\u6539\u914d\u7f6e\u4e00\u6837\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u7ec4\u5408\u53ef\u7528\u7684\u6a21\u578b\u6765\u5b9a\u5236\u81ea\u5df1\u7684\u8bbf\u95ee\u63a7\u5236\u6a21\u578b\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5728\u4e00\u4e2a\u6a21\u578b\u4e2d\u540c\u65f6\u83b7\u5f97 RBAC \u89d2\u8272\u548c ABAC \u5c5e\u6027\uff0c\u5e76\u5171\u4eab\u4e00\u7ec4\u7b56\u7565\u89c4\u5219\u3002 Casbin \u4e2d\u6700\u57fa\u672c\u3001\u6700\u7b80\u5355\u7684\u6a21\u578b\u662f ACL \u3002ACL \u7684\u6a21\u578b CONF \u4e3a:<\/p>\n<pre><code>#Request definition [request_definition] r = sub, obj, act  #Policy definition [policy_definition] p = sub, obj, act   Policy effect [policy_effect] e = some(where (p.eft == allow))   Matchers [matchers] m = r.sub == p.sub &amp;&amp; r.obj == p.obj &amp;&amp; r.act == p.act <\/code><\/pre>\n<p>ACL \u6a21\u578b\u7684\u7b56\u7565\u793a\u4f8b\u5982\u4e0b:<\/p>\n<pre><code>p, alice, data1, read p, bob, data2, write <\/code><\/pre>\n<p>\u8fd9\u8868\u793a\uff1a<\/p>\n<ul>\n<li>alic \u53ef\u4ee5\u8bfb\u53d6 data1<\/li>\n<li>bob \u53ef\u4ee5\u5199 data2<\/li>\n<\/ul>\n<p>\u6211\u4eec\u8fd8\u901a\u8fc7\u5728\u672b\u5c3e\u6dfb\u52a0&#8221;\u6765\u652f\u6301\u591a\u884c\u6a21\u5f0f:<\/p>\n<pre><code>#Matchers [matchers] m = r.sub == p.sub &amp;&amp; r.obj == p.obj    &amp;&amp; r.act == p.act <\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f ABAC\uff0c\u4f60\u53ef\u4ee5\u5728 Casbin golang \u7248(\u76ee\u524d\u4e0d\u652f\u6301 jCasbin \u548c Node-Casbin)\u4e2d\u5c1d\u8bd5\u5982\u4e0b\u64cd\u4f5c\u7b26:<\/p>\n<pre><code>#Matchers [matchers] m = r.obj == p.obj &amp;&amp; r.act == p.act || r.obj in ('data2', 'data3') <\/code><\/pre>\n<p>\u4f46\u662f\u60a8\u5e94\u8be5\u786e\u4fdd\u6570\u7ec4\u7684\u957f\u5ea6\u5927\u4e8e 1\uff0c\u5426\u5219\u4f1a\u5f15\u8d77\u62a5\u8b66\u3002 \u5bf9\u4e8e\u66f4\u591a\u7684\u64cd\u4f5c\u7b26\uff0c\u60a8\u53ef\u4ee5\u67e5\u770bgovaluate\u3002<\/p>\n<p><strong>\u6587\u6863\uff1a<\/strong> https:\/\/casbin.org\/docs\/en\/overview<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4879841\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ychost <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u597d\u8bc4\uff0c\u51e0\u5e74\u524d\u7528\u8fc7 java \u7248\u672c\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbf\u95ee\u63a7\u5236\u6846\u67b6\u4e4b Casbin.NE&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/269072"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=269072"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/269072\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269072"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}