Logo

实现联合身份验证

photo

2023年04月07日

实现联合身份验证

适用于:yes-img-132013 yes-img-162016 yes-img-192019 yes-img-seSubscription Edition no-img-sopSharePoint in Microsoft 365

在 SharePoint Server 中实现联合身份验证

本分步指南介绍如何使用 Active Directory 联合身份验证服务 (AD FS) 在 SharePoint 中配置联合身份验证。

联合身份验证概述

在联合身份验证中,SharePoint 处理由受信任的外部安全令牌服务 (STS) 颁发的 SAML 令牌。 尝试登录的用户将重定向到该 STS,该 STS 对用户进行身份验证并在身份验证成功后生成 SAML 令牌。 然后,SharePoint 会处理此令牌,并使用它来创建自己的令牌并授权用户访问该网站。

先决条件

若要执行配置,需要以下资源:

  • SharePoint 2013 场或更高版本。
  • 已创建的 AD FS 场版本 2 或更高版本,并在 .cer 文件中导出了 AD FS 签名证书的公钥。

本文使用以下值:

  • SharePoint 网站 URL: https://spsites.contoso.local/
  • AD FS 站点 URL: https://adfs.contoso.local/adfs/ls/
  • 领域 (信赖方标识符) : urn:contoso:spsites
  • 标识声明类型: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
  • 角色声明类型: http://schemas.microsoft.com/ws/2008/06/identity/claims/role
  • Windows 网站集管理员: contoso\yvand
  • Email联合 (AD FS) 网站集管理员的值:yvand@contoso.local

在 AD FS 中创建信赖方

在此步骤中,将在 AD FS 中创建信赖方。 信赖方将存储使用 SharePoint 所需的配置,以及定义身份验证成功后将在 SAML 令牌中注入哪些声明的声明规则。

在 AD FS 服务器上,启动 PowerShell 并运行以下脚本:

### STEP 1: Create the relying party
# Name of the Relying Party
$name = "SPSites"
# Unique identifier of the Relying Party (in SharePoint it's referred to as the realm)
$identifier = "urn:contoso:spsites"
# Authority that authenticates users
$identityProvider = "Active Directory"
# SharePoint URL where user is redirected upon successful authentication
$redirectURL = "https://spsites.contoso.local/_trust/default.aspx"
# Allow everyone to use this relying party
$allowEveryoneRule = '=> issue (Type = "http://schemas.microsoft.com/authorization/claims/permit", value = "true");'
# Create the Relying Party
Add-ADFSRelyingPartyTrust -Name $name -Identifier $identifier -ClaimsProviderName $identityProvider -Enabled $true -WSFedEndpoint $redirectURL -IssuanceAuthorizationRules $allowEveryoneRule -Confirm:$false

### STEP 2: Add claim rules to the relying party
# Rule below configured relying party to issue 2 claims in the SAML token: email and role
$claimsRule = @"
@RuleTemplate = "LdapClaims"
@RuleName = "AD"
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"]
=> issue(
store = "Active Directory", 
types = ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"), 
query = ";mail,tokenGroups(fullDomainQualifiedName);{0}", 
param = c.Value);
"@
# Apply the rule to the Relying Party
Set-ADFSRelyingPartyTrust -TargetName $name -IssuanceTransformRules $claimsRule

脚本完成后,AD FS 中的信赖方应如下所示:

ADFS 信赖方

将 SharePoint 配置为信任 AD FS

在此步骤中,将创建一个 SPTrustedLoginProvider,用于存储 SharePoint 信任 AD FS 所需的配置。
启动 SharePoint 命令行管理程序 并运行以下脚本来创建它:

# Define claim types
$email = New-SPClaimTypeMapping "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "EmailAddress" -SameAsIncoming
$role = New-SPClaimTypeMapping "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" -IncomingClaimTypeDisplayName "Role" -SameAsIncoming

# Public key of the AD FS signing certificate
$signingCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Data\Claims\ADFS Signing.cer")
# Unique realm (corresponds to the unique identifier of the AD FS Relying Party)
$realm = "urn:contoso:spsites"
# Set the AD FS URL where users are redirected to authenticate
$signinurl = "https://adfs.contoso.local/adfs/ls/"

# Create a new SPTrustedIdentityTokenIssuer in SharePoint
New-SPTrustedIdentityTokenIssuer -Name "Contoso.local" -Description "Contoso.local" -Realm $realm -ImportTrustCertificate $signingCert -ClaimsMappings $email,$role -SignInUrl $signinurl -IdentifierClaim $email.InputClaimType

