JavaFX WebView 中的"失败的完整性元数据检查"忽略 SystemProp



我正在尝试打开Microsoft身份验证v2的Web视图。在浏览器中加载正常,但在JavaFX的WebView(JDK 8(中,页面是空白的。打开控制台输出后,我看到许多行,例如 CSS 和 JS。

[null:0] Cannot load stylesheet https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8148.16/content/cdnbundles/converged.v2.login.min_t7iocdq0wq2qh0nv233jig2.css. Failed integrity metadata check.

我相对确定问题出在 CORS 上(我正在加载microsoftonline.com并且资源在microsoftonline-p.com上(。我已经尝试了我能想到或在网上找到的所有可能的修复方法。

我尝试设置所有这些

engine.setJavaScriptEnabled(true)
engine.setUserAgent("AppleWebKit/537.44")
System.setProperty("sun.net.http.allowRestrictedHeaders", "true")

我还通过VMOptions中的-Dsun.net.http.allowRestrictedHeaders=true设置了属性(如此处所示(和JavaFX问题JDK-8096797

该属性显示为设置:

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

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

仍然没有变化,在页面输出中,它始终是白色的空白屏幕,并且来自 Web 控制台的相同错误。

我想我在 WebKit(见matchIntegrityMetadata(中找到了问题线,但这并没有帮助我解决问题,因为我不知道如何禁用完整性检查

这真的,真的让我难倒了。任何帮助都非常感谢

作为参考,这里是整个方法:

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=$observablenoldLocation=$oldLocationnnewLocation=$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 组件中打开 login.microsoftonline.com 页面

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

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

更多详情请见: https://github.com/mguessan/davmail/issues/12

=> 更新:OpenJFX 团队在 Windows 和 Linux 上确认的问题, 看: https://github.com/javafxports/openjdk-jfx/issues/230 和 [网页视图]子资源完整性检查在 Windows 和 Linux 上失败 https://bugs.openjdk.java.net/browse/JDK-8219917

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

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

我发现Web View正在使用适用于mac os/linux os的webkit引擎和适用于Windows机器的IE引擎。我有类似的问题 Javafx - 在 webview 组件中打开 login.microsoftonline.com 页面。Mac OS上的WebView工作正常,但在Windows机器上存在问题。当我调查此问题时,我发现此IE引擎存在问题。我可以访问几台安装了不同版本的IE 11的机器。在有update version 11.0.85的机器上,我无法打开这个站点,但是当我在有update version 11.0.90的机器上尝试时,问题不再存在。因此,如果您使用的是Windows操作系统,请尝试更新IE版本,也许它会解决您的问题。

如果有人仍然遇到此问题,那么您可以通过将JDK或JRE版本更新到1.8.0_281或更高版本来解决此问题。

最新更新