Share via


c2WTS에서 토큰을 요청하는 방법

다음 코드 샘플은 에서 토큰을 요청한 다음 이 토큰을 사용하여 사용자를 가장하는 방법을 보여 줍니다. 자세한 내용은 c2WTS(Claims to Windows Token Service) 개요를 참조하십시오.

// Get the current identity and extract the UPN claim. IClaimsIdentity identity = ( ClaimsIdentity )Thread.CurrentPrincipal.Identity; string upn = null; foreach ( Claim claim in identity.Claims ) { if ( StringComparer.Ordinal.Equals( System.IdentityModel.Claims.ClaimTypes.Upn, claim.ClaimType ) ) { upn = claim.Value; } }

// Perform the UPN logon through the c2WTS. WindowsIdentity windowsIdentity = null; if ( !String.IsNullOrEmpty( upn ) ) { try { windowsIdentity = S4UClient.UpnLogon( upn ); } catch ( SecurityAccessDeniedException ) { Console.WriteLine( "Could not map the upn claim to a valid windows identity." ); return; } } else { throw new Exception( "No UPN claim found" ); }

using ( WindowsImpersonationContext ctxt = windowsIdentity.Impersonate() ) { // Access the resource. }

관리자는 허용되는 호출자 목록으로 를 구성해야 합니다. 허용되는 호출자 목록은 WIF 설치 폴더 내부의 버전 폴더에 있는 구성 파일 c2wtshost.exe.configMicrosoft.IdentityModel 섹션에 있는 allowedCallers 요소의 SID(보안 식별자) 목록입니다. 예를 들어 WIF 버전 3.5를 C:\Program Files에 설치한 경우 c2wtshost.exe.config 파일은 C:\Program Files\Windows Identity Foundation\v3.5 폴더에 있습니다. 다음 예를 참조하십시오.

<?xml version="1.0"?>

<configuration> <configSections> <section name="windowsTokenService" type="Microsoft.IdentityModel.WindowsTokenService.Configuration.WindowsTokenServiceSection, Microsoft.IdentityModel.WindowsTokenService, Version=0.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </configSections>

  <windowsTokenService> <!-- By default no callers are allowed to use the Claims to Windows Token Service. Add the identities you wish to allow below. --> <allowedCallers> <clear/> <!-- <add value="NT AUTHORITY\Network Service" /> --> <!-- <add value="NT AUTHORITY\Local Service" /> --> <!-- <add value="NT AUTHORITY\System" /> --> <!-- <add value="NT AUTHORITY\Authenticated Users" /> --> </allowedCallers> </windowsTokenService> </configuration>