2

最近、既存の Web アプリケーションでクレームベース認証を使い始めました。アプリケーションは jQuery と、特に AJAX 関数を使用するため、ハンドラーを変更してXmlHTTPRequests.

FederatedAuthentication.WSFederationAuthenticationModule.AuthorizationFailedイベント ハンドラは次のとおりです。

    protected void WSFederationAuthenticationModule_AuthorizationFailed(object sender, AuthorizationFailedEventArgs e)
    {
        //WSFederationAuthenticationModule sam = (WSFederationAuthenticationModule)sender;

        HttpContext context = HttpContext.Current;
        HttpRequest req = context.Request;
        HttpResponse resp = context.Response;

        if (req == null || resp == null) return;

        if ((resp.StatusCode == 302 || resp.StatusCode == 401) && req.Headers["X-Requested-With"] == "XMLHttpRequest")
        {
            resp.StatusCode = 403;
            e.RedirectToIdentityProvider = false;
        }

    }

AJAX 呼び出しを実装して応答を処理する次のパターンがあります。

$.ajax({
cache: false,
data: $.param(o),
dataType: "xml",
url: "AJAXCall.ashx",
success: function (data)
{
    // Success handler
},
error: function (XMLHttpRequest, textStatus, responseText)
{
    if (XMLHttpRequest.status == 403)
    {
        var retVal = window.showModalDialog("Session.aspx", "", "dialogHeight: 250px; dialogWidth: 250px; edge: Raised; center: Yes; resizable: Yes; status: Yes;");
        if (retVal)
        {
            // Succesful session renewal handler
        }
        else
        {
            // Session renewal failure handler
        }
    }
    else
    {
        // Other errors handler
    }
}
});

'Session.aspx' は基本的にモーダル ダイアログを閉じて、ID プロバイダーへのリダイレクトと戻りが成功した場合、戻り値は true になります。

しかし、私の問題は、次のエラーが発生することです。

「ID4223: SamlAssertion.NotOnOrAfter 条件が満たされていないため、SamlSecurityToken は拒否されました。」

これは、現在のアプリケーション ユーザーを偽装するサブシステムで呼び出され、明らかに前のセッションのトークンが引き続き保持されます。アプリケーションの web.config に次の設定があります。

<federatedAuthentication>
<wsFederation passiveRedirectEnabled="true" persistentCookiesOnPassiveRedirects="true" issuer="https://adfs.example.com/adfs/ls/" realm="https://www.example.com:449/" requireHttps="true" />
<cookieHandler requireSsl="true" />

このエラーを回避するにはどうすればよいですか? どんな助けでも大歓迎です。

4

1 に答える 1

3

次のFederatedAuthentication.WSFederationAuthenticationModule.SignInErrorイベント ハンドラー メソッドが問題を解決しました。

    protected void WSFederationAuthenticationModule_SignInError(object sender, ErrorEventArgs e)
    {
        // handle an intermittent error that most often occurs if you are redirected to the STS after a session expired,
        // and the user clicks back on the browser - second error very uncommon but this should fix
        if (e.Exception.Message.StartsWith("ID4148") ||
            e.Exception.Message.StartsWith("ID4243") ||
            e.Exception.Message.StartsWith("ID4223"))
        {
            FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie();
            e.Cancel = true;
        }
    }

セッションの有効期限が切れた後にユーザーが STS サービスにリダイレクトされた後でも、永続化されたセッション トークン Cookie は削除されます。

于 2013-04-10T07:28:09.200 に答える