2013-12-10 2 views
0

wsHttpBinding을 사용하는 IIS 8에서 호스팅되는 간단한 WCF 서비스가 있습니다. 나는 사용자 (도메인 계정)가 서비스에 액세스 할 수 있도록 제어 할 수 있기를 원합니다. 어떻게해야합니까? 아마도 이것을 수행하는 몇 가지 방법이있을 것입니다. web.config 파일에서 계정을 정의 할 수 있습니까? 아니면 IIS에서이 계정을 설정할 수 있습니까?wsHttpBinding, 특정 계정에 서비스 액세스 허용

+0

가능한 복제본 http://stackoverflow.com/questions/13326365/best-way-to-limit-wcf-service-to-specific-user-accounts –

답변

1

당신은 사용자 정의 인증 프로그램을 사용할 수 있습니다.

UserNamePasswordValidator을 System.IdentityModel.Selectors 네임 스페이스에서 상속해야합니다. 서버에 대한

Sample from MSDN

public class ServiceValidator : UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 

     if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password)) 
     { 
      throw new SecurityTokenException("Username and password required"); 
     } 
     else 
     { 
      if (Authenticate(userName, password)) 
      { 
       // no need to do anything else if authentication was successful. the request will be redirected to the correct web service method. 
      } 
      else 
      { 
       throw new FaultException("Wrong username or password "); 
      } 
     } 

의 Web.config은 :

<behaviors> 
    <serviceBehaviors> 
    <behavior name="SomeServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyApp.ServiceValidator, MyApp" /> 
     <serviceCertificate findValue="CertificateNameHere" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName" /> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
<bindings> 
    <wsHttpBinding> 
    <binding name="RequestUserName"> 
     <security mode="Message"> 
     <message clientCredentialType="UserName" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

이것은 당신이 시간 것의 기본이다 구현할 수 있습니다. 그런 다음 Authenticate/Authorize 메서드에서 웹 서비스 메서드에 대한 호출을 허용해야하는 사용자를 제한 할 수 있습니다.

관련 문제