2011-10-28 27 views
6

Tôi có dịch vụ web sử dụng Xác thực Windows. Dịch vụ Web được lưu trữ trên IIS. Có thể thu hẹp quyền truy cập vào dịch vụ web đó chỉ cho một số người dùng cụ thể không? hiện tại web cấu hình của tôi:Làm cách nào để cấp quyền truy cập vào dịch vụ web WCF được lưu trữ trên IIS chỉ dành cho người dùng cụ thể?

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

Bằng cách này, tôi đã cố gắng một giải pháp tương tự như sau, mà tôi tìm thấy trên Internet:

<authentication mode="Windows"/> 

    <authorization> 

      <allow roles=".\Developers"/> 

      <allow users="DOMAIN\ServiceAccount"/> 

      <deny users="*"/> 

    </authorization> 

Nó không làm việc Tuy nhiên. :(Nó cho phép tất cả người dùng miền đi qua

+0

bạn khuyết tật xác thực ẩn danh và cho phép xác thực Windows cho ứng dụng lưu trữ dịch vụ WCF của bạn trong IIS? –

+0

Có, tôi đã làm điều đó. – neurotix

Trả lời

4

Wrox của Professional WCF 4 mô tả một cách để thiết lập username/password authentication trong Ch 8. Để tóm tắt, bạn cần một validator tùy chỉnh:..

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

Sau đó bạn cần thêm sửa đổi phần tử userNameAuthentication của bạn trong cấu hình phục vụ "Custom" và xác định các validator:.

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

tôi hy vọng điều này sẽ giúp

+1

Okey Ill thử, nhưng tôi không tin rằng bạn không thể thực sự làm cho nó hoạt động mà không cần sửa đổi mã WS. Im vẫn hy vọng tôi có thể làm cho nó hoạt động chỉ bằng cách thay đổi cấu hình web. – neurotix

Các vấn đề liên quan