Proveedores de autenticación de Windows <proveedores>

Información general

La colección <providers> del elemento <windowsAuthentication> define la lista de proveedores de autenticación que se usan con el módulo de autenticación de Windows internet Information Services (IIS) 7. Esta lista de proveedores no se puede extender y, de forma predeterminada, contiene solo dos entradas:

  • Negotiate: este proveedor intentará usar Kerberos para la autenticación si está disponible.
  • NTLM: este proveedor intentará usar Windows NT LAN Manager para la autenticación.

Compatibilidad

Versión Notas
IIS 10.0 El elemento <providers> no se modificó en IIS 10.0.
IIS 8.5 El elemento <providers> no se modificó en IIS 8.5.
IIS 8.0 El elemento <providers> no se modificó en IIS 8.0.
IIS 7.5 El elemento <providers> no se modificó en IIS 7.5.
IIS 7.0 El elemento <providers> del elemento <windowsAuthentication> se introdujo en IIS 7.0.
IIS 6,0 La colección <providers> reemplaza la propiedad de metabase NTAuthenticationProviders de IIS 6.0.

Configuración

La instalación predeterminada de IIS 7 y versiones posteriores no incluye el servicio de rol de autenticación de Windows. Para usar la autenticación de Windows en IIS, debe instalar el servicio de rol, deshabilitar la autenticación anónima para su sitio web o aplicación y, a continuación, habilitar la autenticación de Windows para el sitio o la aplicación.

Nota:

Después de instalar el servicio de rol, IIS 7 confirma las siguientes opciones de configuración en el archivo ApplicationHost.config.

<windowsAuthentication enabled="false" />

Windows Server 2012 o Windows Server 2012 R2

  1. En la barra de tareas, haga clic en Administrador del servidor.
  2. En Administrador del servidor, haga clic en el menú Administrar y, después, haga clic en Agregar roles y características.
  3. En el asistente para Agregar roles y características, haga clic en Siguiente. Seleccione el tipo de instalación y haga clic en Siguiente. Seleccione el servidor de destino y haga clic en Siguiente.
  4. En la página Roles de servidor, expanda Servidor web (IIS), expanda Servidor web, expanda Seguridad y seleccione Autenticación de Windows. Haga clic en Next.
    Screenshot of the Windows Authentication option being selected and highlighted.
  5. En la página Seleccionar características, haz clic en Siguiente.
  6. En la página Confirmar selecciones de instalación, haga clic en Instalar.
  7. En la página Resultados , haga clic en Cerrar.

Windows 8 o Windows 8.1

  1. En la pantalla Inicio, mueva el puntero hasta la esquina inferior izquierda, haga clic con el botón derecho en el botón Inicio y, a continuación, haga clic en Panel de control.
  2. En Panel de control, haga clic en Programas y características y después en Activar o desactivar las características de Windows.
  3. Expanda Internet Information Services, expanda Servicios World Wide Web, expanda Seguridad y luego seleccione Autenticación de Windows.
    Screenshot of the Windows Authentication folder being selected and highlighted.
  4. Haga clic en OK.
  5. Haga clic en Cerrar.

Windows Server 2008 o Windows Server 2008 R2

  1. En la barra de tareas, haga clic en Inicio, seleccione Herramientas administrativas y, luego, haga clic en Administrador del servidor.
  2. En el panel de jerarquía del Administrador del servidor, expanda Roles y, luego, haga clic en Servidor web (IIS).
  3. En el panel Servidor web (IIS), desplácese hasta la sección Servicios de rol y, luego, haga clic en Agregar servicios de rol.
  4. En la página Seleccionar servicios de rol del Asistente para agregar servicios de rol, seleccione Autenticación de Windows y haga clic en Siguiente.
    Screenshot of the Add Role Services Wizard showing the selected and highlighted Windows Authentication option.
  5. En la página Confirmar selecciones de instalación, haz clic en Instalar.
  6. En la página Resultados , haga clic en Cerrar.

Windows Vista o Windows 7

  1. En la barra de tareas, haga clic en Inicio y, luego, haga clic en Panel de control.
  2. En Panel de control, haga clic en Programas y características y después en Activar o desactivar las características de Windows.
  3. Expanda Internet Information Services, después World Wide Web Services y luego Seguridad.
  4. Seleccione Autenticación de Windows y, a continuación, haga clic en Aceptar.
    Screenshot of the Security folder being expanded, showing the Windows Authentication folder being selected and highlighted.

Procedimientos

No hay ninguna interfaz de usuario para proveedores de autenticación de Windows para IIS 7. Para obtener ejemplos de cómo modificar la lista de proveedores de autenticación de Windows mediante programación, consulte la sección Ejemplos de código de este documento.

Configuración

Atributos

Ninguno.

Elementos secundarios

Elemento Descripción
add Elemento opcional.

Agrega un proveedor de seguridad a la colección de proveedores. La autenticación de Windows requiere al menos un proveedor.
remove Elemento opcional.

Quita una referencia a un proveedor de seguridad de la colección de proveedores.
clear Elemento opcional.

Quita todas las referencias a proveedores de la colección de proveedores.

Ejemplo de configuración

El siguiente elemento predeterminado <windowsAuthentication> se configura en el archivo ApplicationHost.config raíz en IIS 7.0 y deshabilita la autenticación de Windows de forma predeterminada. También define los dos proveedores de autenticación de Windows para IIS 7.0.

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

En el siguiente ejemplo se habilita la autenticación de Windows y se deshabilita la autenticación anónima para un sitio web denominado Contoso.

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

Código de ejemplo

Los ejemplos de código siguientes habilitarán la autenticación de Windows y quitarán el proveedor Negotiate para un sitio denominado 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

Nota:

Debe asegurarse de establecer el parámetro de confirmación en apphost cuando use AppCmd.exe para configurar estas opciones. Esto confirma los valores de configuración en la sección de ubicación adecuada del archivo 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