{"id":317319,"date":"2021-02-02T03:00:32","date_gmt":"2021-02-02T03:00:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=317319"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=317319","title":{"rendered":"\u0413\u0438\u0431\u043a\u0430\u044f\u00a0\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0Casbin\u00a0\u0438\u00a0PERM.\u00a0\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e <a href=\"https:\/\/habr.com\/ru\/post\/539778\/\">\u044f\u0437\u044b\u043a\u0443 PERM \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Casbin<\/a>, \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/539778\/#comment_22609026\">\u0432\u043e\u043f\u0440\u043e\u0441\u044b<\/a>. \u041f\u0440\u0438\u0447\u0435\u043c \u043d\u0435 \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043d\u043e \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043b\u043e\u0436\u0443 \u044d\u0442\u043e\u0442 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. <\/p>\n<p>  <\/p>\n<p>\u042f \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u043c\u043e\u0433 \u043f\u043e\u043d\u044f\u0442\u044c \u0442\u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0438\u0434\u0435\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0443 \u0432\u043e\u043f\u0440\u043e\u0448\u0430\u044e\u0449\u0438\u0445, \u043d\u043e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u0441\u043b\u0435 \u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043e\u0442\u0432\u0435\u0442\u044b, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432 \u0446\u0438\u0442\u0430\u0442\u0435. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<blockquote><p>\u0410 \u043a\u0430\u043a \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 DSL \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u00ab\u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043c\u043e\u0433\u0443 \u0432\u0438\u0434\u0435\u0442\u044c? \u041d\u0430\u0434\u043e \u0436\u0435 \u0432 SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u044d\u0442\u043e \u043a\u0430\u043a-\u0442\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0435 \u0432\u044b\u0433\u0440\u0435\u0431\u0430\u0442\u044c \u0436\u0435 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0411\u0414.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0447\u0435\u0433\u043e-\u043b\u0438\u0431\u043e. \u0421\u043a\u0430\u0436\u0435\u043c \u2014 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 CMS. \u0421\u0442\u0430\u0442\u0435\u0439 \u0441 \u0431\u0430\u0437\u0435 \u2014 \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0442\u044b\u0441\u044f\u0447, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0434\u0435\u0441\u044f\u0442\u043a\u0443. \u041a\u0430\u043a \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 \u0411\u0414 \u0441\u0442\u0430\u0442\u044c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0438\u0434\u043d\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e? \u041d\u0443, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0447\u0442\u043e \u043a\u043e\u043c\u0443 \u0432\u0438\u0434\u043d\u043e \u2014 \u0432\u044b\u043d\u0443\u043b\u0438 \u0438\u0437 \u043a\u043e\u0434\u0430 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e DSL?<br \/>  \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u2014 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0442\u0438\u043f\u0430 <\/p>\n<p>  select * from articles a<br \/>  join roles r on r.userId = currentUserId<br \/>  where article.owner = currentUserId<br \/>  OR (r.role in [&#8216;admin&#8217;, &#8216;supevisor&#8217;]) \u2014 \u0430\u0434\u043c\u0438\u043d \u0432\u0441\u0435\u0433\u043e<br \/>  OR (r.domain = currentDomainId AND r.role in [&#8216;domain-admin&#8217;, &#8216;domain-supervisor&#8217;]) \u2014 \u0430\u0434\u043c\u0438\u043d \u0434\u043e\u043c\u0435\u043d\u0430 <\/p>\n<p>  \u0423 \u043c\u0435\u043d\u044f \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432 \u043a\u043e\u0434\u0435, \u0432 \u0432\u0438\u0434\u0435 LINQ-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0438 \u044f \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0430\u0442\u044c \u0443\u043c\u0435\u044e. \u0410 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0434\u0430\u0436\u0435 \u0447\u0430\u0449\u0435, \u0447\u0435\u043c \u00ab\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0435\u0441\u0442\u044c \u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432\u044b\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u043c\u0443 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0443\u00bb<\/p><\/blockquote>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u043b \u044d\u0442\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0438 \u0432 \u0445\u043e\u0434\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0432\u0435\u0440\u0441\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0438\u043d\u0433\u0430, \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u0442\u0435\u043d\u0430\u0442\u043d\u043e\u0441\u0442\u0438 (\u0434\u043e\u043c\u0435\u043d\u044b), \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044e\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. <\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043e\u043f\u0438\u0448\u0443 \u0442\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0438\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0443 \u0432\u043e\u043f\u0440\u043e\u0448\u0430\u044e\u0449\u0435\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0442\u043e\u0436\u0435 \u0435\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043b\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u043c\u044b \u044d\u0442\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Casbin.<\/p>\n<p>  <\/p>\n<h2 id=\"opisanie-zadachi\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f CMS, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0430\u0434\u043c\u0438\u043d\u043f\u0430\u043d\u0435\u043b\u044c \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438. \u0412 \u0430\u0434\u043c\u0438\u043a\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0440\u043e\u043b\u044c\u044e <code>user<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421\u0442\u0430\u0442\u044c\u0438\u00a0\u0434\u0440\u0443\u0433\u0438\u0445\u00a0\u043b\u044e\u0434\u0435\u0439\u00a0\u043e\u043d\u00a0\u043d\u0435\u00a0\u043c\u043e\u0436\u0435\u0442\u00a0\u0432\u0438\u0434\u0435\u0442\u044c, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u043c\u0443 \u043d\u0435 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0430 \u0440\u043e\u043b\u044c <code>admin<\/code> \u0438\u043b\u0438 <code>supervisor<\/code>. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0440\u043e\u043b\u044c\u044e <code>supervisor<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0430 <code>admin<\/code> \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0435 \u0442\u0435 \u0436\u0435 \u043f\u0440\u0430\u0432\u0430 \u0447\u0442\u043e \u0438 <code>supervisor<\/code>, \u043d\u043e \u043a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u0435\u0449\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  <\/p>\n<h3 id=\"struktura-shema-i-soderzhimoe-bd\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u0441\u0445\u0435\u043c\u0430 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0411\u0414:<\/h3>\n<p>  <\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0411\u0414 \u043d\u0430\u0448\u0435\u0439 CMS:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/21d\/61d\/78f\/21d61d78ffaf831393af6ed95ae117ce.png\" alt=\"\u0421\u0445\u0435\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0411\u0414\"><\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u2014 <strong>Users<\/strong>:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0bd\/b9e\/cf1\/0bdb9ecf12845f1069547e5130a75df3.png\" alt=\"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Users\"><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u043e\u043b\u0438:<br \/>  \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u2014 <strong>Roles<\/strong>:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0d1\/d89\/55c\/0d1d8955cc5ea79401977a08923dff54.png\" alt=\"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Roles\"><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, Piter \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c, \u0430 Bob \u2014 \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440\u043e\u043c. Alice \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043c\u043e\u0436\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438 \u2014 <strong>Articles<\/strong>:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/c58\/006\/137\/c58006137a9de74cab4e011b563db3d4.png\" alt=\"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Articles\"><\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u0430, \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 (Piter, id=3) \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">select * from articles a left join roles r on r.userId = 3 where a.owner = 3 OR (r.role in ('admin', 'supevisor'))<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b7e\/42b\/c72\/b7e42bc72a18cea2a4f081db29895e12.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430\"><\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440\u0430 (Bob, id=2) \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">select * from articles a left join roles r on r.userId = 2 where a.owner = 2 OR (r.role in ('admin', 'supevisor'))<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1fd\/3e7\/f02\/1fd3e7f02a67715afa13f33425a16e15.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440\u0430\"><\/p>\n<p>  <\/p>\n<p>\u0410 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Alice, id=1) \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: <\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">select * from articles a left join roles r on r.userId = 1 where a.owner = 1 OR (r.role in ('admin', 'supevisor'))<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/466\/5c2\/6d2\/4665c26d24c73f7b24104160d49d8eb6.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\"><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0430 \u0431\u0430\u0437\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Casbin. <\/p>\n<p>  <\/p>\n<h2 id=\"podhod-s-ispolzovaniem-casbin\">\u041f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Casbin<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0447\u0442\u043e \u0440\u0435\u0441\u0443\u0440\u0441 \u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u0435 PERM \u2014 \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e <em><strong>\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/strong><\/em>, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0430 <strong>\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c<\/strong>.<br \/>  \u0422.\u0435. \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u0434 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (\u0442\u0430\u0431\u043b\u0438\u0446\u0430) \u0421\u0442\u0430\u0442\u044c\u044f. \u0410 \u043d\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u0441 Id=1 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440).<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0435 \u0440\u043e\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u2014 \u044d\u0442\u043e \u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u043e\u043b\u0438 \u0438\u0437 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 RBAC.<br \/>  \u0420\u043e\u043b\u0438 RBAC \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0442\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c RBAC \u0440\u043e\u043b\u044c <code>user<\/code> \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438, \u0440\u043e\u043b\u044c <code>author<\/code> \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0430 \u0440\u043e\u043b\u044c <code>user<\/code> (\u0442.\u0435. \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0435\u0439), \u0438 \u0435\u0449\u0435 \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0430 \u0440\u043e\u043b\u044c <code>admin<\/code> \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043f\u043b\u044e\u0441 \u0435\u0449\u0435 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438.<br \/>  \u0412 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0436\u0435 \u043d\u0430\u043c\u0438 \u0432\u044b\u0448\u0435 \u0437\u0430\u0434\u0430\u0447\u0435, \u043f\u043e \u0441\u0443\u0442\u0438, \u0432\u0441\u0435 \u044d\u0442\u0438 \u0432\u0441\u0435 \u0440\u043e\u043b\u0438 \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430. \u0418 <code>user<\/code> \u0438 <code>supervisor<\/code> \u0438 <code>admin<\/code> \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u043f\u0440\u0430\u0432\u0430, \u043e\u0434\u0438\u043d \u043d\u0430\u0431\u043e\u0440 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u0440\u043e\u043b\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c, \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, <code>user<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c. \u0410 <code>admin<\/code> \u0438 <code>supervisor<\/code> \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438, \u043d\u043e \u0435\u0449\u0435 \u0438 \u0447\u0443\u0436\u0438\u0435.<br \/>  \u0418 \u0432 \u044d\u0442\u043e\u043c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u043c\u043e\u0434\u0435\u043b\u0438 RBAC, \u0442\u0430\u043a \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0438 \u0441 \u0435\u0435 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b.<br \/>  \u041e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/custis\/blog\/248649\/\">\u041f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u0430: RBAC vs. ABAC<\/a><\/p>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435 \u0440\u043e\u043b\u0438, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c (<code>user<\/code>, <code>supervisor<\/code>,<code>admin<\/code>) \u2014 \u044d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u2014 <code>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u043e\u043b\u0438<\/code>. \u0422\u0435\u0440\u043c\u0438\u043d \u043d\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439, \u0438 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u043c \u043f\u043e\u0434 \u043d\u0438\u043c \u0441\u0432\u043e\u0435. \u041e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432\u043e\u043f\u0440\u043e\u0448\u0430\u044e\u0449\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u043b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432. <\/p>\n<p>  <\/p>\n<h3 id=\"vyborka-znacheniy-s-uchetom-dinamicheskih-roley\">\u0412\u044b\u0431\u043e\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c &quot;\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u043e\u043b\u0435\u0439&quot;<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 RBAC (<code>rbac_model.conf<\/code>), \u0435\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/539778\/#primer-2-kontrol-dostupa-na-osnove-roley-rbac\">\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/a> \u044f \u043f\u0440\u0438\u0432\u0435\u043b \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[request_definition] r = sub, obj, act  [policy_definition] p = sub, obj, act  [role_definition] g = _, _  [policy_effect] e = some(where (p.eft == allow))  [matchers] m = g(r.sub, p.sub) &amp;&amp; r.obj == p.obj &amp;&amp; r.act == p.act<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043c\u044b \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0440\u043e\u043b\u0435\u0439 <strong>Roles<\/strong>. \u0420\u043e\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 <code>*.csv<\/code> \u0444\u0430\u0439\u043b, \u0442\u0430\u043a \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c cvs \u0444\u0430\u0439\u043b <code>rbac_policy.csv<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">p, user, article, read p, user, article, modify p, user, article, create p, user, article, delete  g, supervisor, user g, admin, supervisor  g, 1, user g, 2, supervisor g, 3, admin<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0443\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0430\u044f, \u0447\u0442\u043e \u043c\u044b \u0434\u0430\u0435\u043c \u0440\u043e\u043b\u0438 <code>user<\/code> \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435, \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0435\u0439. \u0417\u0430\u0442\u0435\u043c \u0440\u043e\u043b\u044c <code>supervisor<\/code> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0440\u043e\u043b\u0438 <code>user.<\/code> \u0410 \u0440\u043e\u043b\u044c <code>admin<\/code> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0440\u043e\u043b\u0438 <code>supervisor<\/code>.<br \/>  \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e alice(1) \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0440\u043e\u043b\u044c <code>user<\/code>, bob(2) \u0443 \u043d\u0430\u0441 <code>supervisor<\/code>, \u0430 piter(3) \u2014 <code>admin<\/code>.<br \/>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0430\u0432\u0442\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430, \u0430 \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430 \u044f \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/lurumad.github.io\/cross-cutting-concerns-in-asp-net-core-with-meaditr\" rel=\"nofollow noopener noreferrer\">cross-cutting concern<\/a> \u0441 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/architecture\/microservices\/microservice-ddd-cqrs-patterns\/microservice-application-layer-implementation-web-api\" rel=\"nofollow noopener noreferrer\">CQRS+MediatR<\/a> <\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public IList&lt;Article&gt; GetArticlesForAdminPanel(int currentUserId) {     var e = new Enforcer(&quot;CasbinConfig\/rbac_model.conf&quot;, &quot;CasbinConfig\/rbac_policy.csv&quot;);      var obj = &quot;article&quot;;     var act = &quot;read&quot;;      \/\/\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0435\u0439     if (e.Enforce(currentUserId.ToString(), obj, act))     {         \/\/\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u043e\u043b\u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         var currentUserRoles = e.GetRolesForUser(currentUserId.ToString());         \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0430\u0434\u043c\u0438\u043d\u0438\u043e\u043c \u0438\u043b\u0438 \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440\u043e\u043c         var isAdmin = currentUserRoles.Any(x =&gt; x == &quot;admin&quot; || x == &quot;supervisor&quot;);          \/\/\u0415\u0441\u043b\u0438 \u0430\u0434\u043c\u0438\u043d, \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438, \u0438\u043d\u0430\u0447\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e         if (!isAdmin) return _context.Articles.Where(x =&gt; x.OwnerId == currentUserId).ToList();         else return _context.Articles.ToList();     }     else     {         \/\/ \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443         throw new Exception(&quot;403. \u0423 \u0432\u0430\u0441 \u043d\u0435\u0442 \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0435\u0439&quot;);        } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u0434\u0430\u043c! \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0430, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u0434\u0430\u043d. <\/p>\n<p>  <\/p>\n<h2 id=\"redaktirovanie-statey-s-uchetom-dinamicheskih-roley\">\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c &quot;\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u043e\u043b\u0435\u0439&quot;<\/h2>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043f\u043e\u0439\u0434\u0435\u043c \u0435\u0449\u0435 \u0434\u0430\u043b\u044c\u0448\u0435. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043b\u0438 \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435, \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0442\u0430\u0442\u044c\u044e. \u0418 \u043d\u0430\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0438\u043c\u0435\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u0440\u0430\u0432\u0430 \u0447\u0442\u043e\u0431\u044b \u0435\u0435 \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0440\u043e\u043b\u044c\u044e <code>user<\/code> \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, <code>supervisor<\/code> \u0438 <code>admin<\/code> \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0435 <code>rbac_with_abac_model.conf<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[request_definition] r = sub, obj, act  [policy_definition] p = sub, obj, act  [role_definition] g = _, _  [policy_effect] e = some(where (p.eft == allow))  [matchers] m = (r.sub == r.obj.OwnerId.ToString() || g(r.sub, &quot;supervisor&quot;)) &amp;&amp; g(r.sub, p.sub) &amp;&amp; r.act == p.act<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u044f, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u0435\u043a\u0446\u0438\u0438 <code>[matchers]<\/code>, \u0432 \u043d\u0435\u0439 \u043c\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>r.obj == p.obj<\/code> \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u043d\u0430 <code>(r.sub == r.obj.OwnerId.ToString() || g(r.sub, &quot;supervisor&quot;))<\/code>. \u042d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a <em>r.sub (id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f) \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u043f\u043e\u043b\u0435\u043c r.obj.OwnerId (id \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438) \u0438\u043b\u0438 r.sub \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0435 &quot;supervisor&quot;<\/em>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0433\u0440\u0443\u043f\u043f\u0430 <code>admin<\/code> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0430 \u0433\u0440\u0443\u043f\u043f\u044b <code>supervisor<\/code> \u0442\u043e \u0438 \u0447\u043b\u0435\u043d\u044b \u0433\u0440\u0443\u043f\u043f\u044b <code>admin<\/code> \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u0443. <\/p>\n<p>  <\/p>\n<p>\u0424\u0430\u0439\u043b \u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u043c\u0438 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c, \u0435\u0433\u043e \u043c\u044b \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u043a\u043e\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public void UpdateArticle(int currentUserId, Article newArticle) {     var e = new Enforcer(&quot;CasbinConfig\/rbac_with_abac_model.conf&quot;, &quot;CasbinConfig\/rbac_policy.csv&quot;);      var act = &quot;modify&quot;;      \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438     if (e.Enforce(currentUserId.ToString(), newArticle, act))     {         \/\/\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f         _context.Articles.Update(newArticle);         _context.SaveChanges();     }     else     {         \/\/ \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443         throw new Exception(&quot;403. \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0430\u0432&quot;);     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0432 \u043c\u0435\u0442\u043e\u0434 <code>e.Enforce<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Article<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0443 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433 \u2014 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<p>  <\/p>\n<h2 id=\"udalenie-stati\">\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438<\/h2>\n<p>  <\/p>\n<p>\u0411\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0443 \u043d\u0430\u0441 \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0440\u043e\u043b\u044c\u044e <code>user<\/code> \u043c\u043e\u0436\u0435\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u0442\u0430\u0442\u044c\u044e, <code>supervisor<\/code> \u2014 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0447\u0443\u0436\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0430 <code>admin<\/code> \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u043e \u0438\u043c\u0435\u0435\u0442.<br \/>  \u041e\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 PERM, \u0432 \u0444\u0430\u0439\u043b\u0435 <code>delete_model.conf<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[request_definition] r = sub, obj, act  [policy_definition] p = sub, obj, act  [role_definition] g = _, _  [policy_effect] e = some(where (p.eft == allow))  [matchers] m = (r.sub == r.obj.OwnerId.ToString() || g(r.sub, &quot;admin&quot;)) &amp;&amp; g(r.sub, p.sub) &amp;&amp; r.act == p.act<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043d\u0430 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0437\u0430 \u0442\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0447\u0443\u0436\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u043b\u0438 <code>admin<\/code>. \u0415\u0441\u043b\u0438 \u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c \u0440\u043e\u043b\u0438 <code>supervisor<\/code> \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0447\u0443\u0436\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u0443 \u043d\u0435\u0433\u043e \u0432\u044b\u0439\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u043c\u043e\u0447\u0438\u0439. <\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u043a\u043e\u0434 \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0430 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public void DeleteArticle(int currentUserId, Article deleteArticle) {     var e = new Enforcer(&quot;CasbinConfig\/delete_model.conf&quot;, &quot;CasbinConfig\/rbac_policy.csv&quot;);      var act = &quot;delete&quot;;      \/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438     if (e.Enforce(currentUserId.ToString(), deleteArticle, act))     {         \/\/\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u044e         _context.Articles.Remove(deleteArticle);         _context.SaveChanges();     }     else     {         \/\/ \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443         throw new Exception(&quot;403. \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0430\u0432&quot;);     } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"rezyume\">\u0420\u0435\u0437\u044e\u043c\u0435<\/h2>\n<p>  <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c, \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <strong>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Casbin \u0438 \u044f\u0437\u044b\u043a\u0430 PERM<\/strong> \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. <\/p>\n<p>  <\/p>\n<p>\u0415\u0449\u0435 \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u043a\u0430\u043a \u0441\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u0442\u0430\u043a \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0411\u0414. \u0418 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 <a href=\"https:\/\/casbin.org\/docs\/en\/policy-subset-loading\" rel=\"nofollow noopener noreferrer\">\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0430\u0432\u0438\u043b<\/a>, \u0435\u0441\u043b\u0438 \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0438 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0432 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. <\/p>\n<p>  <\/p>\n<p>Casbin \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/davideicardi\/DynamicExpresso\" rel=\"nofollow noopener noreferrer\">DynamicExpresso.Core<\/a> \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 C# \u043f\u0440\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u0440\u0430\u0432\u0438\u043b \u043f\u043e\u043b\u0438\u0442\u0438\u043a \u0441 \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Casbin \u0434\u0430\u0436\u0435 \u0432 \u0441\u0430\u043c\u044b\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. <\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0441\u0432\u043e\u044e \u043c\u043e\u043b\u043e\u0434\u043e\u0441\u0442\u044c, Casbin \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u043e\u0431\u0440\u0430\u0441\u0442\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438 API. \u0422\u0430\u043a\u0438\u043c\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a <a href=\"https:\/\/casbin.org\/docs\/en\/admin-portal\" rel=\"nofollow noopener noreferrer\">UI \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u043c\u0438<\/a>. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u0438 \u0441\u0430\u043c\u043e\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f <a href=\"https:\/\/github.com\/pprometey\/casbin-demo\" rel=\"nofollow noopener noreferrer\">\u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043b \u0443 \u0441\u0435\u0431\u044f \u043d\u0430 Github<\/a>, \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0435. <\/p>\n<p>  <\/p>\n<h2 id=\"poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/casbin.org\/docs\/en\/adapters\" rel=\"nofollow noopener noreferrer\">\u0421\u043f\u0438\u0441\u043e\u043a \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432 \u043a \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u043c, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a<\/a><\/li>\n<li><a href=\"https:\/\/casbin.org\/docs\/en\/model-storage\" rel=\"nofollow noopener noreferrer\">\u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441 Enforcer<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/casbin-net\/casbin-aspnetcore\" rel=\"nofollow noopener noreferrer\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f Casbin c ASP.NET Core, \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432<\/a><\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/540454\/\"> https:\/\/habr.com\/ru\/post\/540454\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e <a href=\"https:\/\/habr.com\/ru\/post\/539778\/\">\u044f\u0437\u044b\u043a\u0443 PERM \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Casbin<\/a>, \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/539778\/#comment_22609026\">\u0432\u043e\u043f\u0440\u043e\u0441\u044b<\/a>. \u041f\u0440\u0438\u0447\u0435\u043c \u043d\u0435 \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043d\u043e \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043b\u043e\u0436\u0443 \u044d\u0442\u043e\u0442 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. <\/p>\n<p>  <\/p>\n<p>\u042f \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u043c\u043e\u0433 \u043f\u043e\u043d\u044f\u0442\u044c \u0442\u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0438\u0434\u0435\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0443 \u0432\u043e\u043f\u0440\u043e\u0448\u0430\u044e\u0449\u0438\u0445, \u043d\u043e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u0441\u043b\u0435 \u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043e\u0442\u0432\u0435\u0442\u044b, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432 \u0446\u0438\u0442\u0430\u0442\u0435. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-317319","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/317319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317319"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/317319\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}