`JavaFX WebView中的完整性元数据检查失败。忽略SystemProp [英] `Failed integrity metadata check.` in JavaFX WebView, ignores SystemProp

查看:534
本文介绍了`JavaFX WebView中的完整性元数据检查失败。忽略SystemProp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向Microsoft的auth v2打开一个webview。在浏览器中加载很好,但在JavaFX的WebView(JDK 8)中,页面是空白的。一旦我打开控制台输出,我会看到许多行,例如CSS和JS。

I am trying to open a webview to Microsoft's auth v2. Loads fine in a browser, but in JavaFX's WebView (JDK 8) the page is blank. Once I turned on console output, I see many lines such as for both CSS and JS.


[null:0]无法加载样式表https://secure.aadcdn.microsoftonline-p.com/ests/2.1 .8148.16 /内容/ cdnbundles / converged.v2.login.min_t7iocdq0wq2qh0nv233jig2.css。完整性元数据检查失败。

我相对肯定问题是CORS(我正在加载 microsoftonline.com ,资源在 microsoftonline-p.com )。我已经尝试了所有可以解决的问题,或者在网上找到。

I am relatively sure that the issue is with CORS (I am loading microsoftonline.com and the resources are on microsoftonline-p.com). I've tried every possible fix that I can think of, or find online.

我试过设置所有这些

engine.setJavaScriptEnabled(true)

engine.setUserAgent("AppleWebKit/537.44")

System.setProperty("sun.net.http.allowRestrictedHeaders", "true")

我也通过设置属性 -Dsun.net.http.allowRestrictedHeaders = true in VMOptions (如图所示其他)和JavaFX问题 JDK-8096797

I've also set the Property via -Dsun.net.http.allowRestrictedHeaders=true in VMOptions ( as seen here ) and from the JavaFX issue JDK-8096797

该属性显示为设置:

println(System.getProperty("sun.net.http.allowRestrictedHeaders"))

在控制台打印输出上产生 true

yields true on the console printout.

仍然没有变化,在页面输出中,它是一个在网络控制台上发出一个白色的空白屏幕和相同的错误。

Still no change, ever in the page output, it is always a white, blank screen, and the same errors from the web console.

我想我找到了 WebKit中的问题行(参见 matchIntegrityMetadata 甚至,但这并没有帮助我解决问题,因为我不知道如何禁用 integrityCheck

这真的,真让我难过。任何帮助非常赞赏。

This really, really has me stumped. Any help is very appreciated.

供参考,以下是整个方法:

For reference, here is the entire method:

private fun WebView.authWindow(provider: Oath2Account){
    engine.setUserAgent("AppleWebKit/537.44")
    engine.setJavaScriptEnabled(true)
    URLPermission("https://*.com")
    System.setProperty("sun.net.http.allowRestrictedHeaders", "true")

    Platform.runLater {
        engine.userDataDirectory = File("C:\\users\\eric\\javafx_tmp")
        engine.setOnError { println("IN PAGE ERROR --> $it") }
        engine.setOnAlert { println("IN PAGE ALERT --> $it") }
        engine.setConfirmHandler { println("IN PAGE CONFIRM HANDLER --> $it")
        true
        }
        engine.setCreatePopupHandler { println("IN PAGE POPUP --> $it")
        engine}
        engine.setOnResized {   println("IN PAGE RESIZED --> $it") }
        engine.setOnStatusChanged {   println("IN PAGE STATUS CHANGED --> $it")
            println("\t${it.data}")
            println("\t${it.source}")
            println("\t${it.eventType}")
            println("\t${it.target}")
            println("\t${it.isConsumed}")

        }
        engine.setOnVisibilityChanged { println("IN PAGE VISIBILITY CHANGED --> $it") }
        engine.setPromptHandler { println("IN PAGE PROMPTED --> $it")
        "HELLO"}
        println("JavaScript engine status: ${engine.isJavaScriptEnabled}")

        println("engine is loading $loadURL")
        engine.locationProperty().addListener { observable, oldLocation, newLocation->
            println("observable=$observable\noldLocation=$oldLocation\nnewLocation=$newLocation")
            //          if (newLocation.startsWith("urn:ietf:wg:oauth:2.0:oob")) {
            //              val code:get
            //              val title:from
            //              val accessToken = service.getAccessToken(verifier)
            //              doSomething(accessToken.getAccessToken())
            //          }
        }
        com.sun.javafx.webkit.WebConsoleListener.setDefaultListener { webview, message, lineNumber, sourceId -> println("Console: [$sourceId:$lineNumber] $message") }
        engine.setOnError({ event -> System.out.println(event.getMessage()) })
        try{
        engine.load(loadURL )
    } catch (e: IOException) {
        println("caught error:")
        e.printStackTrace();
    }
}


推荐答案

这确认我的回答: Javafx - 打开登录。 webview组件中的microsoftonline.com页面

关键点是外部脚本/链接完整性失败。这不是平台浏览器问题,JavaFX(OpenJFK)依赖于嵌入式webkit引擎。

The critical point is external script/link integrity fails. This is not a platform browser issue, JavaFX (OpenJFK) relies on an embedded webkit engine.

在Windows JDK 8上版本40和版本172之间发生了回归。它正在工作适用于Oracle JDK 9.0.4它不适用于Oracle JDK 11

The regression happened between version 40 and version 172 on windows JDK 8. It's working fine with Oracle JDK 9.0.4 It's not working with Oracle JDK 11

更多详细信息: https://github.com/mguessan/davmail/issues/12

=>更新的答案:实现以覆盖Microsoft表单内容并禁用完整性检查。这不是webkit错误的修复,只是解决方法

=> Updated answer: implemented to override Microsoft form content and disable integrity check. This is not a fix of the webkit bug, just a workaround

try {
    URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            if ("https".equals(protocol)) {
                return new sun.net.www.protocol.https.Handler() {
                    @Override
                    protected URLConnection openConnection(URL url, Proxy proxy) throws IOException {
                        System.out.println("openConnection " + url);

                        if (url.toExternalForm().endsWith("/common/handlers/watson")) {
                            System.out.println("Failed: form calls watson");
                        }
                        final HttpsURLConnectionImpl httpsURLConnection = (HttpsURLConnectionImpl) super.openConnection(url, proxy);
                        if ("login.microsoftonline.com".equals(url.getHost())
                                && "/common/oauth2/authorize".equals(url.getPath())) {

                            return new URLConnection(url) {
                                @Override
                                public void connect() throws IOException {
                                    httpsURLConnection.connect();
                                }

                                public InputStream getInputStream() throws IOException {
                                    byte[] content = readFully(httpsURLConnection.getInputStream());
                                    String contentAsString = new String(content, "UTF-8");
                                    System.out.println(contentAsString);
                                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                    baos.write(contentAsString.replaceAll("integrity", "integrity.disabled").getBytes("UTF-8"));
                                    return new ByteArrayInputStream(baos.toByteArray());
                                }

                                public OutputStream getOutputStream() throws IOException {
                                    return httpsURLConnection.getOutputStream();
                                }

                            };

                        } else {
                            return httpsURLConnection;
                        }
                    }

                };
            }
            return null;
        }
    });
} catch (Throwable t) {
    System.out.println("Unable to register custom protocol handler");
}

这篇关于`JavaFX WebView中的完整性元数据检查失败。忽略SystemProp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