セキュリティ認証 <authentication>

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

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

概要

認証は、Web サイトまたは Web アプリケーションの利用者の ID を確認するために使用するメカニズムです。通常、利用者に対してユーザー名とパスワードを割り当てるか、サイト上の公開コンテンツへの匿名アクセスを許可することによって認証を行います。

認証は利用者の ID を確認するために使用しますが、承認はサイトまたはアプリケーションのさまざまなエリアへの利用者のアクセスを制御するために使用します。

IIS 7.0 では、匿名認証、基本認証、クライアント証明書マッピング認証、ダイジェスト認証、IIS クライアント証明書マッピング認証、および Windows 認証をサポートしています。また、その他の認証モードがサード パーティ製認証モジュールで提供されている場合もあります。

いずれかの認証モジュールをインストールした後は、認証を利用する Web サイト、Web アプリケーション、または Web サービスで、選択した認証モジュールを有効にする必要があります。

また既定では、IIS 7.0 で Windows 認証スキーム (Kerberos または NTLM を利用) のカーネル モードの認証が有効になっています。カーネル モード認証には、以下のような利点があります。

  • Web アプリケーションを特権の低いアカウントを使用して実行できます。
  • Kerberos 認証を使用する場合は、既定のアカウントとは異なる、サーバーのサービス プリンシパル名 (SPN) に関連付けられたアカウントを使用できます。
  • カーネル モード認証を使用する場合は、Windows 認証 Kerberos プロバイダーを明示的な SPN 構成を行わずに使用できます。

互換性

  IIS 7.0 IIS 6.0
注意 <authentication> は IIS 7.0 で新たに導入された要素です。

なし

セットアップ

<authentication> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

匿名認証を無効にする方法

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

  2. [接続] ウィンドウで当該サーバー名を展開して [サイト] を展開し、ツリー表示内の構成対象のレベルに進んで Web サイトまたは Web アプリケーションをクリックします。

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

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

    拡大

匿名認証の資格情報を IUSR アカウントから変更する方法

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。
  2. [接続] ウィンドウで当該サーバー名を展開して [サイト] を展開し、ツリー表示内の構成対象のレベルに進んで Web サイトまたは Web アプリケーションをクリックします。
  3. [ホーム] ウィンドウで、[セキュリティ] セクションまでスクロールして [認証] をダブルクリックします。
  4. [認証] ウィンドウで [匿名認証] を選択し、[操作] ウィンドウの [編集] をクリックします。
  5. [匿名認証資格情報の編集] ダイアログ ボックスで、次のいずれかの操作を行います。
    • アプリケーション プール用に設定された ID を使用する場合は、[アプリケーション プール ID] を選択して、[OK] をクリックします。

      拡大

    • [設定] をクリックし、[資格情報の設定] ダイアログ ボックスで、[ユーザー名] ボックスにアカウントのユーザー名を入力し、[パスワード] および [パスワードの確認] ボックスにアカウントのパスワードを入力して、[OK] を 2 回クリックします。

      拡大 : この操作を行う場合、新しいアカウントに付与する特権は、IIS サーバー コンピューター上での最小限の特権に制限してください。

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

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

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

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

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

    拡大

構成

<authentication> セクション グループは、<system.webServer> 構成セクションで定義します。このセクション グループは、サーバーにインストールして有効にできるすべてのユーザー認証タイプの構成セクションを定義します。サーバー レベルでのこの要素の構成は ApplicationHost.config ファイルで、アプリケーション レベルでの構成は Web.config ファイルで、それぞれ設定できます。

属性

なし。

子要素

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

匿名認証の設定を指定します。
basicAuthentication オプションの要素。

基本認証の設定を指定します。
clientCertificateMappingAuthentication オプションの要素。

Active Directory を使用したクライアント証明書マッピング認証の設定を指定します。
digestAuthentication オプションの要素。

ダイジェスト認証の設定を指定します。
iisClientCertificateMappingAuthentication オプションの要素。

IIS を使用したクライアント証明書マッピング認証の設定を指定します。
windowsAuthentication オプションの要素。

Windows 認証の設定を指定します。

構成サンプル

次の構成例では、Contoso という名前のサイトで匿名認証を無効にしてから、基本認証および Windows 認証の両方を有効にします。

<location path="Contoso">
   <system.webServer>

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

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

      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 basicAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/basicAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
basicAuthenticationSection.Properties.Item("enabled").Value = true;

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 basicAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/basicAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
basicAuthenticationSection.Properties.Item("enabled").Value = True

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

adminManager.CommitChanges()