管理認証 <authentication>

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

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

概要

<management> 要素の <authentication> 要素は、IIS マネージャー ユーザー アカウントの認証資格情報を指定します。IIS マネージャー ユーザーは、サーバー管理者に承認を受けたサイトおよびアプリケーションに IIS マネージャーを使用して接続することができます。

認証プロバイダーとして既定の "ConfigurationAuthenticationProvider" を使用し、IIS マネージャー認証を有効にする場合、<credentials> 子要素には一連の <add> 要素を含めて IIS マネージャー ユーザー アカウントのユーザー名とパスワードを定義することができます。これらの IIS マネージャー ユーザー アカウントは Windows アカウントではないため、ユーザーが構成できるのはサーバー管理者に許可を受けたサイトおよび設定のみに制限されます。

互換性

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

セットアップ

IIS 7.0 の既定のインストールには、"管理サービス" 役割サービスは含まれません。この役割サービスをインストールする手順は次のとおりです。

Windows Server 2008

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

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

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

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

    拡大

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

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

Windows Vista

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

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

  3. [Internet Information Services][Web 管理ツール] の順に展開します。

  4. [IIS 管理サービス] を選択して、[OK] をクリックします。

    拡大

方法

サーバーで IIS マネージャー資格情報を有効にする方法

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

  2. [接続] ウィンドウで当該サーバー名をクリックします。

  3. サーバーの [ホーム] ウィンドウで [管理サービス] をダブルクリックします。

    拡大

  4. [管理サービス] ページで [Windows 資格情報または IIS マネージャー資格情報] を選択し、[操作] ウィンドウの [適用] をクリックします。

    拡大

サーバーに IIS マネージャー ユーザー資格情報を追加する方法

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

  2. [接続] ウィンドウで当該サーバー名をクリックします。

  3. サーバーの [ホーム] ウィンドウで [IIS マネージャー ユーザー] をダブルクリックします。

    拡大

  4. [IIS マネージャー ユーザー] ページで、[操作] ウィンドウの [ユーザーの追加] をクリックします。

    拡大

  5. [ユーザーの追加] ダイアログ ボックスで、ユーザー名とパスワードを入力し、[OK] をクリックします。

    拡大

構成

属性

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

Web サーバーで IIS マネージャー ユーザーに認証を提供する既定のプロバイダーを指定します。

既定のプロバイダーを変更する場合、管理サービス (WMSVC) を再起動して変更を有効にする必要があります。IIS マネージャーを開いている場合も、IIS マネージャーを開き直してください。

子要素

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

ユーザーが IIS マネージャーを使用してサーバー上のサイトやアプリケーションに接続できるように、IIS マネージャー ユーザー資格情報を構成します。
providers オプションの要素。

IIS マネージャーを使用してサイトやアプリケーションにリモートで接続する IIS マネージャー ユーザーを認証する認証プロバイダーを構成します。

構成サンプル

次の構成サンプルでは、ContosoUser という名前の IIS マネージャー ユーザーを Administration.config に追加する方法を示します。

<credentials>
   <add name="ContosoUser" password="Encrypted-Password-Data" enabled="true" />
</credentials>

次の <authentication> 要素の下の既定の <providers> 要素は、"管理サービス" 役割サービスをインストールすると、IIS 7.0 の Administration.config ファイルに構成されます。

<authentication defaultProvider="ConfigurationAuthenticationProvider">
   <providers>
      <add name="ConfigurationAuthenticationProvider"
         type="Microsoft.Web.Management.Server.ConfigurationAuthenticationProvider, Microsoft.Web.Management, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   </providers>
</authentication>

サンプル コード

次のコード サンプルでは、ContosoUser という名前の IIS マネージャー ユーザー アカウントを IIS 7.0 に追加します。

AppCmd.exe

: AppCmd.exe を使用して <system.webServer/management/authentication> 設定を構成することはできません。

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.GetAdministrationConfiguration();

         ConfigurationSection authenticationSection = config.GetSection("system.webServer/management/authentication");
         ConfigurationElementCollection credentialsCollection = authenticationSection.GetCollection("credentials");
         ConfigurationElement addElement = credentialsCollection.CreateElement("add");
         addElement["name"] = @"ContosoUser";
         addElement["password"] =   GetHashPwssword (@"P@ssw0rd");
         credentialsCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

