简体   繁体   English

在LinuxFX上运行时,JavaFX应用程序中的iFrame无法加载某些页面

[英]iFrame in JavaFX application not loading certain pages when running on Linux

From within my Java FX app, I'm supposed to load a simple HTML page that includes an iframe which displays external websites. 从我的Java FX应用程序中,我应该加载一个简单的HTML页面,其中包含一个显示外部网站的iframe。 I know I can use webEngine.load() to load the websites but as a requirement I had to implement it this way (I'm trying to incorporate the Duo Security Web SDK into our Java app). 我知道我可以使用webEngine.load()来加载网站,但是作为一项要求,我必须以这种方式实现(我正在尝试将Duo Security Web SDK合并到我们的Java应用程序中)。

On Windows, everything works fine. 在Windows上,一切正常。 However certain websites are not loading on Linux (Debian, Fedora). 但是,某些网站未在Linux上加载(Debian,Fedora)。 I can display sites like gmail (https), espn.com, or en.wikipedia.org. 我可以显示gmail(https),espn.com或en.wikipedia.org之类的网站。 However google and yahoo won't load. 但是,不会加载google和yahoo。 I don't think it's a https or flash issue. 我不认为这是https或Flash问题。 Please see the code below. 请参见下面的代码。

Java: Java:

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: 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>

THis fixes HTTPS: 这修复了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);
}

use installCertificateVerificationBypassTools() in the public void start(Stage mainStage) method, in the myClass extends Application class. myClass扩展Application类的public void start(Stage mainStage)方法中使用installCertificateVerificationBypassTools()

Be advised that this accepts all incoming certificates. 请注意,它接受所有传入的证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM