我正在使用 WCF 服务和 net.tcp 端点,并将 serviceAuthentication 的主体 PermissionMode 设置为 UseWindowsGroups。
目前,在服务的实现中,我使用PrincipalPermission 属性来设置每个方法的角色要求。
[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public string method1()
我正在尝试做几乎相同的事情,除了在 app.config 中设置角色的配置。有什么方法可以做到这一点并且仍然使用 Windows 组身份验证吗?
Thanks
如果您在 IIS 中托管 WCF 服务,它将在 ASP.NET 工作进程中运行,这意味着您可以像使用 ASMX Web 服务一样配置身份验证和授权:
<system.Web>
<authentication mode="Windows"/>
<authorization>
<allow roles=".\Administrators"/>
<deny users="*"/>
</authorization>
</system.Web>
然后,您必须在 IIS 中禁用对端点的匿名访问,并启用Windows 集成身份验证.
在 IIS 管理控制台中,您可以通过调出 '特性' 虚拟目录的对话框。然后您将在“目录安全' tab.
当然,唯一可用的通信通道是 HTTP。客户端必须在请求中提供其 Windows 身份传输层使用这些设置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WindowsSecurity">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/myservice"
binding="wsHttpBinding"
bindingConfiguration="WindowsSecurity"
contract="IMyService" />
</client>
</system.serviceModel>
请注意,如果您的服务端点使用wsHttpBinding那么您还必须将 SSL 添加到端点,因为这是使用传输级安全性时 WCF 强制执行的要求。
如果你选择基本Http绑定,然后您就可以使用不太安全WCF 中可用的身份验证模式称为仅传输凭证,其中不再需要 SSL。
欲了解更多详细信息,here很好地概述了 WCF 中的安全基础结构。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)