基本認証 <basicAuthentication>

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

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

概要

<basicAuthentication> 要素には、インターネット インフォメーション サービス (IIS) 7.0 の基本認証モジュールの構成設定が含まれます。この要素を構成して、基本認証を有効または無効にし、領域および既定のログオン ドメインを特定し、モジュールが使用するログオン方法を決定することができます。

基本認証スキームは、ユーザー名およびパスワードの情報を収集するために一般的に使用されている業界標準の方法です。基本認証では、ユーザー名とパスワードが非暗号化形式でネットワーク上で送信されます。SSL 暗号化を基本認証と組み合わせて使用すると、インターネットまたは企業ネットワーク上で送信されるユーザー アカウント情報をセキュリティで保護するのに役立ちます。

互換性

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

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

セットアップ

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

"基本認証" 役割サービスをインストールする手順は次のとおりです。

Windows Server 2008

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

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

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

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

    拡大

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

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

Windows Vista

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

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

  3. [Internet Information Services][World Wide Web サービス][セキュリティ] の順に展開し、[基本認証] を選択して [OK] をクリックします。

    拡大

方法

基本認証を有効にして匿名認証を無効にする方法

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

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

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

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

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

    拡大

構成

<basicAuthentication> 要素は、サイト、アプリケーション、仮想ディレクトリ、および URL レベルで構成可能です。役割サービスをインストールすると、IIS 7.0 は次の構成設定を ApplicationHost.config ファイルに適用します。

<basicAuthentication enabled='false' />

属性

属性 説明
defaultLogonDomain オプションの string 属性。

基本認証の既定のログオン ドメインを指定します。
enabled オプションの Boolean 属性。

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

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

logonMethod 属性には、次のいずれかの値を指定できます。既定値は ClearText です。

----------------------------------------------------------------------------------------

値: Batch

説明:

  • このログオンの種類は、ユーザーの直接的な介入なしに、ユーザーの代理としてプロセスを実行するバッチ サーバー用です。
  • 数値は 1 です。

値: ClearText

説明:

  • このログオンの種類では、認証パッケージに名前とパスワードを保存します。それによって、サーバーが、クライアントになりすまして、他のネットワーク サーバーに接続できるようになります。
  • 数値は 3 です。

値: Interactive

説明:

  • このログオンの種類は、コンピューターを対話的に使用するユーザー用です。
  • 数値は 0 です。

値: Network

説明:

  • このログオンの種類は、プレーンテキストによるパスワードを認証する高パフォーマンス サーバー用です。このログオンの種類では、資格情報はキャッシュされません。
  • 数値は 2 です。
realm オプションの string 属性。

基本認証の領域を指定します。

子要素

なし。

構成サンプル

次の構成サンプルでは、Web サイト、Web アプリケーション、または Web サービスで基本認証を有効にします。既定では、これらの設定を ApplicationHost.config ファイルに含める必要があり、これらの設定を <location> 要素に含め、path 属性を使用して認証設定を適用する Web サイトまたはアプリケーションを定義する必要があります。

<security>
   <authentication>
      <anonymousAuthentication enabled="false" />
      <basicAuthentication enabled="true" />
   </authentication>
</security>

サンプル コード

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

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 を使用してこれらの設定を構成する際には、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;

        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

      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;

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

adminManager.CommitChanges()