Windows 認証 <windowsAuthentication>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<windowsAuthentication> 要素は、インターネット インフォメーション サービス (IIS) 7.0 の Windows 認証モジュールの構成設定を定義します。IIS 7.0 サーバーを企業ネットワークで実行する場合、Windows 認証を使用することができます。その際は、Microsoft Active Directory ディレクトリ サービス ドメイン ID やその他の Windows アカウントを使用してユーザーを識別します。このため、サーバーが Active Directory ドメインのメンバーであるかどうかにかかわらず、Windows 認証を使用できます。

Windows 認証 (以前は NTLM という名称で、Windows NT チャレンジ/レスポンス認証とも呼ばれていました) では、ユーザー名とパスワードがネットワーク上に送信される前にハッシュされるため、安全な認証方式です。Windows 認証を有効にすると、クライアント ブラウザーは強力にハッシュされた暗号形式のパスワードを Web サーバーと交換します。

Windows 認証では、Kerberos および NTLM の 2 つの認証プロトコルをサポートします。これらは <providers> 要素で定義されます。IIS 7.0 で Windows 認証をインストールして有効にした場合、既定のプロトコルは Kerberos です。<windowsAuthentication> 要素には useKernelMode 属性も含まれます。この属性は、Windows Server 2008 の新機能であるカーネル モード認証機能の使用を構成します。

Windows 認証は、次の理由からイントラネット環境に最も適しています。

  • クライアント コンピューターと Web サーバーが同じドメインに存在する。
  • 管理者は、各クライアント ブラウザーが Internet Explorer 2.0 以降であることを確認できる。
  • HTTP プロキシ接続が不要 (HTTP プロキシ接続は NTLM ではサポートされません)。
  • Kerberos バージョン 5 では Active Directory への接続が必要 (インターネット環境では、これはあまり現実的ではありません)。

互換性

  IIS 7.0 IIS 6.0
説明 <windowsAuthentication> は IIS 7.0 で新たに導入された要素です。

<windowsAuthentication> 要素は、IIS 6.0 の AuthType および AuthFlags メタベース プロパティの一部に代わるものです。

セットアップ

IIS 7.0 の既定のインストールには、"Windows 認証" 役割サービスは含まれません。IIS で Windows 認証を使用するには、この役割サービスをインストールして、Web サイトまたはアプリケーションで匿名認証を無効にし、Windows 認証を有効にする必要があります。

: この役割サービスをインストールすると、IIS 7.0 は次の構成設定を ApplicationHost.config ファイルに適用します。

<windowsAuthentication enabled='false' />

Windows Server 2008

  1. タスク バーの [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] のツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、[Windows 認証] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーの [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックして、[Windows の機能の有効化または無効化] をクリックします。

  3. [Internet Information Services][World Wide Web サービス][セキュリティ] の順に展開します。

  4. [Windows 認証] を選択して、[OK] をクリックします。

    拡大

方法

Web サイト、Web アプリケーション、または Web サービスで Windows 認証を有効にする方法

  1. タスク バーの [スタート] ボタンをクリックして、[管理ツール] をポイントし、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで当該サーバー名を展開して [サイト] を展開し、Windows 認証を有効にする Web サイト、Web アプリケーション、または Web サービスをクリックします。

  3. [ホーム] ウィンドウで、[セキュリティ] セクションまでスクロールして [認証] をダブルクリックします。

  4. [認証] ウィンドウで [Windows 認証] を選択し、[操作] ウィンドウの [有効にする] をクリックします。

    拡大

構成

<windowsAuthentication> 要素は、ApplicationHost.config ファイル内で、サイト、アプリケーション、または仮想ディレクトリ レベルで構成できます。

属性

属性 説明
authPersistNonNTLM オプションの Boolean 属性。

非 NTLM (Kerberos など) 要求において、毎回 (同一の接続でも) 自動的に再認証するかどうかを指定します。true に設定すると、同一の接続で複数の認証が可能になります。

: false に設定すると、同一の接続においてクライアントは一度だけ認証されることになります。TCP セッションが確立されたままになっている場合、IIS はサーバー上でトークンまたはチケットをキャッシュします。

既定値は false です。
authPersistSingleRequest オプションの Boolean 属性。

このフラグを true に設定すると、認証は 1 回の接続で一度の要求の間のみ保持されます。IIS は、各要求の最後に認証をリセットし、セッションの次の要求時に再認証を強制します。

既定値は false です。
enabled 必須の Boolean 属性。

Windows 認証を有効にするかどうかを指定します。

既定値は false です。
useKernelMode オプションの Boolean 属性。

Windows 認証がカーネル モードで実行されるかどうかを指定します。True は、Windows 認証でカーネル モードが使用されることを指定します。

カーネル モードの認証では、認証のパフォーマンスが向上します。また、カスタム ID を使用するようにアプリケーション プールを構成している場合の認証の問題を回避できます。

ベスト プラクティスとして、Kerberos 認証を使用しており、アプリケーション プールでカスタム ID を使用している場合は、この設定を無効にしないでください。

既定値は true です。

子要素

要素 説明
providers オプションの要素。

Windows 認証で使用されるセキュリティ サポート プロバイダーを指定します。

構成サンプル

次の既定の <windowsAuthentication> 要素は、IIS 7.0 のルート ApplicationHost.config ファイルに構成されます。これにより、Windows 認証は既定で無効になっています。また、IIS 7.0 の 2 つの Windows 認証プロバイダーを定義しています。

<windowsAuthentication enabled="false">
   <providers>

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

次の例では、Contoso という名前の Web サイトで、Windows 認証を有効にし、匿名認証を無効にします。

<location path="Contoso">

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

      </security>
   </system.webServer>
</location>

サンプル コード

次の例では、Contoso という名前のサイトで匿名認証を無効にし、Windows 認証を有効にします。

AppCmd.exe

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

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

: AppCmd.exe を使用してこれらの設定を構成する際には、commit パラメーターを APPHOST に設定する必要があります。それにより、ApplicationHost.config ファイル内の該当する location セクションに構成設定が適用されます。

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 anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
         anonymousAuthenticationSection["enabled"] = false;

         ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso");
         windowsAuthenticationSection["enabled"] = true;

         serverManager.CommitChanges();
      }
   }
}

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 anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso")
      anonymousAuthenticationSection("enabled") = False

      Dim windowsAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso")
      windowsAuthenticationSection("enabled") = True

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
anonymousAuthenticationSection.Properties.Item("enabled").Value = false;

var windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
windowsAuthenticationSection.Properties.Item("enabled").Value = true;

adminManager.CommitChanges();

VBScript

Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
anonymousAuthenticationSection.Properties.Item("enabled").Value = False

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

adminManager.CommitChanges()