JavaFX应用程序中的iFrame在Linux上运行时不加载某些页面

时间:2014-08-14 19:27:59

标签: java linux iframe webview javafx

在我的Java FX应用程序中,我应该加载一个简单的HTML页面,其中包含一个显示外部网站的iframe。我知道我可以使用webEngine.load()来加载网站,但作为一项要求,我必须以这种方式实现它(我试图将Duo Security Web SDK合并到我们的Java应用程序中)。

在Windows上,一切正常。但是某些网站没有在Linux上加载(Debian,Fedora)。我可以显示gmail(https),espn.com或en.wikipedia.org等网站。然而谷歌和雅虎不会加载。我不认为它是https或flash问题。请参阅下面的代码。

爪哇:

webEngine.getLoadWorker().stateProperty().addListener(
    new javafx.beans.value.ChangeListener<State>() {
        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == State.SUCCEEDED) {
                webEngine.executeScript(
                      "window.duoHost = '"+duoHost+"';"
                    + "window.duoSigRequest = '"+duoSigRequest+"';"
                    + "loadDuoOptions();");
                JSObject jsobj = (JSObject) webEngine.executeScript("window");
                jsobj.setMember("java", new Bridge());
                System.out.println("Set up done");
            }
        }
    });

HTML:

<head>
<title>Designer Login with Duo </title>
<script src="Duo-Web-v1.bundled.js"></script>
<script>
    function loadDuoOptions(){
        Duo.init({
            'host' :  window.duoHost,
            'sig_request' : window.duoSigRequest 
        });
        Duo.ready();
    }
    window.processDuoResponse = function(data){
        duoResponse = data;
        loginHandler.verifyDuoResponse(duoResponse);
    }
</script>
</head>
<body>
<iframe id="duo_iframe" width="500" height="500" frameborder="0"></iframe>
</html>

1 个答案:

答案 0 :(得分:0)

这修复了HTTPS:

private void installCertificateVerificationBypassTools() {
    this.installCustomTrustManager();
    this.installCustomHostNameverifier();

}

private void installCustomTrustManager() {
    System.out.println("Installing custom trust manager");
    try {
        TrustManager[] nonDiscriminantTrustManager = new TrustManager[]{new X509TrustManager() {
            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
                // ignore client trust check
            }

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
                // ignore server trust check
            }
        }};
        final SSLContext ret = SSLContext.getInstance("SSL");
        ret.init(null, nonDiscriminantTrustManager, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(ret.getSocketFactory());
    } catch (KeyManagementException | NoSuchAlgorithmException ex) {

    }
}

private void installCustomHostNameverifier() {
    System.out.println("Installing custom hostname verifier");
    HostnameVerifier hv = new HostnameVerifier() {
        @Override
        public boolean verify(String string, SSLSession ssls) {
            System.out.println("Verifying connection...");
            showSSLSessionDetails(ssls);
            if (ssls.getProtocol().contains("https")) {
                System.out.println("https session allowed.");
            }
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
}

mySplass扩展应用程序类的 public void start(Stage mainStage)方法中使用 installCertificateVerificationBypassTools()

请注意,这会接受所有传入的证书。

相关问题