
Web服务公开客户端应用程序要访问的多个API或方法,如下所示:
[OperationContract] bool Read(); [OperationContract] bool Write();
所有客户端都应该可以访问Read()方法
Write()方法只能由属于Active Directory维护的特定windows用户组的用户访问.
题:
我们如何根据客户端在AD中维护的用户组来过滤或限制公开的接口或方法?
jrista,
感谢您的回复.我尝试了与PrincipalPermission相同的指令,如下所示:
[PrincipalPermission(SecurityAction.Demand,Role = "Readers")][OperationContract]bool Read();[PrincipalPermission(SecurityAction.Demand,Role = "Writers")][OperationContract]bool Write();
但它不起作用.读组用户也可以调用Writer()方法,而Writer组用户也可以调用Write()方法.
我想告诉你的一件事是我在web.config文件中使用BasichttpBind,如下所示:
<system.serviceModel> <bindings> <basichttpBinding> <binding name="BasichttpBind"> <security mode="TransportCredentialOnly"> <transport clIEntCredentialType="windows" proxyCredentialType="windows" /> </security> </binding> </basichttpBinding> </bindings> <services> <service name="DXDirectory.DXDirectoryService" behaviorConfiguration="DXDirectory.Service1Behavior"> <!-- Service Endpoints --> <endpoint address="" binding="basichttpBinding" bindingConfiguration="BasichttpBind" name="BasicBinding" contract="DXDirectory.IDXDirectoryService"> <!-- Upon deployment,the following IDentity element should be removed or replaced to reflect the IDentity under which the deployed service runs. If removed,WCF will infer an appropriate IDentity automatically. --> <IDentity> <dns value="localhost" /> </IDentity> </endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="DXDirectory.Service1Behavior"> <!-- To avoID disclosing Metadata information,set the value below to false and remove the Metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true" /> <!-- To receive exception details in faults for deBUGging purposes,set the value below to true. Set to false before deployment to avoID disclosing exception information --> <serviceDeBUG includeExceptionDetailinFaults="false" /> <serviceAuthorization principalPermissionMode="UsewindowsGroups"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
是否需要为此功能实现wshttpBinding?如果是,那么如何在我的Web服务中实现wshttpBinding?
解决方法 我不确定如何将AD凭证集成到正常的.NET安全框架中.但是,它是可能的(我会看看我是否可以找到一些链接),一旦你这样做,你应该能够使用标准的安全属性来检查一个“角色”,它将对应于你的AD组:[OperationContract]bool Read();[PrincipalPermission(SecurityAction.Demand,Role = "Writers")][OperationContract]bool Write();
要使用AD组,请配置服务行为:
<system.serviceModel> <behaviors> <serviceBehaviors> <adServiceBehavior> <serviceAuthorization principalPermissionMode="UsewindowsGroups" /> </adServiceBehavior> </serviceBehaviors> </behaviors></system.serviceModel>
有另一个想法.有时希望甚至根本不在接口上使用Write()方法.使用WCF,您可以在单个服务类上实现多个服务契约接口.一个理想的解决方案可能是创建两个服务契约接口,一个使用Read()和Write(),一个只使用Read().根据登录到客户端的用户,您可以对只有读访问权限的用户使用Read()接口,对有权访问这些用户的人使用Read()/ Write()接口.这还允许您向不应具有写访问权限的客户端公开最安全的服务合同,同时在内部使用读/写合同进行管理.您永远不会暴露可能以这种方式被利用的代码.
总结以上是内存溢出为你收集整理的基于用户组限制WCF Web服务功能全部内容,希望文章能够帮你解决基于用户组限制WCF Web服务功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)