{"id":4750,"date":"2017-10-20T15:57:58","date_gmt":"2017-10-20T07:57:58","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4750"},"modified":"2017-10-20T15:57:58","modified_gmt":"2017-10-20T07:57:58","slug":"qsecurityqsecurity-%e4%bd%bf%e7%94%a8%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4750","title":{"rendered":"[QSecurity]QSecurity \u4f7f\u7528\u5165\u95e8\u6307\u5357"},"content":{"rendered":"<p>QSecurity \u662f QPlugins \u7684\u5b89\u5168\u76f8\u5173\u63d2\u4ef6\u63a5\u53e3\u53ca\u5176\u5b9e\u73b0\uff0c qplugins_security.pas \u5b9a\u4e49\u4e86\u5b89\u5168\u76f8\u5173\u7684\u63a5\u53e3\uff0c\u6211\u4eec\u5728\u63d2\u4ef6\u4e2d\u4f7f\u7528\u65f6\uff0c\u53ea\u9700\u8981\u5f15\u7528\u8fd9\u4e2a\u63a5\u53e3\u6587\u4ef6\u5c31\u53ef\u4ee5\u4e86\u3002\u800c\u670d\u52a1\u7684\u5b9e\u73b0\u5355\u5143\u5e76\u4e0d\u5305\u542b\u5728\u514d\u8d39\u5f00\u6e90\u7684\u8303\u56f4\u5185\uff0c\u5982\u679c\u60a8\u4e0d\u60f3\u81ea\u5df1\u5b9e\u73b0\uff0c\u6216\u8005\u60f3\u53c2\u8003\u5b9e\u73b0\uff0c\u9700\u8981\u4ed8\u8d39\u8d2d\u4e70\uff0c\u4ef7\u683c\u4e3a\u4eba\u6c11\u5e01 99.00 \u5143\u3002<\/p>\n<p>\u65e0\u8bba\u662f\u6211\u7684\u5b9e\u73b0\uff0c\u8fd8\u662f\u60a8\u81ea\u5df1\u53bb\u5b9e\u73b0\u8fd9\u4e9b\u63a5\u53e3\uff0c\u5b83\u7684\u7528\u6cd5\u662f\u4e00\u6837\u7684\uff0c\u6240\u4ee5\u8fd9\u4e2a\u5165\u95e8\u6559\u7a0b\u9002\u5408\u517c\u5bb9\u4e8eqplugins_security \u63a5\u53e3\u7684\u6240\u6709\u5b9e\u73b0\u3002<\/p>\n<h4>\u4e00\u3001\u67e5\u627e IQSecurityService \u670d\u52a1<\/h4>\n<p>\u67e5\u627e IQSecurityService \u670d\u52a1\u63a5\u53e3\u548c\u67e5\u627e\u666e\u901a\u7684\u670d\u52a1\u662f\u4e00\u6837\u7684\uff0c\u6709\u591a\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4f60\u4e0d\u77e5\u9053\u670d\u52a1\u7684\u8def\u5f84\uff0c\u90a3\u4e48\u76f4\u63a5\u901a\u8fc7 PluginsManager \u6765\u67e5\u627e IQSecurityService \u5b9e\u4f8b\u5373\u53ef\uff0c\u5f53\u7136\u8fd9\u5e76\u4e0d\u662f\u6548\u7387\u6700\u9ad8\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a PluginsManager \u4f1a\u904d\u5386\u67e5\u627e\u6240\u6709\u6ce8\u518c\u7684\u63a5\u53e3\u53ca\u670d\u52a1\uff0c\u4ee5\u4fbf\u627e\u5230\u5b83\u3002\u4f46\u5b83\u662f\u6700\u6613\u7528\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u5728 Delphi \u4e2d\uff0c\u53ef\u4ee5\uff1a\n<pre class=\"lang:delphi decode:true\">var\r\n   AService:IQSecurityService;\r\nbegin\r\n  AService:=PluginsManager as IQSecurityService;\r\n  ....\r\nend;<\/pre>\n<p>\u6216\u8005<\/p>\n<pre class=\"lang:delphi decode:true\">var\r\n   AService:IQSecurityService;\r\nbegin\r\n  if Supports(PluginsManager ,IQSecurityService ,AService then\r\n     begin\r\n     ....\r\n     end;\r\nend;<\/pre>\n<p>\u6216\u8005\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">var\r\n   AService:IQSecurityService;\r\nbegin\r\n  if PluginsManager.QueryInterface(IQSecurityService ,AService)=S_OK then\r\n     begin\r\n     ....\r\n     end;\r\nend;<\/pre>\n<p>\u5f53\u7136\uff0c\u8fd9\u51e0\u79cd\u65b9\u5f0f\u672c\u8eab\u6ca1\u5565\u4f18\u52a3\u4e4b\u5206\uff0c\u7b2c\u4e00\u79cd\u8981\u6c42\u670d\u52a1\u5fc5\u9700\u5df2\u7ecf\u6ce8\u518c\u624d\u80fd\u4f7f\u7528\uff0c\u800c\u540e\u4e24\u79cd\u90fd\u4f1a\u5224\u5b9a\u662f\u5426\u5b58\u5728\u76f8\u5e94\u7684\u63a5\u53e3\u3002\u5982\u679c\u786e\u8ba4\u652f\u6301\u76f8\u5e94\u7684\u670d\u52a1\uff0c\u90a3\u5c31\u653e\u5fc3\u4f7f\u7528\u7b2c\u4e00\u79cd\u65b9\u5f0f\uff0c\u5b83\u5728 Delphi \u4e2d\u6700\u65b9\u4fbf\u3002<\/li>\n<li>\u5982\u679c\u60a8\u77e5\u9053\u670d\u52a1\u7684\u8def\u5f84\uff0c\u6309\u6ce8\u518c\u8def\u5f84\u67e5\u627e\u66f4\u5feb\u4e00\u4e9b\uff0c\u6211\u5b9e\u73b0\u7684\u670d\u52a1\u6ce8\u518c\u8def\u5f84\u4e3a \/Services\/Security\uff0c\u6240\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u5b50\u8c03\u7528\uff1a\n<pre class=\"lang:delphi decode:true\">var\r\n   AService:IQSecurityService;\r\nbegin\r\n   AService:=PluginsManager.ByPath('\/Services\/Security') as IQSecurityService;\r\n   ....\r\nend;<\/pre>\n<\/li>\n<\/ul>\n<h4>\u4e8c\u3001\u6ce8\u518c\u81ea\u5df1\u6a21\u5757\u7684\u6743\u9650<\/h4>\n<p>\u5bf9\u4e8e\u677e\u6563\u8026\u5408\u7684\u5e94\u7528\u5f00\u53d1\u6765\u8bf4\uff0c\u4f60\u6c38\u8fdc\u4e0d\u77e5\u9053\u5565\u65f6\u5019\u589e\u52a0\u5565\u6a21\u5757\uff0c\u800c\u589e\u52a0\u6a21\u5757\u5c31\u610f\u5473\u7740\u53ef\u80fd\u589e\u52a0\u65b0\u6743\u9650\u9879\u76ee\u3002QPlugins Security \u6a21\u5757\u5c06\u8fd9\u4e00\u6b65\u4ea4\u7531\u63d2\u4ef6\u81ea\u8eab\uff0c\u201c\u81ea\u4e8b\u81ea\u77e5\u201d\uff0c\u901a\u8fc7\u542f\u52a8\u65f6\u6ce8\u518c\u81ea\u5df1\u7684\u6743\u9650\uff0c\u7136\u540e\u6388\u6743\u6a21\u5757\u5c31\u53ef\u4ee5\u4e3a\u7528\u6237\u8fdb\u884c\u6388\u6743\u3002<\/p>\n<p>\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff08\u6211\u4eec\u7ee7\u7eed\u63a5\u4e0a\u9762\u7684 AService\uff09\u662f\u5b89\u5168\u7ba1\u7406\u670d\u52a1\u6ce8\u518c\u81ea\u5df1\u7684\u6743\u9650\uff1a<\/p>\n<ol>\n<li>\u5b9a\u4e49\u6743\u9650\u7684ID\uff0c\u5b83\u662f\u4e00\u4e2aGUID\u7f16\u7801\uff0c\u4f60\u81ea\u5df1\u6a21\u5757\u968f\u610f\u5b9a\u4e49\u5c31\u53ef\u4ee5\uff0c\u4e0d\u9700\u8981\u5173\u5fc3\u5176\u5b83\u6a21\u5757\u7684\u5b9a\u4e49\uff0c\u6bd5\u7adf\u4f60\u7528 Ctrl+Shift+G \u751f\u6210\u7684\u968f\u673a\u7684 GUID \u7f16\u7801\u4e0e\u5176\u5b83\u4eba\u5b9a\u4e49\u91cd\u590d\u7684\u53ef\u80fd\u6027\u5f88\u4f4e\u3002\u8fd9\u4e2a ID \u662f\u4f60\u7a0b\u5e8f\u4e2d\u68c0\u67e5\u6743\u9650\u7684\u57fa\u7840\uff0c\u4e00\u822c\u6211\u4eec\u4f1a\u4e3a\u6743\u9650\u8fdb\u884c\u5206\u7ec4\uff0c\u8c61\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u5b9a\u4e49\u7684\u662f\u4e00\u4e2a\u5206\u7ec4ID\uff0c\u4e24\u4e2a\u5b50\u9879\u6743\u9650\uff1a\n<pre class=\"lang:delphi decode:true\">const\r\n  \/\/ \u89d2\u8272\u53ca\u6743\u9650\u7ba1\u7406\u5206\u7ec4ID\r\n  SID_SECURITY_GROUP: TGuid = '{110CA18E-4B52-4D75-B3F3-9C99DC2B76FE}';\r\n  \/\/ \u67e5\u770b\u5176\u5b83\u7528\u6237\u8d26\u53f7\u53ca\u6743\u9650\r\n  SID_SECURITY_VIEW: TGuid = '{B02A4134-3563-42A0-825E-C90BB5DD031E}'; \/\/\r\n  \/\/ \u4fee\u6539\u5176\u5b83\u7528\u6237\u8d26\u53f7\u53ca\u6743\u9650\u7b49\u8d44\u6599\r\n  SID_SECURITY_EDIT: TGuid = '{800896A0-E733-48BB-8CB4-857EC83F6F89}';<\/pre>\n<\/li>\n<li>\u5728\u63d2\u4ef6\u7684 initialization \u91cc\uff0c\u6ce8\u518c\u6743\u9650\uff1a\n<pre class=\"lang:delphi decode:true\">var\r\n   ARights:IQSecurityRights;\r\n   AService:IQSecurityService;\r\nbegin\r\nwith PluginsManager as IQSecurityService do\r\n   begin\r\n   \/\/\u6ce8\u518c\u5206\u7ec4\r\n   ARights:=IQSecurityRights(GetRootRight).AddGroup(SID_SECURITY_GROUP,\r\n      '\u8d26\u53f7\u53ca\u6743\u9650\u7ba1\u7406', TQAccessRight.arDeny);\r\n   \/\/\u6ce8\u518c\u5b50\u6743\u9650\r\n   ARights.AddRight(SID_SECURITY_VIEW, '\u67e5\u770b\u5b58\u5728\u7684\u8d26\u53f7\u53ca\u89d2\u8272\u4fe1\u606f', TQAccessRight.arDeny);\r\n   ARights.AddRight(SID_SECURITY_EDIT, '\u7ba1\u7406\u8d26\u53f7\u3001\u89d2\u8272\u53ca\u5176\u6743\u9650', TQAccessRight.arDeny);\r\n   end;\r\nend;\r\n<\/pre>\n<p>\u6ce8\u518c\u5b8c\u6210\u540e\uff0c\u5185\u5b58\u4e2d\u5c31\u6709\u4e86\u76f8\u5e94\u7684\u6743\u9650\u5bf9\u8c61\u3002<\/li>\n<\/ol>\n<h4>\u4e09\u3001\u5224\u65ad\u5f53\u524d\u7528\u6237\u6743\u9650<\/h4>\n<p>\u5728\u9700\u8981\u5224\u65ad\u6743\u9650\u7684\u5730\u65b9\uff0c\u901a\u8fc7 IQSecurityService.CanAccess \u5373\u53ef\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">with PluginsManager as IQSecurityService do\r\n   begin\r\n     btnView.Visible:=CanAccess(SID_SECURITY_VIEW);\r\n     btnEdit.Visible:=CanAccess(SID_SECURITY_EDIT);\r\n   end;<\/pre>\n<p>QSecurity \u7528\u6237\u6743\u9650\u68c0\u9a8c\u7684\u89c4\u5219\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u7528\u6237\u5982\u679c\u672a\u767b\u5f55\uff0c\u5219\u6839\u636e\u6743\u9650\u5bf9\u8c61\u9ed8\u8ba4\u6743\u9650\u5b9a\u4e49\u8fd4\u56de\uff1b\u5982\u679c\u9ed8\u8ba4\u6743\u9650\u4e0d\u662f\u660e\u786e\u7684\u5141\u8bb8\u6216\u62d2\u7edd\uff0c\u5219\u7ee7\u627f\u81ea\u5168\u5c40\u7684\u9ed8\u8ba4\u6743\u9650\u3002\u5728\u6211\u7684\u5b9e\u73b0\u4e2d\uff0c\u5b83\u662f\u62d2\u7edd\u3002\u5982\u679c\u4f60\u786e\u5b9a\u67d0\u4e2a\u6743\u9650\u9ed8\u8ba4\u5f00\u901a\uff0c\u90a3\u4f60\u53ef\u4ee5\u5728\u4e0a\u4e00\u6b65\u6ce8\u518c\u6743\u9650\u65f6\uff0c\u5c06\u9ed8\u8ba4\u6743\u9650\u8bbe\u7f6e\u4e3a arAllow \u5373\u53ef\u3002<\/li>\n<li>\u5982\u679c\u7528\u6237\u5df2\u7ecf\u767b\u5f55\uff0c\u5219\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u6267\u884c\uff1a<br \/>\n\uff081\uff09\u5728\u5f53\u524d\u767b\u5f55\u7528\u6237\u7ea7\u522b\u4e0a\uff0c\u660e\u786e\u4e86\u5141\u8bb8\u8fd8\u662f\u62d2\u7edd\uff0c\u5219\u8fd4\u56de\u660e\u786e\u7684\u7ed3\u679c\uff1b\u5982\u679c\u6ca1\u6709\uff0c\u5219\u68c0\u67e5\u6709\u6ca1\u6709\u660e\u786e\u5141\u8bb8\u5176\u7236\u6743\u9650\u5206\u7ec4\u5b9a\u4e49\uff0c\u5982\u679c\u4ecd\u6ca1\u6709\uff0c\u5219\u904d\u5386\u81ea\u5df1\u7236\u89d2\u8272\u6267\u884c\u540c\u6837\u7684\u64cd\u4f5c\uff0c\u4ee5\u6700\u7ec8\u786e\u5b9a\u6743\u9650\u3002<br \/>\n\uff082\uff09\u5982\u679c\u5f53\u524d\u7528\u6237\u591a\u4e2a\u7236\u89d2\u8272\u5bf9\u540c\u4e00\u5bf9\u8c61\u7684\u8bbf\u95ee\u6743\u9650\u6709\u51b2\u7a81\uff0c\u90a3\u4e48\u6309\u7528\u6237\u672a\u767b\u5f55\u65f6\uff0c\u68c0\u67e5\u6743\u9650\u7684\u89c4\u5219\u6765\u5904\u7406\u3002<\/li>\n<\/ol>\n<h4>\u56db\u3001\u6ce8\u6d88\u6743\u9650\u6ce8\u518c<\/h4>\n<p>QSecurity \u4e0d\u652f\u6301\u6743\u9650\u7684\u6ce8\u9500\uff0c\u4e5f\u4e0d\u9700\u8981\u63d2\u4ef6\u91ca\u653e\u76f8\u5173\u7684\u6743\u9650\u5bf9\u8c61\u5b9e\u4f8b\u3002<\/p>\n<h4>\u4e94\u3001\u5bf9\u63d2\u4ef6\u4fee\u6539\u5f53\u524d\u7528\u6237\u6743\u9650\u7684\u652f\u6301<\/h4>\n<p>\u51fa\u4e8e\u5b89\u5168\u539f\u56e0\uff0cQSecurity \u4e0d\u5141\u8bb8\u5176\u5b83\u63d2\u4ef6\u53bb\u4fee\u6539\u6743\u9650\uff0c\u76f8\u5173\u7684\u63a5\u53e3\u4e5f\u4e0d\u516c\u5f00\u7ed9\u5176\u5b83\u63d2\u4ef6\u4f7f\u7528\u3002\u8981\u4fee\u6539\u5f53\u524d\u7528\u6237\u7684\u6743\u9650\uff0c\u901a\u8fc7 IQSecurityService \u7684 Config \u63a5\u53e3\u6765\u6253\u5f00\u6743\u9650\u7ba1\u7406\u754c\u9762\u6765\u4fee\u6539\u3002\u5982\u679c\u5f53\u524d\u767b\u5f55\u7528\u6237\u6743\u9650\u53d1\u751f\u53d8\u52a8\uff0c\u8fd8\u4f1a\u53d1\u9001 SNotify_RightsChanged \u901a\u77e5\u3002<\/p>\n<p>\u66f4\u591a\u63a5\u53e3\u8bf4\u660e\uff0c\u8bf7\u53c2\u8003 qplugins_security \u4e2d\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u7684\u8bf4\u660e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>QSecurity \u662f QPlugins [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,9,50,603],"tags":[441,738],"class_list":["post-4750","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-qplugin","category-603","tag-qplugins","tag-qsecurity"],"views":4246,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4750"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4750\/revisions"}],"predecessor-version":[{"id":4751,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4750\/revisions\/4751"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}