我有一个关于WCF上的模拟的问题。我想连接到由客户端应用程序调用的WCF Windows服务上的DB。到DB的连接应该使用运行服务的帐户来完成。但是我想验证对WCF服务的调用是来自可信源(验证客户端应用程序的用户是域的经过身份验证的用户)。
你会建议我使用哪种安全措施?
我尝试了模拟,但是当我试图从windows服务连接到DB时,我得到了这个错误:
System.Data.SqlClient。日志示例:用户'NT AUTHORITYANONYMOUS LOGON'登录失败。
配置字符串像这样:
server=myServer;Initial Catalog=myDatabase;Integrated Security=True
服务的WCF配置如下所示:
<system.serviceModel>
<services>
<service name="MyNamespace.MyService"
behaviorConfiguration="TransfertServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8095/MyNamespace.MyService"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="TransactionalBinding"
contract="myContract" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TransactionalBinding"
transferMode="Streamed" transactionFlow="true" maxReceivedMessageSize="1000000000">
<readerQuotas maxDepth="10000" maxStringContentLength="1000000000"
maxArrayLength="1000000000" maxBytesPerRead="10000" maxNameTableCharCount="10000" />
<security mode="Transport" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TransfertServiceBehavior">
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>
</serviceBehaviors>
</behaviors>
客户端配置如下:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_Client" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="true" transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="1000000000"
maxBufferSize="1000000000" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="1000000000"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8095/MyNamespace.MyService"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Client"
contract="myContract" behaviorConfiguration="ImpersonationBehavior">
<identity>
<userPrincipalName value="myUsername@intra.myDomain.ca" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
如果您的WCF进行了模拟,那么您必须为WCF帐户服务启用Kerberos约束委托,另请参阅使用WCF进行委托和模拟。
配置受约束委托信任的WCF服务标识的详细说明:
- 在域控制器上启动Microsoft Management Console(MMC)活动目录用户和计算机管理单元。
- 在MMC管理单元的左窗格中,单击Computers节点。
- 在右窗格中,双击WCF服务器计算机到显示属性对话框。
- 在WCF服务器的属性窗口的Delegation选项卡上"不要信任委托的计算机"是由违约。若要使用约束委托,请选择信任此计算机用于仅委托给指定的服务。你要精确地指定
- 在"信任此计算机以委托给指定的服务"下面只使用Kerberos,保留默认选项。
- 单击"添加"按钮,显示"添加服务"对话框。
- 点击用户或计算机按钮。
在"选择用户或计算机"对话框中,键入您的如果将SQL server作为系统或数据库服务器计算机运行网络服务。
或者,如果您正在运行SQL Server,使用自定义域帐户,请输入该帐户名称,然后单击"确定"。您将看到为所选用户或配置的所有spn计算机帐户。要限制对SQL Server的访问,请选择
从你的服务配置中删除这一行:
<serviceAuthorization impersonateCallerForAllOperations="true" />
和客户端配置:
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
模拟意味着所有操作都将在模拟用户的上下文中完成=服务的标识被调用用户的标识替换。如果SQL服务器本地安装在运行Windows服务的机器上,那么对数据库的调用也将被模拟。
如果您关闭模拟,您将得到您想要的,因为在服务中执行将使用服务帐户,但服务将对每个调用客户端进行身份验证。这是通过您的netTcpBinding
配置完成的,它使用传输安全性和Windows集成身份验证。