Is it possible to hide Vaadin Version

时间:2016-04-15 11:16:00

标签: vaadin vaadin7

Is there any way to hide the version of vaadin version (i.e v=7.6.2) in page source? Also is it possible to change the default directory "VAADIN" to any other directory or rename it?

enter image description here

3 个答案:

答案 0 :(得分:1)

我认为不可能摆脱VAADIN目录名,因为它在服务器端和客户端的某些框架类中是硬编码的。例如:com.vaadin.server.BootstrapHandler,com.vaadin.server.VaadinServlet和com.vaadin.client.ui.ui.UIConnector

答案 1 :(得分:1)

从技术上讲,可以隐藏Vaadin版本。您所需要的只是在Servlet会话开始时注册BootstrapListener

public class ApplicationBootstrapListener implements BootstrapListener {

    @Override
    public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
        List<Node> nodes = response.getFragmentNodes();
        for (Node node : nodes) {
            if (node.toString()
                    .contains("js?v=")) {
                String fakeVersion = node.attr("src")
                                         .replace("7.5.8", "1.1.1");
                node.attributes()
                    .put("src", fakeVersion);
            }
        }
    }

    @Override
    public void modifyBootstrapPage(BootstrapPageResponse response) {
    }
}

    //somewhere in servletInitialized()
getService().addSessionInitListener(event -> event.getSession()
                       .addBootstrapListener(
                               new ApplicationBootstrapListener()));

在此步骤之后,应用程序应该停止工作。那是因为Vaadin因为你的名字改名而无法找到vaadinBootstrap.js。您可能需要复制此JavaScript的内容,将其放在公共文件夹中的某个位置,并将其重命名为您想要的任何虚假名称(在我的情况下,它将是vaadinBootstrap.js?v=1.1.1

关于第二个问题,我认为这是不可能的,至少没有逆向工程的帮助。

答案 2 :(得分:0)

基于 Kuki 的回答,这在 Vaadin 8.9.4 上对我有用,无需复制任何 js 文件。

@Override
public void modifyBootstrapFragment(BootstrapFragmentResponse bootstrapFragmentResponse) {
    final List<Node> nodes = bootstrapFragmentResponse.getFragmentNodes();
    final String oldVersion = "8.9.4";
    final String fakeVersion = "x.y.z";
    for (Node node : nodes) {
        /* replacing the version in src-attributes */
        if (node.attr("src").contains(oldVersion)) {
            node.attributes().put("src", node.attr("src").replace(oldVersion, fakeVersion));
        }

        /* replacing the version in the child-DataNodes */
        for (Node child : node.childNodes()) {
            if (child instanceof DataNode) {
                final DataNode dataNode = ((DataNode) child);
                if (dataNode.getWholeData().contains(oldVersion)) {
                    dataNode.setWholeData(dataNode.getWholeData().replace(oldVersion, fakeVersion));
                }
            }
        }
    }
}