2

I have a setup where I obtain protected JNLP via browser, and JNLP saves the authentication cookie as a property. Then javaws is run with the jnlp file. The jnlp requires protected resources, so I need to pass the authentication cookie to the javaws process, so it can use it when downloading the resources... How can I pass the auth cookie to javaws process?

I've checked all parameters available to javaws and JNLP but I couldnt find how this can be done.

Is this even possible?

4

2 回答 2

2

我想我找到了解决方案。Java Web Start 使用与 Internet Explorer 相同的 cookie 存储 - 请参阅此处的评论,了解 JavaWebStart 应用程序如何获取 IE 持久性 cookie。

为了让它发挥作用,我开发了以下内容:

  1. JNLP 和 jars 受到保护
  2. 通过 IE 访问 JNLP - 这会将您重定向到您登录的登录页面并获取身份验证 cookie
  3. 在您的 Web 服务器中有一个 servlet,它拦截身份验证 cookie,使其持久化并将其添加到响应中

    public class CookieServlet extends org.springframework.web.servlet.mvc.AbstractController {
    ...
        protected ModelAndView handleRequestInternal(final HttpServletRequest req,
                                             final HttpServletResponse resp) throws Exception {
            ....
            Cookie[] cookies = req.getCookies();
            String session = null;
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("AUTHSESSION")) {
                        session = cookie.getValue();
                        break;
                    }
                }
            }
    
    
            if(null!=session) {
                Cookie cookie = new Cookie("AUTHSESSION", session);
                cookie.setMaxAge(<specify cookie age>);
                resp.addCookie(cookie);
            }
            ...
        }
    
  4. 现在通过 cmd.exe 启动您的 jnlp - 您可以毫无问题地访问资源,因为它从 IE cookie 存储中获取 cookie

注意:如果您的身份验证支持将身份验证会话令牌作为参数传递,那么您还可以扩展 jnlp“jar”标签以包含 AUTHSESSION 值,即

<jar href="your_jar.jar?AUTHSESSION=<session value>"/>

对我们来说,情况并非如此,身份验证会话必须作为 cookie 提供。

于 2015-02-05T13:23:47.960 回答
1

我认为您所需要的只是从您的服务器动态创建的 JNLP,其中包括 cookie(或者更好的票证?)作为<parameter>. 这篇文章对我帮助很大http://wayback.archive.org/web/20160423141428/http://portal.krypthonas.de/2010/10/11/passing-dynamically-parameters-to-a-java-web-启动应用程序 jnlp/

于 2015-01-27T07:48:38.737 回答