neu*_*tix 6 c# wcf web-services
我有一个使用Windows身份验证的Web服务.Web服务托管在IIS上.是否可以仅限少数特定用户访问该Web服务?我当前的网络配置:
<services>
<service name="LANOS.SplunkSearchService.SplunkSearch">
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttp"
contract="LANOS.SplunkSearchService.ISplunkSearch" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true" maxBufferSize="20000000"
maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxDepth="32" maxStringContentLength="200000000"
maxArrayLength="200000000" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我尝试了一个类似于此的解决方案,我在互联网上找到了:
<authentication mode="Windows"/>
<authorization>
<allow roles=".\Developers"/>
<allow users="DOMAIN\ServiceAccount"/>
<deny users="*"/>
</authorization>
Run Code Online (Sandbox Code Playgroud)
它不起作用.:(它让所有域用户通过.
Wrox 的Professional WCF 4在第 1 章中描述了一种设置用户名/密码身份验证的方法。8. 总而言之,您需要一个自定义验证器:
public class MyCustomUserNamePasswordValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if(userName != "foo" && password != "bar")
{
throw new SecurityTokenValidationException("Invalid user");
}
}
}
Run Code Online (Sandbox Code Playgroud)
之后,您需要将服务配置中的 userNameAuthentication 元素添加修改为“自定义”并定义验证器:
<userNameAuthentication
userNamePasswordValidationMode = "Custom"
customUserNamePasswordValidatorType =
"Common.MyCustomUserNamePasswordValidator, Common" />
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助。
| 归档时间: |
|
| 查看次数: |
1015 次 |
| 最近记录: |