문제

양식으로 인증 된 ASPX 페이지로 실행되는 Java 애플릿이 있습니다. 내 사이트의 .NET 1.1 버전에서 애플릿은 세션 쿠키에 액세스 할 수 있으며 서버에서 파일을 검색 할 수 있지만 .NET 2.0 버전에서는 인증되지 않습니다.

나는 2.0이 기본적으로 쿠키를 httponly로 설정한다고 말하는 다른 곳에서 두 개의 포럼 게시물을 보았지만 지금까지 제공된 솔루션은 저에게 효과적이지 않았습니다. 또한 2.0이 사용자 에이전트를 기준으로 차별 할 수 있다는 것을 읽었습니다.

누구든지 이것에 대한 경험이나 통찰력이 있습니까?

도움이 되었습니까?

해결책

This question is old, but I figured it was valuable to have the correct answer here.

Filip is confusing server-side Java with client-side Java. He is correct that you cannot share sessions between two server-side platforms, such as Java (J2EE) and ASP.Net without using a custom approach.

However, applets are client-side and therefore should be able to access the session information of the host page. The issue is that ASP.Net 2.0 added the HttpOnly flag on session cookies. This flag prevents JavaScript and Java applets from accessing these cookies.

The workaround is to turn off the HttpOnly flag on session cookies. While you may be able to do it in the configuration in newer versions of ASP.Net, in previous versions the solution was to add the following code to your Global.asax file:

protected void Application_EndRequest(object sender, EventArgs e)
{
    /**
    * @note Remove the HttpOnly attribute from session cookies, otherwise the 
    *      Java applet won't have access to the session. This solution taken
    *      from
    *      http://blogs.msdn.com/jorman/archive/2006/03/05/session-loss-after-migrating-to-asp-net-2-0.aspx
    *
    *      For more information on the HttpOnly attribute see:
    *
    *      http://msdn.microsoft.com/netframework/programming/breakingchanges/runtime/aspnet.aspx
    *      http://msdn2.microsoft.com/en-us/library/system.web.httpcookie.httponly.aspx
    */
    if (Response.Cookies.Count > 0)
    {
        foreach (string lName in Response.Cookies.AllKeys)
        {
            if (lName == FormsAuthentication.FormsCookieName || 
                lName.ToLower() == "asp.net_sessionid")
            {
                Response.Cookies[lName].HttpOnly = false;
            }
        }
    }
}

Note that even with this fix, not all browser/OS/Java combinations can access cookies. I'm currently researching an issue with session cookies not being accessible on Firefox 4.0.1 with Java 1.6.0_13 on Windows XP.

The workaround is to use the approach Dr. Dad suggested, where the session ID gets passed to the applet as a parameter, and then either gets embedded into the request URL (requires URL sessions to be turned on in the server-side configuration) or sent as a manually-set cookie.

다른 팁

필립은 적어도 Java와 ASP.Net에 맞는 정확하고 잘못된 것입니다. 애플릿은 속임수를 통해 ASP.NET 세션에 액세스 할 수 있습니다. 필자의 경우 세션 ID를 애플릿에 매개 변수로 추가했으며 애플릿은 요청에 쿠키로 추가됩니다. 잘 작동하는 것 같습니다. (우리는 그 불쾌한 해커 민속을 포일하기 위해 세션 ID를 암호화했습니다!)

필립의 대답은 전적으로 정확하지 않습니다. 나는 워크 스테이션에서 HTTP 헤더를 스니핑하는 프로그램을 실행했으며 Java 애플릿은 실제로 어떤 상황에서 ASP.NET 인증 티켓을 제시합니다.

결국 나는 이것에 대한 해결책을 찾았지만 내 문제를 완전히 해결하지 못했습니다. .NET 2.0에서 web.config에 항목을 추가 할 수 있습니다. <httpCookies httpOnlyCookies="false" />; 그러나 이것은 모든 사용자에게 효과가 없었습니다.

장기 솔루션은 Java 애플릿을 수정하여 웹 서버에서 아무것도 검색 할 필요가 없습니다.

나는 그것이 매우 늦은 답변 일 수 있음을 알고 있지만, 더 간단한 해결책을 줄 수 있습니다. - 일반적으로 항상 아플릿이 인터페이스와 상호 작용에 HTML과 JavaScript를 많이 사용합니다. -JavaScript가 브라우저에서 실행됩니다. -Ajax 호출은 브라우저에서 이루어집니다. -Ajax 호출은 비동기식이며 애플릿 로직에 쉽게 통합 될 수 있습니다.

Ajax 호출을 애플릿의 논리에 통합하는 우아한 솔루션을 찾을 수 있으며, 브라우저에 보안을 위임합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top