2012-12-18 2 views
2

Windows Azure ACS로 보호되는 특정 영역이있는 ASP.NET MVC 사이트를 만들려고합니다. 기본 영역을 보호 해제 (익명 사용자 허용)하고 하위 영역 만 보호하려고합니다.세션 시작 후 ACS가 발생했습니다.

나는 Web.config의 system.web 섹션에서 인증 요소를 제거함으로써 이러한 일이 발생했습니다.

<authorization> 
    <deny users="?" /> 
</authorization> 

그런 다음 원하는 MVC3 영역의 보호 된 위치를 추가하십시오.

<location path="MyArea"> 
    <system.web> 
     <authorization> 
      <deny users="?" /> 
     </authorization> 
    </system.web> 
</location> 

그러나, IClaimsIdentity에 액세스하고 내 Global.asax에의으로 session_start 이벤트에서 살았 처리를 위해 오프 특성을 추출하는 데 사용 내 예전의 코드. 사이트가 기본 영역에 액세스하기 위해 인증을 요구하지 않았으므로 인증없이 Session_Start가 발생합니다.

WIF의 인증 이벤트를 처리하기 위해 어떤 이벤트를 연결할 수 있습니까?

SessionAuthenticationModule_SessionSecurityTokenReceived를 사용하여 슬라이딩 세션 시간 초과를 구현했으며 OnPostAuthenticationRequest 이벤트에 내 사용자 분석 논리를 추가하지 않으려 고 시도했습니다. 이 이벤트에서,

FederatedAuthentication.WSFederationAuthenticationModule.SignedIn 

그러나 :

FederatedAuthentication.ServiceConfigurationCreated 

그런 다음이 이벤트에서 나는이 이벤트에 철사 :

나는 다음 이벤트까지, 제 1 배선 후 사용자를 얻을 수 있었다 세션은 null이며 session_start는 다시 호출되지 않습니다. 따라서 ID 공급자로 리다이렉트 할 때 세션이 부서져 버린 것처럼 보입니다. 곧

-> 위해 Application_Start은
곧 ->으로 session_start
이 곧 -> 이동에/MyArea
곧 -> ACS에 옴 -> IDP
익명으로 옴 ->에 옴 ->
인증 로그인/MyArea
auth -> FederatedAuthentication.WSFederationAuthenticationModule.SignedIn이 발생하지만 세션이 null입니다.

업데이트 : 세션과 인증이 모두 존재하는 장소를 아직 찾지 못했습니다. Unity를 사용하여 필요에 따라 사용자를 감지하고 있습니다. 그것이 일어날 때 그것을하는 사건이 있었다면 나는 그것을 좋아할 것입니다.하지만 그 주위의 일은 여전히 ​​효과가 있습니다. 당신은 로그인 후 (로직을 실행하려는시기와 방법에 따라

[Authorize] 
public ActionResult Index() 
{ 
    return View(); 
} 

답변

3

가지고있어 몇 가지 옵션 :

+0

내 FederatedAuthentication 클래스에서 해당 이벤트가없는 것처럼 보입니다. .NET 4.5에서만 사용할 수 있습니까? – markti

0

은 확보 할 컨트롤러/행동의 [권한 부여] 속성을 사용 세션 토큰을 만들 때, 그것을받은 후). SessionAuthenticationModule_SessionSecurityTokenReceived 이벤트는 올바르게 작동하지만 구독은 까다로울 수 있습니다. 이것은 당신이 그것을 할 수있는 방법은 다음과 같습니다

public class MvcApplication : System.Web.HttpApplication 
{ 
    protected void Application_Start() 
    { 
     ... 

     FederatedAuthentication.FederationConfigurationCreated += (s, e) => 
     { 
      FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenCreated += SessionAuthenticationModule_SessionSecurityTokenCreated; 
      FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenReceived += SessionAuthenticationModule_SessionSecurityTokenReceived; 
      FederatedAuthentication.WSFederationAuthenticationModule.SessionSecurityTokenCreated += WSFederationAuthenticationModule_SessionSecurityTokenCreated; 
      FederatedAuthentication.WSFederationAuthenticationModule.SecurityTokenValidated += WSFederationAuthenticationModule_SecurityTokenValidated; 
      FederatedAuthentication.WSFederationAuthenticationModule.SecurityTokenReceived += WSFederationAuthenticationModule_SecurityTokenReceived; 
      FederatedAuthentication.WSFederationAuthenticationModule.SignedIn += WSFederationAuthenticationModule_SignedIn; 
     }; 
    } 

    void SessionAuthenticationModule_SessionSecurityTokenReceived(object sender, SessionSecurityTokenReceivedEventArgs e) 
    { 
     Debugger.Break(); 
    } 

    void SessionAuthenticationModule_SessionSecurityTokenCreated(object sender, SessionSecurityTokenCreatedEventArgs e) 
    { 
     Debugger.Break();    
    } 

    void WSFederationAuthenticationModule_SessionSecurityTokenCreated(object sender, SessionSecurityTokenCreatedEventArgs e) 
    { 
     Debugger.Break();    
    } 

    void WSFederationAuthenticationModule_SecurityTokenValidated(object sender, SecurityTokenValidatedEventArgs e) 
    { 
     Debugger.Break();    
    } 

    void WSFederationAuthenticationModule_SecurityTokenReceived(object sender, SecurityTokenReceivedEventArgs e) 
    { 
     Debugger.Break();    
    } 

    void WSFederationAuthenticationModule_SignedIn(object sender, EventArgs e) 
    { 
     Debugger.Break();  
    } 
} 

이 코드의 모든 Global.asax 파일에 가고, 당신은 SessionAuthenticationModule 및 WSFederationAuthenticationModule 될 때 이것이합니다 (FederationConfigurationCreated 이벤트 인상 후 이벤트를 설정하려는 유효한). 각 이벤트 처리기에 Debugger.Break를 추가했습니다.애플리케이션을 그대로두고 애플리케이션을 디버그하여 각 이벤트가 트리거되는 시점을 확인하십시오. 이렇게하면 논리를 추가 할시기와 위치를 결정할 수 있습니다.