2009-09-16 13 views
0

J'ai un problème lorsque je me connecte à un service WCF d'ISS et qu'il transmet les informations d'identification du pool d'applications IIS au lieu de mes informations d'identification Windows. Quand je cours le site localement en appuyant sur F5 dans VS il passe dans mes identifiants de Windows qui est ce que je veux.Sécurité WCF: les informations d'identification incorrectes sont passées au service

Mon site Web est configuré pour utiliser l'authentification Windows et l'authentification anonyme est désactivée.

Je peux voir dans l'Observateur d'événements Windows qu'il n'utilise pas Kerberos pour se connecter à la boîte sur laquelle IIS est allumé, il utilise NTLM. Mais je peux voir qu'il est en utilisant Kerberos lors du passage d'IIS à mon service WCF en utilisant:

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

Je pense qu'il devrait utiliser Kerberos lors de la connexion à la boîte IIS donc une idées, il serait apprécié?

Les boîtes et l'utilisateur sont configurés pour permettre la délégation et moi-même avons permet etc communication NetTcp sur mon

Voici ma config hôte qui est hébergé à l'aide d'une application de la console sur le même serveur que le serveur 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> 

Voici ma config client:

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

Et voici la méthode de service qui est appelé:

[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!"); 
    } 

Répondre

2

Sons comme un cas de Double Hop Problem. Le serveur ne peut pas transmettre l'usurpation d'identité des informations d'identification qu'il a reçues sur le réseau à un autre hôte dans la plupart des cas.

Voici un blog post décrivant ce phénomène plus en détail.

2

Assurez-vous que vous spécifiez

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

Cela garantit que connexion anonyme n'est pas autorisé.

En outre, si vous souhaitez transmettre vos droits au service WCF, vous devez utiliser la délégation. Créer un comportement dans vos sites web.config comme ceci:

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

et l'utiliser dans votre terminal via behaviorConfiguration="DelegationBehavior".

Si cela ne fonctionne pas, essayez d'ajouter <serviceAuthenticationManager authenticationSchemes="IntegratedWindowsAuthentication" /> au <serviceBehavior> -Tag dans le fichier web.config de la WCF.

Et ne pas oublier de décorer vos méthodes WCF avec:

[OperationBehavior(Impersonation = ImpersonationOption.Required)] 

ou bien vous pouvez passer pour chaque appel via une balise supplémentaire <serviceBehavior>:

<serviceAuthorization impersonateCallerForAllOperations="true" /> 

Je rencontre actuellement un autre problème, mais ma configuration qui devrait fonctionner pour votre scénario est affichée ici: My Stackoverflow Post

Je sais que c'est un très vieux post, b J'espère que cela a été utile à quelqu'un qui connaît le même problème.

Questions connexes