多對一對應 < 多ToOneMappings>
概觀
元素的 <iisClientCertificateMappingAuthentication>
元素會 <manyToOneMappings>
根據用戶端瀏覽器憑證中的準則,將多個用戶端憑證對應至使用者帳戶。 多對一憑證對應可用來取代較常用的驗證方法,例如Windows 驗證或基本驗證。
您可以針對多對一規則啟用兩種不同的存取方法: 允許 或 拒絕。 這些設定可讓您建立規則,以接受允許存取網站的用戶端憑證群組,同時拒絕根據不同準則存取其他憑證群組。 例如,您可以建立規則,允許存取人力資源組織單位中的所有 Contoso 員工,同時拒絕存取銷售組織單位中的員工。
用戶端憑證中有兩個欄位可用來做為多對一規則的準則:
- 簽發者 - 此欄位會指定發行用戶端憑證之憑證授權單位單位 (CA) 的相關資訊。
- 主體 - 此欄位會指定發行用戶端憑證之實體的相關資訊。
每個欄位都可以包含一般 LDAP 子欄位;例如:
- CN = commonName (例如「Nancy Davolio」)
- OU = organizationUnitName (例如「Sales」)
- O = organizationName (例如「Contoso」)
- L = localityName (例如 「Redmond」)
- S = stateOrProvinceName (例如 「WA」)
- C = countryName (例如「US」)
若要建立對應,您可以根據特定值的欄位/子欄位配對來建立規則。 例如,您可以建立符合簽發者 O 子欄位與 Contoso 的規則,以允許存取 Contoso CA 所簽發憑證的所有用戶端。 這可有效地消除不屬於 Contoso 組織之任何用戶端的用戶端連線。
注意
多對一憑證對應與 一對一 憑證對應不同,可將個別用戶端憑證對應至個別使用者帳戶。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 未在 IIS 10.0 中修改專案 <manyToOneMappings> 。 |
IIS 8.5 | 未在 IIS 8.5 中修改專案 <manyToOneMappings> 。 |
IIS 8.0 | 未在 IIS 8.0 中修改專案 <manyToOneMappings> 。 |
IIS 7.5 | 未在 IIS 7.5 中修改專案 <manyToOneMappings> 。 |
IIS 7.0 | 元素 <manyToOneMappings> 的 <iisClientCertificateMappingAuthentication> 元素是在 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 Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[IIS 用戶端憑證對應驗證],然後按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。
- 展開 [Internet Information Services],然後選取 [IIS 用戶端憑證對應驗證],然後按一下 [ 確定]。
作法
沒有用於設定 IIS 7 的 IIS 用戶端憑證對應驗證的使用者介面。 For examples of how to configure IIS Client Certificate Mapping authentication programmatically, see the Code Samples section of this document.
組態
屬性
無。
子元素
元素 | 描述 |
---|---|
add |
選擇性項目。 將對應加入 至多ToOneMappings 的集合。 |
clear |
選擇性項目。 從 manyToOneMappings 集合中移除對應的所有參考。 |
組態範例
下列組態範例會針對預設網站執行下列動作:
- 使用多對一憑證對應啟用 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()