重要

请勿将选项 -UseDefaultConfiguration 与 cmdlet New-SPTrustedIdentityTokenIssuer 一起使用。 此选项会导致意外的副作用,因为它在内部设置用户标识。

然后,必须将相关证书添加到 SharePoint 根颁发机构证书存储。 有 2 种可能的选项:

  • 如果 AD FS 签名证书由证书颁发机构颁发, (出于安全原因的最佳做法)

必须将颁发者证书的公钥 (和所有中间) 添加到存储:启动 SharePoint 命令行管理程序 并运行以下脚本进行添加:

$rootCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Data\Claims\ADFS Signing issuer.cer")
New-SPTrustedRootAuthority -Name "adfs.contoso.local signing root authority" -Certificate $rootCert
  • 如果 ADFS 签名证书是自签名证书, (出于安全原因不建议使用)

必须将 ADFS 签名证书本身的公钥添加到存储:启动 SharePoint 命令行管理程序 并运行以下脚本来添加它:

$rootCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Data\Claims\ADFS Signing.cer")
New-SPTrustedRootAuthority -Name "adfs.contoso.local signing certificate" -Certificate $rootCert

配置 SharePoint Web 应用程序

在此步骤中,将使用上面创建的 SPTrustedLoginProvider 将 SharePoint 中的 Web 应用程序配置为与 AD FS 信任联合。

有一些重要的规则需要遵守:

  • SharePoint Web 应用程序的默认区域必须启用Windows 身份验证。 这是搜索爬网程序所必需的。
  • 必须使用 HTTPS 配置将使用 AD FS 联合身份验证的 SharePoint URL。

有两种可能的配置:

  • 如果创建新的 Web 应用程序并在默认区域中同时使用 Windows 和 AD FS 身份验证:

    1. 启动 SharePoint 命令行管理程序 并运行以下脚本:

      # This script creates a new web application and sets Windows and AD FS authentication on the Default zone
      # URL of the SharePoint site federated with ADFS
      $trustedSharePointSiteUrl = "https://spsites.contoso.local/"
      $applicationPoolManagedAccount = "Contoso\spapppool"
      
      $winAp = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos:$true
      $sptrust = Get-SPTrustedIdentityTokenIssuer "Contoso.local"
      $trustedAp = New-SPAuthenticationProvider -TrustedIdentityTokenIssuer $sptrust
      
      New-SPWebApplication -Name "SharePoint - ADFS on contoso.local" -Port 443 -SecureSocketsLayer -URL $trustedSharePointSiteUrl -ApplicationPool "SharePoint - ADFS on contoso.local" -ApplicationPoolAccount (Get-SPManagedAccount $applicationPoolManagedAccount) -AuthenticationProvider $winAp, $trustedAp
      
    2. 打开 SharePoint 管理中心 网站。

    3. “系统设置”下,选择“ 配置备用访问映射”。 此时会打开 “备用访问映射集合 ”框。

    4. 使用新的 Web 应用程序筛选显示,并确认看到如下所示的内容:

      Web 应用程序的备用访问映射

  • 如果扩展现有 Web 应用程序以在新区域上设置 AD FS 身份验证:

    1. 启动 SharePoint 命令行管理程序并运行以下脚本:

      # This script extends an existing web application to set AD FS authentication on a new zone
      # URL of the default zone of the web application
      $webAppDefaultZoneUrl = "http://spsites/"
      # URL of the SharePoint site federated with ADFS
      $trustedSharePointSiteUrl = "https://spsites.contoso.local/"
      
      $sptrust = Get-SPTrustedIdentityTokenIssuer "Contoso.local"
      $ap = New-SPAuthenticationProvider -TrustedIdentityTokenIssuer $sptrust
      $wa = Get-SPWebApplication $webAppDefaultZoneUrl
      New-SPWebApplicationExtension -Name "SharePoint - ADFS on contoso.local" -Identity $wa -SecureSocketsLayer -Zone Intranet -Url $trustedSharePointSiteUrl -AuthenticationProvider $ap
      
    2. 打开 SharePoint 管理中心 网站。

    3. “系统设置”下,选择“ 配置备用访问映射”。 此时会打开 “备用访问映射集合 ”框。

    4. 使用已扩展的 Web 应用程序筛选显示,并确认看到如下所示的内容:

      扩展应用程序的备用访问映射

