다음을 통해 공유


SessionAuthenticationModule 클래스

정의

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
상속
SessionAuthenticationModule

예제

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은 처리 파이프라인에 대한 액세스를 제공하는 여러 이벤트를 노출합니다. SessionSecurityTokenReceivedSessionSecurityTokenCreated 이벤트를 사용하면 쿠키에서 읽거나 처리하는 동안 생성된 세션 토큰을 수정할 수 있습니다. 일반적으로 토큰에서 클레임을 추가, 제거 또는 변환하거나 만료 시간을 조정하기 위해 수행됩니다. SigningOut, SignedOutSignOutError 이벤트는 로그아웃 요청 처리에 대한 후크를 제공합니다. 대부분의 시나리오에서는 종종 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
AuthenticateSessionSecurityToken(SessionSecurityToken, Boolean)

들어오는 세션 토큰의 유효성을 검사하여 들어오는 요청을 인증합니다. 유효성 검사가 성공하면 현재 HTTP 컨텍스트 및 스레드 보안 주체를 지정된 SessionSecurityToken것으로 업데이트합니다.

ContainsSessionTokenCookie(HttpCookieCollection)

세션 쿠키가 지정된 쿠키 컬렉션에 있는지 여부를 확인합니다.

CreateSessionSecurityToken(ClaimsPrincipal, String, DateTime, DateTime, Boolean)

SessionSecurityToken 구성된 세션 토큰 처리기를 사용하여 지정된 매개 변수에서 a를 만듭니다.

DeleteSessionTokenCookie()

세션 쿠키를 삭제하고 캐시에서 제거합니다.

Dispose()

클래스의 현재 인스턴스에서 사용하는 리소스(메모리 제외)를 해제합니다 HttpModuleBase .

(다음에서 상속됨 HttpModuleBase)
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
Init(HttpApplication)

HTTP 모듈을 초기화합니다.

(다음에서 상속됨 HttpModuleBase)
InitializeModule(HttpApplication)

모듈을 초기화하고 모듈의 ASP.NET 애플리케이션 개체에서 이벤트를 처리하도록 준비합니다.

InitializePropertiesFromConfiguration()

구성 파일의 정의를 기반으로 모듈 속성을 초기화합니다.

MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnAuthenticateRequest(Object, EventArgs)

ASP.NET 파이프라인에서 이벤트를 처리합니다 AuthenticateRequest .

OnPostAuthenticateRequest(Object, EventArgs)

ASP.NET 파이프라인에서 이벤트를 처리합니다 PostAuthenticateRequest .

OnSessionSecurityTokenCreated(SessionSecurityTokenCreatedEventArgs)

SessionSecurityTokenCreated 이벤트를 발생시킵니다.

OnSessionSecurityTokenReceived(SessionSecurityTokenReceivedEventArgs)

SessionSecurityTokenReceived 이벤트를 발생시킵니다.

OnSignedOut(EventArgs)

SignedOut 이벤트를 발생시킵니다.

OnSigningOut(SigningOutEventArgs)

SigningOut 이벤트를 발생시킵니다.

OnSignOutError(ErrorEventArgs)

SignOutError 이벤트를 발생시킵니다.

ReadSessionTokenFromCookie(Byte[])

SessionSecurityToken 지정된 세션 쿠키에서 읽습니다.

SetPrincipalFromSessionToken(SessionSecurityToken)

지정된 세션 토큰에 HttpContext 포함된 보안 주체 및 Thread 보안 주체에 대한 보안 주체를 설정합니다.

SignOut()

현재 사용자를 로그아웃하고 연결된 이벤트를 발생합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
TryReadSessionTokenFromCookie(SessionSecurityToken)

세션 쿠키에서 읽기 SessionSecurityToken 를 시도하고 세션 쿠키를 성공적으로 읽었는지 여부를 나타내는 값을 반환합니다.

ValidateSessionToken(SessionSecurityToken)

지정된 SessionSecurityToken ID의 유효성을 검사하고 해당 ID를 반환합니다.

WriteSessionTokenToCookie(SessionSecurityToken)

세션 쿠키에 지정된 SessionSecurityToken 내용을 씁니다.

이벤트

Name Description
SessionSecurityTokenCreated

세션 보안 토큰을 만들 때 발생합니다.

SessionSecurityTokenReceived

쿠키에서 세션 보안 토큰을 읽을 때 발생합니다.

SignedOut

사용자가 로그아웃된 후에 발생합니다.

SigningOut

로그인 세션을 삭제하기 전에 발생합니다.

SignOutError

로그아웃하는 동안 오류가 발생할 때 발생합니다.

적용 대상