简体   繁体   English

如何仅为特定用户授予对IIS上托管的WCF Web服务的访问权限?

[英]How to give access to WCF web service hosted on IIS only for specific users?

I have a web service which uses Windows Authentication. 我有一个使用Windows身份验证的Web服务。 Web Service is hosted on IIS. Web服务托管在IIS上。 Is it possible to narrow access to that web service only to few specific users? 是否可以仅限少数特定用户访问该Web服务? My current web config: 我当前的网络配置:

<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>

By the way, I tried a solution similar to this, which I found over the Internet: 顺便说一句,我尝试了一个类似于此的解决方案,我在互联网上找到了:

    <authentication mode="Windows"/>

    <authorization>

          <allow roles=".\Developers"/>

          <allow users="DOMAIN\ServiceAccount"/>

          <deny users="*"/>

    </authorization>

It does not work though. 它不起作用。 :( It let all domain users pass through. :(它让所有域用户通过。

Wrox's Professional WCF 4 describes a way to set up UserName/Password authentication in Ch. Wrox的专业WCF 4描述了一种在Ch中设置UserName / Password身份验证的方法。 8. To summarize, you need a custom validator: 8.总而言之,您需要一个自定义验证器:

public class MyCustomUserNamePasswordValidator : UserNamePasswordValidator
{
   public override void Validate(string userName, string password)
   {
     if(userName != "foo" && password != "bar") 
     {
        throw new SecurityTokenValidationException("Invalid user");
     }
   }
}

After that you need to add modify your userNameAuthentication element in the service configuration to "Custom" and define the validator: 之后,您需要将服务配置中的userNameAuthentication元素修改为“Custom”并定义验证器:

 <userNameAuthentication
      userNamePasswordValidationMode = "Custom"
          customUserNamePasswordValidatorType =
          "Common.MyCustomUserNamePasswordValidator, Common" />

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM