【问题标题】:iFrame in JavaFX application not loading certain pages when running on LinuxJavaFX 应用程序中的 iFrame 在 Linux 上运行时未加载某些页面
【发布时间】:2014-08-14 19:27:59
【问题描述】:

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

在 Windows 上,一切正常。但是,某些网站无法在 Linux(Debian、Fedora)上加载。我可以显示像 gmail (https)、espn.com 或 en.wikipedia.org 这样的网站。但是谷歌和雅虎不会加载。我认为这不是 https 或 flash 问题。请看下面的代码。

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:

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

【问题讨论】:

    标签: java linux iframe webview javafx


    【解决方案1】:

    这修复了 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);
    }
    

    myClass extends Application 类的 public void start(Stage mainStage) 方法中使用 installCertificateVerificationBypassTools()

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

    【讨论】:

    • 感谢您的回答。我实际上发现了问题所在。该应用程序的另一部分实际上是清除导致 SSL 通信失败的信任库路径。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2015-11-11
    • 2013-10-20
    相关资源
    最近更新 更多