Share via


Fournisseurs d’authentification Windows <providers>

Vue d’ensemble

La collection <providers> de l’élément <windowsAuthentication> définit la liste des fournisseurs d’authentification utilisés avec le module d’authentification Windows Internet Information Services (IIS) 7. Cette liste de fournisseurs ne peut pas être étendue et, par défaut, elle ne contient que deux entrées :

  • Negotiate : ce fournisseur tente d’utiliser Kerberos pour l’authentification s’il est disponible.
  • NTLM - ce fournisseur tente d’utiliser Windows NT LAN Manager pour l’authentification.

Compatibilité

Version Notes
IIS 10.0 L’élément <providers> n’a pas été modifié dans IIS 10.0.
IIS 8.5 L’élément <providers> n’a pas été modifié dans IIS 8.5.
IIS 8.0 L’élément <providers> n’a pas été modifié dans IIS 8.0.
IIS 7.5 L’élément <providers> n’a pas été modifié dans IIS 7.5.
IIS 7.0 L’élément <providers> de l’élément <windowsAuthentication> a été introduit dans IIS 7.0.
IIS 6.0 La collection <providers> remplace la propriété métabase NTAuthenticationProviders IIS 6.0.

Programme d’installation

L’installation par défaut d’IIS 7 et versions ultérieures n’inclut pas le service de rôle d’authentification Windows. Pour utiliser l’authentification Windows sur IIS, vous devez installer le service de rôle, désactiver Authentification anonyme pour votre site web ou votre application, puis activer Authentification Windows pour le site ou l’application.

Remarque

Après avoir installé le service de rôle, IIS 7 valide les paramètres de configuration suivants dans le fichier ApplicationHost.config.

<windowsAuthentication enabled="false" />

Windows Server 2012 ou Windows Server 2012 R2

  1. Dans la barre des tâches, cliquez sur Gestionnaire de serveur.
  2. Dans Gestionnaire de serveur, cliquez sur le menu Gérer, puis sur Ajouter des rôles et des fonctionnalités.
  3. Dans l’Assistant Ajout de rôles et de fonctionnalités, cliquez sur Suivant. Sélectionnez le type d’installation, puis cliquez sur Suivant. Sélectionnez le serveur de destination, puis cliquez sur Suivant.
  4. Dans la page Rôles serveur, développez Serveur web (IIS), Serveur web, Sécurité, puis sélectionnez Authentification Windows. Sélectionnez Suivant.
    Screenshot of the Windows Authentication option being selected and highlighted.
  5. Dans la page Sélectionner les composants, cliquez sur Suivant.
  6. Dans la page Confirmer les sélections d’installation, cliquez sur Installer.
  7. Dans la page Résultats , cliquez sur Fermer.

Windows 8 ou Windows 8.1

  1. Dans l’écran d’accueil, déplacez le pointeur jusqu’au coin inférieur gauche, cliquez avec le bouton droit sur le bouton Démarrer, puis cliquez sur Panneau de configuration.
  2. Dans le Panneau de configuration, cliquez sur Programmes et fonctionnalités, puis sur Activer ou désactiver des fonctionnalités Windows.
  3. Développez Internet Information Services, Services World Wide Web, Sécurité, puis sélectionnez Authentification Windows.
    Screenshot of the Windows Authentication folder being selected and highlighted.
  4. Cliquez sur OK.
  5. Cliquez sur Fermer.

Windows Server 2008 ou Windows Server 2008 R2

  1. Dans la barre des tâches, cliquez sur Démarrer, pointez sur Outils d’administration, puis cliquez sur Gestionnaire de serveur.
  2. Dans le volet de hiérarchie Gestionnaire de serveur, développez Rôles, puis cliquez sur Serveur web (IIS).
  3. Dans le volet Serveur web (IIS), faites défiler jusqu’à la section Services de rôle, puis cliquez sur Ajouter des services de rôle.
  4. Dans la page Sélectionner des services de rôle de l’Assistant Ajout de services de rôle, sélectionnez Authentification Windows, puis cliquez sur Suivant.
    Screenshot of the Add Role Services Wizard showing the selected and highlighted Windows Authentication option.
  5. Dans la page Confirmer les sélections pour l'installation, cliquez sur Installer.
  6. Dans la page Résultats , cliquez sur Fermer.

Windows Vista ou Windows 7

  1. Dans la barre des tâches, cliquez sur Démarrer, puis sur Panneau de configuration.
  2. Dans le Panneau de configuration, cliquez sur Programmes et fonctionnalités, puis sur Activer ou désactiver des fonctionnalités Windows.
  3. Développez Internet Information Services, Services World Wide Web, puis Sécurité.
  4. Sélectionnez Authentification Windows, puis cliquez sur OK.
    Screenshot of the Security folder being expanded, showing the Windows Authentication folder being selected and highlighted.

Procédure

