新增多對一對應新增 <>
概觀
元素 <add>
的 <manyToOneMappings>
元素會將唯一的用戶端憑證對應新增至多對一對應集合。
每個多對一對應都會對應至使用者帳戶和密碼,可用來取代較常用的驗證方法,例如Windows 驗證或基本驗證。
您可以針對多對一規則啟用兩種不同的存取方法: 允許 或 拒絕。 這些設定可讓您建立規則,以接受允許存取網站的用戶端憑證群組,同時拒絕根據不同準則存取其他憑證群組。 例如,您可以建立規則,允許存取人力資源組織單位中的所有 Contoso 員工,同時拒絕存取銷售組織單位中的員工。
注意
多對一憑證對應與 一對一 憑證對應不同,將個別用戶端憑證對應至個別使用者帳戶。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 在 <add> IIS 10.0 中未修改專案。 |
IIS 8.5 | 未 <add> 在 IIS 8.5 中修改專案。 |
IIS 8.0 | 在 IIS 8.0 中未修改專案 <add> 。 |
IIS 7.5 | 未 <add> 在 IIS 7.5 中修改專案。 |
IIS 7.0 | 元素 <add> 的 <manyToOneMappings> 元素是在 IIS 7.0 中引進。 |
IIS 6.0 | 元素 <manyToOneMappings> 會取代 IIS 6.0 IIsCertMapper Metabase 物件。 |
安裝程式
專案 <iisClientCertificateMappingAuthentication>
無法在 IIS 7 和更新版本的預設安裝上使用。 若要安裝,請使用下列步驟。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在伺服器管理員中,按一下 [管理]功能表,然後按一下 [新增角色和功能]。
- 在 [ 新增角色和功能 精靈] 中,按 [下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,依序展開 [Web 服務器] ([IIS) ]、[ 網頁伺服器]、[ 安全性] 和 [ IIS 用戶端憑證對應驗證]。 按一下 [下一步] 。
. - 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或Windows 8.1
- 在 [開始] 畫面上,將指標全部移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 依 序展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [IIS 用戶端憑證對應驗證]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [Web 服務器 (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[IIS 用戶端憑證對應驗證],然後按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 展開 [Internet Information Services],然後選取 [IIS 用戶端憑證對應驗證],然後按一下 [ 確定]。
作法
沒有使用者介面可用於設定 IIS 7 的 IIS 用戶端憑證對應驗證。 如需如何以程式設計方式設定 IIS 用戶端憑證對應驗證的範例,請參閱本檔的程式 代碼範例 一節。
組態
屬性
屬性 | 描述 | ||||||
---|---|---|---|---|---|---|---|
描述 | 選擇性字串屬性。 指定這個一對多對應的描述。 |
||||||
enabled |
選擇性的 Boolean 屬性。 指定是否啟用此一對多對應。 預設值是 true 。 |
||||||
name |
必要的字串屬性。 指定這個一對多對應的名稱。 |
||||||
password |
選擇性字串屬性。 指定用來驗證符合此規則之用戶端的帳戶密碼。 注意: 若要避免在組態檔中儲存未加密的密碼字串,請一律使用 AppCmd.exe 或 IIS 管理員來輸入密碼。 如果您使用這些管理工具,密碼字串將會在寫入 XML 組態檔之前自動加密。 這提供比儲存未加密密碼更好的密碼安全性。 |
||||||
permissionMode |
選擇性列舉屬性。 permissionMode 屬性可以是下列其中一個可能的值。 預設值為 Allow 。
|
||||||
username |
選擇性字串屬性。 指定用來驗證符合此規則之用戶端的帳戶使用者名稱。 |
子元素
元素 | 描述 |
---|---|
rules |
選擇性項目。 指定與 IIS 對應用戶端憑證的準則,讓許多用戶端可以使用一個憑證。 |
組態範例
下列組態範例會針對預設網站執行下列動作:
- 使用多對一憑證對應啟用 IIS 用戶端憑證對應驗證。
- 根據符合 Contoso 之用戶端憑證主體中的組織欄位,為使用者帳戶建立多對一憑證對應規則。
- 將月臺設定為要求 SSL 和交涉用戶端憑證。
<location path="Default Web Site">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="false" />
<anonymousAuthentication enabled="false" />
<digestAuthentication enabled="false" />
<basicAuthentication enabled="false" />
<iisClientCertificateMappingAuthentication enabled="true"
manyToOneCertificateMappingsEnabled="true">
<manyToOneMappings>
<add name="Contoso Employees"
enabled="true"
permissionMode="Allow"
userName="Username"
password="[enc:AesProvider:57686f6120447564652c2049495320526f636b73:enc]">
<rules>
<add certificateField="Subject"
certificateSubField="O"
matchCriteria="Contoso"
compareCaseSensitive="true" />
</rules>
</add>
</manyToOneMappings>
</iisClientCertificateMappingAuthentication>
</authentication>
<access sslFlags="Ssl, SslNegotiateCert" />
</security>
</system.webServer>
</location>
範例程式碼
下列程式碼範例會針對預設網站執行下列動作:
- 使用多對一憑證對應啟用 IIS 用戶端憑證對應驗證。
- 根據符合 Contoso 之用戶端憑證主體中的組織欄位,為使用者帳戶建立多對一憑證對應規則。
- 將月臺設定為要求 SSL,並交涉用戶端憑證。
AppCmd.exe
appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /enabled:"True" /manyToOneCertificateMappingsEnabled:"True" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /+"manyToOneMappings.[name='Contoso Employees',enabled='True',permissionMode='Allow',userName='Username',password='Password']" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /+"manyToOneMappings.[name='Contoso Employees'].rules.[certificateField='Subject',certificateSubField='O',matchCriteria='Contoso',compareCaseSensitive='True']" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/security/access /sslFlags:"Ssl, SslNegotiateCert" /commit:apphost
注意
當您使用 AppCmd.exe 來設定這些設定時,請務必將 認可 參數 apphost
設定為 。 這會將組態設定認可至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 iisClientCertificateMappingAuthenticationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site");
iisClientCertificateMappingAuthenticationSection["enabled"] = true;
iisClientCertificateMappingAuthenticationSection["manyToOneCertificateMappingsEnabled"] = true;
ConfigurationElementCollection manyToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("manyToOneMappings");
ConfigurationElement addElement = manyToOneMappingsCollection.CreateElement("add");
addElement["name"] = @"Contoso Employees";
addElement["enabled"] = true;
addElement["permissionMode"] = @"Allow";
addElement["userName"] = @"Username";
addElement["password"] = @"Password";
ConfigurationElementCollection rulesCollection = addElement.GetCollection("rules");
ConfigurationElement addElement1 = rulesCollection.CreateElement("add");
addElement1["certificateField"] = @"Subject";
addElement1["certificateSubField"] = @"O";
addElement1["matchCriteria"] = @"Contoso";
addElement1["compareCaseSensitive"] = true;
rulesCollection.Add(addElement1);
manyToOneMappingsCollection.Add(addElement);
ConfigurationSection accessSection = config.GetSection("system.webServer/security/access", "Default Web Site");
accessSection["sslFlags"] = @"Ssl, SslNegotiateCert";
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 iisClientCertificateMappingAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site")
iisClientCertificateMappingAuthenticationSection("enabled") = True
iisClientCertificateMappingAuthenticationSection("manyToOneCertificateMappingsEnabled") = True
Dim manyToOneMappingsCollection As ConfigurationElementCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("manyToOneMappings")
Dim addElement As ConfigurationElement = manyToOneMappingsCollection.CreateElement("add")
addElement("name") = "Contoso Employees"
addElement("enabled") = True
addElement("permissionMode") = "Allow"
addElement("userName") = "Username"
addElement("password") = "Password"
Dim rulesCollection As ConfigurationElementCollection = addElement.GetCollection("rules")
Dim addElement1 As ConfigurationElement = rulesCollection.CreateElement("add")
addElement1("certificateField") = "Subject"
addElement1("certificateSubField") = "O"
addElement1("matchCriteria") = "Contoso"
addElement1("compareCaseSensitive") = True
rulesCollection.Add(addElement1)
manyToOneMappingsCollection.Add(addElement)
Dim accessSection As ConfigurationSection = config.GetSection("system.webServer/security/access", "Default Web Site")
accessSection("sslFlags") = "Ssl, SslNegotiateCert"
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site");
iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = true;
iisClientCertificateMappingAuthenticationSection.Properties.Item("manyToOneCertificateMappingsEnabled").Value = true;
var manyToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("manyToOneMappings").Collection;
var addElement = manyToOneMappingsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "Contoso Employees";
addElement.Properties.Item("enabled").Value = true;
addElement.Properties.Item("permissionMode").Value = "Allow";
addElement.Properties.Item("userName").Value = "Username";
addElement.Properties.Item("password").Value = "Password";
var rulesCollection = addElement.ChildElements.Item("rules").Collection;
var addElement1 = rulesCollection.CreateNewElement("add");
addElement1.Properties.Item("certificateField").Value = "Subject";
addElement1.Properties.Item("certificateSubField").Value = "O";
addElement1.Properties.Item("matchCriteria").Value = "Contoso";
addElement1.Properties.Item("compareCaseSensitive").Value = true;
rulesCollection.AddElement(addElement1);
manyToOneMappingsCollection.AddElement(addElement);
var accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site");
accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert";
adminManager.CommitChanges();
VBScript
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site")
iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = True
iisClientCertificateMappingAuthenticationSection.Properties.Item("manyToOneCertificateMappingsEnabled").Value = True
Set manyToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("manyToOneMappings").Collection
Set addElement = manyToOneMappingsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "Contoso Employees"
addElement.Properties.Item("enabled").Value = True
addElement.Properties.Item("permissionMode").Value = "Allow"
addElement.Properties.Item("userName").Value = "Username"
addElement.Properties.Item("password").Value = "Password"
Set rulesCollection = addElement.ChildElements.Item("rules").Collection
Set addElement1 = rulesCollection.CreateNewElement("add")
addElement1.Properties.Item("certificateField").Value = "Subject"
addElement1.Properties.Item("certificateSubField").Value = "O"
addElement1.Properties.Item("matchCriteria").Value = "Contoso"
addElement1.Properties.Item("compareCaseSensitive").Value = True
rulesCollection.AddElement(addElement1)
manyToOneMappingsCollection.AddElement(addElement)
Set accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site")
accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert"
adminManager.CommitChanges()