How to avoid 'SamlAssertion.NotOnOrAfter condition is not satisfied' errors

与世无争的帅哥 提交于 2019-12-07 22:44:45

问题


Recently I have started using claim-based authentication on an existing web application. Because the application makes use of jQuery & more notably, the AJAX functions, I have had to alter the handlers not to attempt to redirect the XmlHTTPRequests, and instead return a 403 status which is easier to handle.

Here is the FederatedAuthentication.WSFederationAuthenticationModule.AuthorizationFailed event hanlder:

    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;
        }

    }

I have the following pattern that implements the AJAX calls and handle the response:

$.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
    }
}
});

The 'Session.aspx' basically closes the modal dialog with a return value of true if it successfully redirected to the Identity Provider and back.

But my problem is that I get the following error:

"ID4223: The SamlSecurityToken is rejected because the SamlAssertion.NotOnOrAfter condition is not satisfied."

This is invoked on a subsystem that impersonates the current application user and obviously the token of the previous session still persist. I have the following setting in my application's 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" />

How do I avoid this error? Any help will be greatly appreciated.


回答1:


The following FederatedAuthentication.WSFederationAuthenticationModule.SignInError event handler method sorted out the problem:

    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;
        }
    }

It will delete the Session Token Cookie that persisted, even after the user has been redirected to the STS service after a session has expired.



来源:https://stackoverflow.com/questions/15904480/how-to-avoid-samlassertion-notonorafter-condition-is-not-satisfied-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!