Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
최초 문서 게시일: 2011년 3월 27일 일요일
이 게시물에서는 이전에 몇 번 질문을 받은 적이 있는 내용인 웹 응용 프로그램에서 사용되는 클레임 공급자를 프로그래밍 방식으로 확인하는 방법에 대해 설명합니다. 일반적으로 현재 사용되고 있는 SPTrustedIdentityTokenIssuers를 확인하려는 경우 클레임 공급자를 확인합니다. 그러나 이 게시물에서 설명하는 방법을 사용하면 사용되고 있는 클레임 공급자뿐만 아니라 기본적으로 사용하도록 설정되지 않는 사용자 지정 클레임 공급자도 확인할 수 있습니다(기본적으로 사용하도록 설정되는 클레임 공급자는 여러 위치에서 사용됨).
클레임 공급자를 확인할 때 먼저 이해해야 하는 점은, 웹 응용 프로그램에 대해 사용하도록 설정되어 있는 항목을 찾아서는 안 된다는 것입니다. 많은 사용자들이 이 정보를 찾는 데 시간을 낭비하는 경우가 많습니다. 클레임 공급자는 웹 응용 프로그램 수준이 아니라 영역 수준에서 적용됩니다. 그러면 SharePoint URL이 주어졌을 때 이 정보를 어떻게 찾을 수 있을까요?
먼저, 원하는 URL을 기반으로 새 SPSite를 가져옵니다.
using (SPSite theSite = new SPSite("https://someUrl"))
{
…
}
SPSite 개체를 가져온 후에는 웹 응용 프로그램과 영역을 가져올 수 있습니다.
//get the web app
SPWebApplication wa = theSite.WebApplication;
//get the zone for the site
SPUrlZone theZone = theSite.Zone;
이 정보를 통해 영역의 SPIisSettings를 가져올 수 있습니다. 여기에 유용한 정보가 대부분 포함되어 있습니다.
//get the settings associated with the zone
SPIisSettings theSettings = wa.GetIisSettingsWithFallback(theZone);
영역 정보를 가져온 후에는 해당 영역에 대해 인증 공급자와 클레임 공급자를 모두 가져올 수 있습니다. 이러한 공급자 정보는 ClaimsAuthenticationProviders 및 ClaimsProviders에 포함되어 있습니다. 각 ClaimsAuthenticationProvider에는 정보가 극히 일부분만 포함되어 있으며, PowerShell에서 Get-SPTrustedIdentityTokenIssuers 등을 수행하면 이러한 정보만 가져오게 됩니다. 따라서 핵심적인 기본 개체를 가져오려면 ClaimsAuthenticationProvider를 사용하고 여기서 SPTrustedLoginProvider를 가져와야 합니다. 다행히도 이를 위한 코드 역시 쉽게 작성할 수 있습니다. 다음은 제가 LINQ를 사용하여 SPTrustedLoginProviders 목록을 쿼리하는 코드의 예제입니다. 이 예제에서는 SAML 클레임 공급자(SPTrustedIdentityTokenIssuer)에 대한 정보만 가져옵니다.
//get the token service manager so we can retrieve the appropriate
//trusted login provider
SPSecurityTokenServiceManager sptMgr = SPSecurityTokenServiceManager.Local;
//get the list of authentication providers associated with the zone
foreach (SPAuthenticationProvider prov in theSettings.ClaimsAuthenticationProviders)
{
//make sure the provider we're looking at is a SAML claims provider
if (prov.GetType() == typeof(Microsoft.SharePoint.Administration.SPTrustedAuthenticationProvider))
{
//get the SPTrustedLoginProvider using the DisplayName
var lp =
from SPTrustedLoginProvider spt in
sptMgr.TrustedLoginProviders
where spt.DisplayName == prov.DisplayName
select spt;
//there should only be one match, so retrieve that
if ((lp != null) && (lp.Count() > 0))
{
//get the login provider
SPTrustedLoginProvider loginProv = lp.First();
}
}
}
코드를 완성하기 위해 아래에 전체 코드를 붙여 넣겠습니다. 이 특정 시나리오에서는 영역에 연결된 모든 SPTrustedIdentityTokenIssuers를 찾고, 각 SPTrustedIdentityTokenIssuers에 대해 공급자의 이름과 URL(해당 공급자를 사용할 때 인증을 위해 리디렉션되는 위치)이 포함된 문자열을 만듭니다.
using (SPSite theSite = new SPSite("https://someUrl"))
{
//get the web app
SPWebApplication wa = theSite.WebApplication;
//get the zone for the site
SPUrlZone theZone = theSite.Zone;
//get the settings associated with the zone
SPIisSettings theSettings = wa.GetIisSettingsWithFallback(theZone);
//if this isn't a claims auth site then bail out
if (!theSettings.UseTrustedClaimsAuthenticationProvider)
{
MessageBox.Show("This is not a SAML claims auth site");
return;
}
//clear the list of providers out
ProviderLst.Items.Clear();
//get the token service manager so we can retrieve the appropriate
//trusted login provider
SPSecurityTokenServiceManager sptMgr = SPSecurityTokenServiceManager.Local;
//get the list of authentication providers associated with the zone
foreach (SPAuthenticationProvider prov in
theSettings.ClaimsAuthenticationProviders)
{
//make sure the provider we're looking at is a SAML claims provider
if (prov.GetType() ==
typeof(Microsoft.SharePoint.Administration.SPTrustedAuthenticationProvider))
{
//get the SPTrustedLoginProvider using the DisplayName
var lp =
from SPTrustedLoginProvider spt in
sptMgr.TrustedLoginProviders
where spt.DisplayName == prov.DisplayName
select spt;
//there should only be one match, so retrieve that
if ((lp != null) && (lp.Count() > 0))
{
//get the login provider
SPTrustedLoginProvider loginProv = lp.First();
//get the login info
string provInfo = prov.DisplayName + " - " +
loginProv.ProviderUri.ToString();
//add the login info to the list
ProviderLst.Items.Add(provInfo);
}
}
}
}
이 문서는 번역된 블로그 게시물입니다. 원본 문서는 How To Get All Claims Providers Associated with a Web Application in SharePoint 2010을 참조하십시오.