没有 SSL 但具有 Windows 组身份验证的 WCF 服务

标签 wcf ssl web-config windows-authentication

我们正在尝试创建一个只能由指定的 Windows 组访问的 WCF 服务。 如何在服务器 web.config 和客户端配置中进行配置?

注意:我们希望能够在服务器 web.config 中而不是在代码中控制允许访问的 Windows 组。此外,我们根本不需要/不需要 SSL。

我四处搜索,然后我能找到的最好的例子都是这样的......

WCF Service, Windows Authentication

但这并没有解释如何将访问权限限制为仅特定的一个或多个组。

最佳答案

如果这是 Intranet 应用程序,您可以使用 netTcpBinding:

<services>
   <service name="YourService"
      behaviorConfiguration="YourServiceBehavior">
      <endpoint 
         binding="netTcpBinding"
         bindingConfiguration="SecureTransportWindows"
         contract="YourContract" />
   </service>
</services>

<bindings>
   <binding name="SecureTransportWindows">
      <security mode="Transport">
          <transport clientCredentialType="Windows" />
      </security>
   </binding>
</bindings>

<behaviors>
   <serviceBehaviors>
      <behavior name="YourServiceBehavior">          
          <serviceAuthorization principalPermissionMode="UseWindowsGroups" />
      </behavior>
   </serviceBehaviors>
</behaviours>

然后在服务代码中你可以请求窗口角色:

class YourService : YourContract
{
    [PrincipalPermission(SecurityAction.Demand, Role="MYDOMAIN\Administrators")]
    public string SecuredOperation(string name)
    {
       return "secured operation";
    }
}

如果你需要在配置中设置它,那么你必须实现自定义授权:

<behavior name="YourServiceBehavior">          
   <serviceAuthorization principalPermissionMode="Custom">            
      <authorizationPolicies>
         <add policyType="YourCustomAuthorizationPolicy"/>
      </authorizationPolicies>          
   </serviceAuthorization>
</behavior>

并在代码中实现 IAuthorizationPolicy 接口(interface):

public class YourCustomAuthorizationPolicy : IAuthorizationPolicy
{
   //you need to check msdn 
}

关于没有 SSL 但具有 Windows 组身份验证的 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10593897/

相关文章:

ASP.NET/Web.config : customErrors redirect only on a 404

asp.net - 保存 web.config 错误 访问被拒绝

wcf - 使用 RealProxy 包装多个 WCF 连接

javascript - 从 wcf 服务返回的 json 日期不一致

ssl - 无法在 golang 上将 *tls.listener 转换为 *net.TCPListener

java - 发生 MQException : Completion Code 2, 原因 2400 MQJE011:套接字连接尝试被拒绝

ssl - 如何为从主机文件指向的域创建 ssl?

ASP.Net/web.config - "The entry ' x' 已经输入”?

c# - 如何避免为 WCF 中值为 Nothing 的属性创建 xml 标记?

wcf - Oracle ESB、WS-AT 和 WCF