【发布时间】:2009-08-27 18:43:54
【问题描述】:
我有一个由 C# 客户端应用程序使用的 WCF Web 服务。我还有 4 个组存储在 Active Directory 中。客户端应用程序正在传递用户凭据以连接此 Web 服务。
Web 服务公开多个 API 或方法供客户端应用程序访问,如下所示:
[OperationContract]
bool Read();
[OperationContract]
bool Write();
Read() 方法应该可供所有客户端访问
只有属于 Active Directory 维护的特定 windows 用户组的用户才能访问 Write() 方法。
问题: 我们如何根据客户端在AD中维护的用户组过滤或限制暴露的接口或方法?
jrista, 感谢您的回复。我尝试了与 PrincipalPermission 相同的指令,如下所示:
[PrincipalPermission(SecurityAction.Demand, Role = "Readers")]
[OperationContract]
bool Read();
[PrincipalPermission(SecurityAction.Demand, Role = "Writers")]
[OperationContract]
bool Write();
但它不起作用。读组用户也可以调用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?
【问题讨论】:
-
如果您在 IIS 中托管,服务器是否设置为允许匿名?
-
否,匿名未选中,集成 Windows 身份验证已选中。基本和摘要式身份验证未选中。
-
我发现由于某种原因,WCF 无法识别合约接口上的声明性安全性,它必须在实际实现上。