Il n’existe aucune interface utilisateur pour les fournisseurs d’authentification Windows pour IIS 7. Pour obtenir des exemples de modification de la liste des fournisseurs d’authentification Windows par programmation, consultez la section Exemples de code de ce document.

Configuration

Attributs

Aucune.

Éléments enfants

Élément Description
add Élément facultatif.

Ajoute un fournisseur de sécurité à la collection de fournisseurs. L’authentification Windows nécessite au moins un fournisseur.
remove Élément facultatif.

Supprime une référence à un fournisseur de sécurité de la collection de fournisseurs.
clear Élément facultatif.

Supprime toutes les références aux fournisseurs de la collection provider.

Exemple Configuration

L’élément par défaut <windowsAuthentication> suivant est configuré dans le fichier ApplicationHost.config racine dans IIS 7.0 et désactive l’authentification Windows par défaut. Il définit également les deux fournisseurs d’authentification Windows pour IIS 7.0.

<windowsAuthentication enabled="false">
   <providers>
      <add value="Negotiate" />
      <add value="NTLM" />
   </providers>
</windowsAuthentication>

L’exemple suivant active l’authentification Windows et désactive l’authentification anonyme pour un site web nommé Contoso.

<location path="Contoso">
   <system.webServer>
      <security>
         <authentication>
            <anonymousAuthentication enabled="false" />
            <windowsAuthentication enabled="true" />
         </authentication>
      </security>
   </system.webServer>
</location>

Exemple de code

Les exemples de code suivants activent l’authentification Windows et suppriment le fournisseur Negotiate pour un site nommé Contoso.

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:apphost

appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/windowsAuthentication /-"providers.[value='Negotiate']" /commit:apphost

Remarque

Vous devez veiller à définir le paramètre commit sur apphost quand vous utilisez AppCmd.exe pour configurer ces paramètres. Cela valide les paramètres de configuration dans la section d’emplacement appropriée dans le fichier ApplicationHost.config.

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso");
         windowsAuthenticationSection["enabled"] = true;

         ConfigurationElementCollection providersCollection = windowsAuthenticationSection.GetCollection("providers");
         ConfigurationElement addElement = FindElement(providersCollection, "add", "value", @"Negotiate");

         if (addElement == null) throw new InvalidOperationException("Element not found!");
         providersCollection.Remove(addElement);

         serverManager.CommitChanges();
      }
   }

   private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            bool matches = true;
            for (int i = 0; i < keyValues.Length; i += 2)
            {
               object o = element.GetAttributeValue(keyValues[i]);
               string value = null;
               if (o != null)
               {
                  value = o.ToString();
               }
               if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
               {
                  matches = false;
                  break;
               }
            }
            if (matches)
            {
               return element;
            }
         }
      }
      return null;
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim windowsAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso")
      windowsAuthenticationSection("enabled") = True

      Dim providersCollection As ConfigurationElementCollection = windowsAuthenticationSection.GetCollection("providers")
      Dim addElement As ConfigurationElement = FindElement(providersCollection, "add", "value", "Negotiate")

      If (addElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If
      providersCollection.Remove(addElement)

      serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
      For Each element As ConfigurationElement In collection
         If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
            Dim matches As Boolean = True
            Dim i As Integer
            For i = 0 To keyValues.Length - 1 Step 2
               Dim o As Object = element.GetAttributeValue(keyValues(i))
               Dim value As String = Nothing
               If (Not (o) Is Nothing) Then
                  value = o.ToString
               End If
               If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                  matches = False
                  Exit For
               End If
            Next
            If matches Then
               Return element
            End If
         End If
      Next
      Return Nothing
   End Function


End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
windowsAuthenticationSection.Properties.Item("enabled").Value = true;

var providersCollection = windowsAuthenticationSection.ChildElements.Item("providers").Collection;
var addElementPos = FindElement(providersCollection, "add", ["value", "Negotiate"]);
if (addElementPos == -1) throw "Element not found!";
providersCollection.DeleteElement(addElementPos);

adminManager.CommitChanges();

function FindElement(collection, elementTagName, valuesToMatch) {
   for (var i = 0; i < collection.Count; i++) {
      var element = collection.Item(i);
      if (element.Name == elementTagName) {
         var matches = true;
         for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
            var property = element.GetPropertyByName(valuesToMatch[iVal]);
            var value = property.Value;
            if (value != null) {
               value = value.toString();
            }
            if (value != valuesToMatch[iVal + 1]) {
               matches = false;
               break;
            }
         }
         if (matches) {
            return i;
         }
      }
   }
   return -1;
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
windowsAuthenticationSection.Properties.Item("enabled").Value = True

Set providersCollection = windowsAuthenticationSection.ChildElements.Item("providers").Collection
addElementPos = FindElement(providersCollection, "add", Array("value", "Negotiate"))

If (addElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
providersCollection.DeleteElement(addElementPos)

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not IsNull(value) Then
               value = CStr(value)
            End If
            If Not value = CStr(valuesToMatch(iVal + 1)) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function