public string GetHashPwssword(string passWord)
{            
   SHA256 sha = SHA256.Create();
   byte[] hashBytes = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(passWord));

   byte f1 = 0xf0;
   byte f2 = 0x0f;
   string hexString = "";

   foreach (byte b in hashBytes)
   {
      int first4 = (b & f1) >> 4;
      int second4 = (b & f2);
      hexString = hexString + ((first4 > 9) ? (char)('A' + (first4 - 10)) : (char)('0' + first4));
      hexString = hexString + ((second4 > 9) ? ((char)('A' + (second4 - 10))) : (char)('0' + second4));
   }
   return hexString;   
}

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.GetAdministrationConfiguration

      Dim authenticationSection As ConfigurationSection = config.GetSection("system.webServer/management/authentication")
      Dim credentialsCollection As ConfigurationElementCollection = authenticationSection.GetCollection("credentials")
      Dim addElement As ConfigurationElement = credentialsCollection.CreateElement("add")
      addElement("name") = "ContosoUser"
      addElement("password") = "P@ssw0rd"
      credentialsCollection.Add(addElement)
      addElement("enabled") = True
      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager"); 
adminManager.CommitPath = "MACHINE/WEBROOT"; 
adminManager.SetMetadata("pathMapper", "AdministrationConfig");

var authenticationSection = adminManager.GetAdminSection("system.webServer/management/authentication", "MACHINE/WEBROOT"); 
var credentialsCollection = authenticationSection.ChildElements.Item("credentials").Collection;

var addElement = credentialsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoUser";
addElement.Properties.Item("password").Value = "P@ssw0rd";
addElement.Properties.Item("enabled").Value = true;
credentialsCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"

Set authenticationSection = adminManager.GetAdminSection("system.webServer/management/authentication", "MACHINE/WEBROOT")
Set credentialsCollection = authenticationSection.ChildElements.Item("credentials").Collection

Set addElement = credentialsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoUser"
addElement.Properties.Item("password").Value = "P@ssw0rd"
addElement.Properties.Item("enabled").Value = True
credentialsCollection.AddElement(addElement)

adminManager.CommitChanges()

: このドキュメントで紹介している例は、.NET グローバル アセンブリ キャッシュ (GAC) に保存されているマネージ コード アセンブリを使用して示しています。これらの例で示すコードを使用して独自のアセンブリを展開するには、事前に GAC からアセンブリ情報を取得する必要があります。それには、次の手順を実行します。

  • Windows エクスプローラーで C:\Windows\assembly パスを開きます (C: は、オペレーティング システム ドライブを示します)。
  • アセンブリを見つけます。
  • アセンブリを右クリックして [プロパティ] をクリックします。
  • [カルチャ] の値をコピーします (例 : Neutral)。
  • [バージョン] の番号をコピーします (例 : 1.0.0.0)。
  • [公開キー トークン] の値をコピーします (例 : f0e1d2c3b4a59687)。
  • [キャンセル] をクリックします。

次のコード例では、ContosoAuthenticationProvider という名前の認証プロバイダーを管理認証プロバイダーのコレクションに追加し、既定の認証プロバイダーを ContosoAuthenticationProvider に設定します。

AppCmd.exe

: AppCmd.exe を使用して <system.webServer/Management> 設定を構成することはできません。

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.GetAdministrationConfiguration();

         ConfigurationSection authenticationSection = config.GetSection("system.webServer/management/authentication");
         ConfigurationElementCollection providersCollection = authenticationSection.GetCollection("providers");
         ConfigurationElement addElement = providersCollection.CreateElement("add");
         addElement["name"] = @"ContosoAuthenticationProvider";
         addElement["type"] = @"Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687";
         providersCollection.Add(addElement);
         authenticationSection["defaultProvider"] = "ContosoAuthenticationProvider";

         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.GetAdministrationConfiguration

      Dim authenticationSection As ConfigurationSection = config.GetSection("system.webServer/management/authentication")
      Dim providersCollection As ConfigurationElementCollection = authenticationSection.GetCollection("providers")
      Dim addElement As ConfigurationElement = providersCollection.CreateElement("add")
      addElement("name") = "ContosoAuthenticationProvider"
      addElement("type") = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687"
      providersCollection.Add(addElement)
      authenticationSection("defaultProvider") = "ContosoAuthenticationProvider"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager"); 
adminManager.CommitPath = "MACHINE/WEBROOT"; 
adminManager.SetMetadata("pathMapper", "AdministrationConfig");

var authenticationSection = adminManager.GetAdminSection("system.webServer/management/authentication", "MACHINE/WEBROOT"); 
var providersCollection = authenticationSection.ChildElements.Item("providers").Collection;

var addElement = providersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoAuthenticationProvider";
addElement.Properties.Item("type").Value = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687";
providersCollection.AddElement(addElement);
authenticationSection.Properties.Item("defaultProvider").Value = "ContosoAuthenticationProvider";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"

Set authenticationSection = adminManager.GetAdminSection("system.webServer/management/authentication", "MACHINE/WEBROOT")
Set providersCollection = authenticationSection.ChildElements.Item("providers").Collection

Set addElement = providersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoAuthenticationProvider"
addElement.Properties.Item("type").Value = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687"
providersCollection.AddElement(addElement)
authenticationSection.Properties.Item("defaultProvider").Value = "ContosoAuthenticationProvider"

adminManager.CommitChanges()