SessionAuthenticationModule 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
WS-Federation 시나리오에서 세션 쿠키를 처리하는 ASP.NET 모듈을 구현합니다.
public ref class SessionAuthenticationModule : System::IdentityModel::Services::HttpModuleBase
public class SessionAuthenticationModule : System.IdentityModel.Services.HttpModuleBase
type SessionAuthenticationModule = class
inherit HttpModuleBase
Public Class SessionAuthenticationModule
Inherits HttpModuleBase
- 상속
예제
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
//SUBSCRIBE TO SAM EVENTS
FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenCreated += new EventHandler<SessionSecurityTokenCreatedEventArgs>(SessionAuthenticationModule_SessionSecurityTokenCreated);
FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenReceived += new EventHandler<SessionSecurityTokenReceivedEventArgs>(SessionAuthenticationModule_SessionSecurityTokenReceived);
FederatedAuthentication.SessionAuthenticationModule.SigningOut += new EventHandler<SigningOutEventArgs>(SessionAuthenticationModule_SigningOut);
FederatedAuthentication.SessionAuthenticationModule.SignedOut += new EventHandler(SessionAuthenticationModule_SignedOut);
FederatedAuthentication.SessionAuthenticationModule.SignOutError += new EventHandler<ErrorEventArgs>(SessionAuthenticationModule_SignOutError);
}
void SessionAuthenticationModule_SignOutError(object sender, ErrorEventArgs e)
{
System.Diagnostics.Trace.WriteLine("Handling SignOutError event");
}
void SessionAuthenticationModule_SignedOut(object sender, EventArgs e)
{
System.Diagnostics.Trace.WriteLine("Handling SignedOut event");
}
void SessionAuthenticationModule_SigningOut(object sender, SigningOutEventArgs e)
{
System.Diagnostics.Trace.WriteLine("Handling SigningOut event");
}
void SessionAuthenticationModule_SessionSecurityTokenReceived(object sender, SessionSecurityTokenReceivedEventArgs e)
{
System.Diagnostics.Trace.WriteLine("Handling SessionSecurityTokenReceived event");
}
void SessionAuthenticationModule_SessionSecurityTokenCreated(object sender, SessionSecurityTokenCreatedEventArgs e)
{
System.Diagnostics.Trace.WriteLine("Handling SessionSecurityTokenCreated event");
//Store session on the server-side token cache instead writing the whole token to the cookie.
//It may improve throughput but introduces server affinity that may affect scalability
FederatedAuthentication.SessionAuthenticationModule.IsReferenceMode = true;
}
다음 XML은 ASP.NET 파이프라인에서 SAM을 구성하는 방법을 보여줍니다. 일반적인 구성에 있는 다른 많은 요소는 간결하게 하기 위해 여기에서 생략됩니다.
<configuration>
<system.webServer>
<modules>
<!--WIF 4.5 modules -->
<add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="WsFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</modules>
</system.webServer>
</configuration>
설명
ASP.NET 파이프라인 SessionAuthenticationModule 에 있는 경우 SAM은 WS-Federation 시나리오에서 세션 쿠키를 처리합니다. 속성에서 지정한 CookieHandler 쿠키 처리기를 사용하여 HTTP 요청에서 원시 세션 쿠키를 읽고 HTTP 응답에 씁니다. 애플리케이션이 SessionSecurityTokenHandler 원시 세션 쿠키를 개체로 SessionSecurityToken 역직렬화하도록 구성된 항목을 사용합니다. 세션 보안 토큰에는 요청이 제공되는 엔터티와 연결된 클레임Claim() 및 보안 주체(ClaimsPrincipal)가 포함됩니다.
SAM은 이벤트 OnAuthenticateRequest 처리기를 ASP.NET 파이프라인의 HttpApplication.AuthenticateRequest 이벤트에 추가합니다. 이 처리기는 로그인 요청을 가로채고 세션 쿠키가 있는 경우 세션 토큰으로 역직렬화하고 세션 토큰에 포함된 클레임 보안 주체로 속성 및 HttpContext.User 속성을 설정합니다Thread.CurrentPrincipal. 이 프로세스 중에 SAM이 노출하는 다른 여러 메서드를 호출합니다.
메서드를 SignOut 호출하여 세션에서 사용자를 로그아웃할 수 있습니다(예: SignOut.aspx.cs 코드 숨김 파일).
SAM은 처리 파이프라인에 대한 액세스를 제공하는 여러 이벤트를 노출합니다. SessionSecurityTokenReceived 및 SessionSecurityTokenCreated 이벤트를 사용하면 쿠키에서 읽거나 처리하는 동안 생성된 세션 토큰을 수정할 수 있습니다. 일반적으로 토큰에서 클레임을 추가, 제거 또는 변환하거나 만료 시간을 조정하기 위해 수행됩니다. SigningOut, SignedOut및 SignOutError 이벤트는 로그아웃 요청 처리에 대한 후크를 제공합니다. 대부분의 시나리오에서는 종종 global.asax.cs 파일에 이러한 이벤트에 대한 처리기를 추가하는 것만으로도 충분합니다.
더 복잡한 시나리오의 경우 사용자 지정 SAM을 SessionAuthenticationModule 구현하기 위해 파생할 수 있습니다. 이를 위해 세션 처리 수명 주기의 특정 단계에서 사용자 지정 동작을 제공할 수 있도록 많은 메서드가 호출 OnAuthenticateRequestSignOut 되고 노출됩니다.
SAM을 IIS 버전 7 이상의 요소 아래 또는 IIS 7 이전 버전의 요소 아래에 <system.webServer> 있는 HTTP 모듈에 추가하여 구성 파일의 <system.web> ASP.NET 파이프라인에 추가할 수 있습니다. SAM에서 사용하는 쿠키 처리기는 cookieHandler> 요소로< 구성할 수 있습니다.
생성자
| Name | Description |
|---|---|
| SessionAuthenticationModule() |
SessionAuthenticationModule 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| ContextSessionSecurityToken |
현재HttpContext에 대한 활성 SessionSecurityToken 을 가져옵니다. |
| CookieHandler |
세션 쿠키를 읽고 쓰고 삭제하는 데 사용되는 쿠키 처리기를 가져옵니다. |
| FederationConfiguration |
현재 모듈에 FederationConfiguration 적용되는 개체를 가져오거나 설정합니다. (다음에서 상속됨 HttpModuleBase) |
| IsReferenceMode |
세션 정보(클레임 값 등)를 세션 쿠키에 저장할지 또는 세션 콘텐츠를 서버 쪽에 저장해야 하는지 여부를 지정하는 값을 가져오거나 설정합니다. 쿠키를 사용하여 참조만 저장합니다. |
메서드
이벤트
| Name | Description |
|---|---|
| SessionSecurityTokenCreated |
세션 보안 토큰을 만들 때 발생합니다. |
| SessionSecurityTokenReceived |
쿠키에서 세션 보안 토큰을 읽을 때 발생합니다. |
| SignedOut |
사용자가 로그아웃된 후에 발생합니다. |
| SigningOut |
로그인 세션을 삭제하기 전에 발생합니다. |
| SignOutError |
로그아웃하는 동안 오류가 발생할 때 발생합니다. |