2009-09-16 2 views
0

У меня возникла проблема, когда я подключаюсь к службе WCF с ISS и передаю учетные данные пула приложений IIS вместо учетных данных Windows. Когда я запускаю сайт локально, нажимая F5 в VS, он передает в мои учетные данные Windows, что и я хочу.WCF Security: неправильные учетные данные, переданные службе

Мой сайт настроен на использование проверки подлинности Windows, а анонимное auth отключено.

В окне просмотра событий Windows я вижу, что он не использует Kerberos для подключения к ядру IIS, он использует NTLM. Но я вижу, что он использует Kerberos при переходе от IIS к моей службе WCF с помощью:

OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.AuthenticationType.ToString() 

Я думаю, что следует использовать Kerberos при подключении к блоку IIS так что идеи там буду оценен?

Коробки и пользовательские настроены, чтобы позволить делегирование и я позволяет NETTCP связи и т.д. на мой

Вот мой хозяин конфигурации, который размещается с помощью консольного приложения на том же сервере, что и сервер IIS:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="defaultBinding" closeTimeout="02:02:00" openTimeout="02:01:00" 
      receiveTimeout="02:10:00" sendTimeout="02:02:00" maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647"> 
      <security mode="Transport" > 
      <transport clientCredentialType="Windows"/> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="defaultClientBehavior"> 
      <clientCredentials /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceConfigBehavior"> 
      <serviceMetadata httpGetEnabled="false" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceAuthorization impersonateCallerForAllOperations="true" /> 
      <serviceCredentials> 
      <windowsAuthentication includeWindowsGroups="true" allowAnonymousLogons="false" /> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="ServiceConfigBehavior" 
      name="ServiceConfig"> 
     <endpoint address="" behaviorConfiguration="" binding="netTcpBinding" 
      bindingConfiguration="defaultBinding" contract="IServiceConfig"> 
      <identity> 
      <servicePrincipalName value="nettcp/RDM" /> 
      <dns value="" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://ServerName:8731/ServiceConfig/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

Вот мой клиент конфигурации:

 </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
    </behaviors> 
    <bindings> 
    <netTcpBinding> 
    <binding name="NetTcpBinding_IServiceConfig" closeTimeout="00:01:00" 
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
    hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" 
    maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536"> 
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
     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://syrwp01:8731/ServiceConfig/" 
    behaviorConfiguration="defaultClientBehavior" binding="netTcpBinding" 
    bindingConfiguration="NetTcpBinding_IServiceConfig" contract="ServiceReference1.IServiceConfig" 
    name="NetTcpBinding_IServiceConfig"> 
    <identity> 
    <servicePrincipalName value="nettcp/RDM" /> 
    </identity> 
    </endpoint> 
    </client> 
    </system.serviceModel> 

А вот метод сервис, который называется:

[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]   
    public string PrintMessage(string msg) 
    { 
     Console.WriteLine(DateTime.Now.ToString()); 

     WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity; 
     Console.WriteLine("AuthenticationType: " + OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.AuthenticationType.ToString()); 
     Console.WriteLine("WindowsIdentity.GetCurrent(): {0}", WindowsIdentity.GetCurrent().Name); 

     using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate()) 
     { 
      Console.WriteLine("WindowsIdentity.GetCurrent(): {0}", WindowsIdentity.GetCurrent().Name); 
     } 
     Console.WriteLine("Method called successfully!"); 
    } 

ответ

2

Похоже случае Double Hop Problem. Сервер не может передать олицетворение учетных данных, которые он получил по сети другому хосту в большинстве ситуаций.

Вот blog post, описывающий это явление более подробно.

2

Убедитесь, что вы задаете

<system.web> 
    <identity impersonate="true" /> 
    <authentication mode="Windows" /> 
    <authorization> 
     <deny users="?" /> 
    </authorization> 
</system.web> 

Это гарантирует, что Анонимно Логин не допускается.

Кроме того, если вы хотите передать свои кредиты службе WCF, вам необходимо использовать делегирование. Создать поведение ваших сайтов web.config как это:

<behaviors> 
    <endpointBehaviors> 
    <behavior name="DelegationBehavior"> 
     <callbackDebug includeExceptionDetailInFaults="true" /> 
     <clientCredentials> 
     <windows allowedImpersonationLevel="Delegation" /> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

и использовать его в конечной точке с помощью behaviorConfiguration="DelegationBehavior".

Если это не сработает, попробуйте добавить <serviceAuthenticationManager authenticationSchemes="IntegratedWindowsAuthentication" /> в <serviceBehavior> -Tag в web.config WCF.

И не забудьте украсить свои методы WCF с:

[OperationBehavior(Impersonation = ImpersonationOption.Required)] 

или, в качестве альтернативы вы можете выдать себя за каждый вызов через дополнительный тег в <serviceBehavior>:

<serviceAuthorization impersonateCallerForAllOperations="true" /> 

Я в настоящее время испытывает другая проблема, но моя конфигурация, которая должна работать для вашего сценария, размещена здесь: My Stackoverflow Post

Я знаю, что это очень старое сообщение, b Надеюсь, это было полезно для кого-то, испытывающего ту же проблему.

Смежные вопросы