在 IIS 中设置 HTTPS 证书

由于 SharePoint URL 使用 HTTPS 协议 (https://spsites.contoso.local/) ,因此必须在相应的 Internet Information Services (IIS) 网站上设置证书。

生成站点证书

注意

如果已生成证书,则可以跳过此步骤。

  1. 打开Windows PowerShell控制台。

  2. 运行以下脚本以生成自签名证书并将其添加到计算机的 MY 存储中:

    New-SelfSignedCertificate -DnsName "spsites.contoso.local" -CertStoreLocation "cert:\LocalMachine\My"
    

重要

自签名证书仅适用于测试目的。 在生产环境中,强烈建议改用证书颁发机构颁发的证书。

设置证书

  1. 打开 Internet Information Services Manager 控制台。

  2. 在树视图中展开服务器,展开 “网站”,选择 contoso.local 网站上的 SharePoint – ADFS ,然后选择“ 绑定”。

  3. 选择 “https 绑定 ”,然后选择“ 编辑”。

  4. 在“TLS/SSL 证书”字段中,选择 “spsites.contoso.local 证书”,然后选择“ 确定”。

创建网站集

在此步骤中,你将创建一个包含两个管理员的团队网站集:一个管理员作为 Windows 管理员,一个作为联合 (AD FS) 管理员。

  1. 打开 SharePoint 管理中心 网站。

  2. 在“应用程序管理”下,选择“创建网站集”。 此时会打开 “创建网站集 ”页。

  3. 键入 “标题”、“ Url”,然后选择模板 “工作组网站”。

  4. “主网站集管理员 ”部分中,单击书籍图标以打开人员选取器对话框。

  5. 在“人员选取器”对话框中,键入 Windows 管理员帐户,例如 yvand

  6. 在左侧,单击“ 组织”筛选列表。 应会看到如下所示的输出:

    人员选取器 Windows 管理员

  7. 选择帐户,然后单击“ 确定”。

  8. “辅助网站集管理员 ”部分中,单击书籍图标以打开人员选取器对话框。

  9. 在人员选取器对话框中,键入 AD FS 管理员帐户的 确切 电子邮件值,例如 yvand@contoso.local

  10. 在左侧,单击“ Contoso.local”筛选列表。 应会看到如下所示的输出:

    人员选取器 FS 管理员电子邮件

  11. 选择帐户,然后单击“ 确定”。

  12. 单击“确定”创建网站集。

创建网站集后,你应该能够使用 Windows 或联合网站集管理员帐户登录它。

后续步骤

在联合身份验证中,人员选取器不会验证输入,这可能会导致拼写错误或用户意外选择了错误的声明类型。 可以使用自定义声明提供程序解决此问题;例如 LDAPCP

重要

LDAPCP 不是 Microsoft 产品,Microsoft 支持部门不支持。 若要在本地 SharePoint 场上下载、安装和配置 LDAPCP,请参阅 LDAPCP 网站。

在 SharePoint Server 订阅版中,本机人员选取器可以使用用户配置文件服务应用程序进行联合身份验证来搜索和解析人员。 了解如何将人员选取器配置为使用联合身份验证

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它
所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

热门文章

修复群晖Synology Drive client右键菜单缺失问题 本教程主要解决windows10右键菜单中没有SynologyDrive菜单的问题,整体思路是找到...修复群晖SynologyDriveclient右键菜单缺失问题 作者:Pastore Antonio
2005 浏览量
docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 前言:有时候我们会在docker上下载一个镜像,或者是上传一个镜像到docker上,甚至有时候就是在...docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 作者:Pastore Antonio
1944 浏览量
Adobe Acrobat Pro 激活 这里记录了一些AdobeAcrobat的激活教程和组件。浏览量:1,825 作者:Pastore Antonio
1668 浏览量
追寻日出,找回自己 为什么我要去追寻日出?其实我是一个很懒的人,每次都起不来,直到有一次我在租房中睡到了大天亮,阳光照...追寻日出,找回自己 作者:Pastore Antonio
1625 浏览量
Swagger2 接口多级分组方法 swagger无疑是Java开发的最佳伴侣,接口非常方便调试;当然也有用Postman,因人而异吧...Swagger2接口多级分组方法 作者:Pastore Antonio
1532 浏览量