简体   繁体   English

GWT-Web应用程序的历史记录管理

[英]GWT- History Management for web application

I am working on History management for my application. 我正在为我的应用程序进行历史记录管理。 I have two views, one is login and the other is main application. 我有两个视图,一个是登录名,另一个是主应用程序。 I have added local links #login and #application. 我添加了本地链接#login和#application。 Now ideally what should happen is, when the user opens the application he should see the login view which has #login token. 现在理想情况下应该发生的是,当用户打开应用程序时,他应该看到带有#login令牌的登录视图。 It works fine. 工作正常。 Then when his credentials are validated he goes to application view with token #application. 然后,当他的凭据经过验证后,他将使用令牌#application进入应用程序视图。 And when he logs out he goes back to #login. 当他注销时,他返回到#login。 All this works fine. 所有这些都很好。 But what bothers me is when I change the link token from #login to #application manually, the main application opens directly even after I have logged out. 但是令我困扰的是,当我手动将链接令牌从#login更改为#application时,即使注销后主应用程序仍会直接打开。 But when I try the same thing in a new tab, it works fine. 但是,当我在新标签中尝试相同的操作时,效果很好。 The application is vulnerable to attacks which needs to be fixed. 该应用程序容易受到需要修复的攻击。 I need some help here. 我需要一些帮助。

    //When application loads
    History.newItem("application",true);           
    //When login screen loads //     
    History.newItem("login",true); 

    //On change
    History.addValueChangeHandler(new ValueChangeHandler<String>(){   

        @Override     
        public void onValueChange(ValueChangeEvent<String> event) { 
            String historyToken   = event.getValue(); 
            if (historyToken.substring(0, 5).equals("login")) {
                login();   
            }
            if (historyToken.substring(0, 11).equals("application")) {
                     mainApplicationView();    
            }
     });

When I logout, login() method is called which loads relevant panels into RootPanel and also has #login token inside. 注销时,将调用login()方法,该方法会将相关面板加载到RootPanel中,并且内部也包含#login令牌。 Also, the main application panels are removed from rootpanel. 同样,主应用程序面板也从rootpanel中删除。

The mistake was inside second if condition: 错误是在第二个条件内:

    History.addValueChangeHandler(new ValueChangeHandler<String>(){   

            @Override     
            public void onValueChange(ValueChangeEvent<String> event) { 
                String historyToken   = event.getValue(); 
                if (historyToken.substring(0, 5).equals("login")) {
                    login();   
                }
                if (historyToken.substring(0, 11).equals("application")) {
                    startApplication(); //it will again check if the session is valid. If not, login screen will show up. Else mainApplication.
                }
    });

After I logout, it should not allow me to see the application page in any case. 注销后,无论如何都不允许我查看应用程序页面。 So, I should make sure that sessionID is valid. 因此,我应该确保sessionID有效。 I did it only once when the application start but not under History.addChangeHandler. 当应用程序启动时,我只执行了一次,但是在History.addChangeHandler下却没有。 This was a blunder. 这是一个错误。

    String sessionID = Cookies.getCookie("JSESSIONID");
    if(sessionID == null) {
        login();
    } else {
        checkWithServer();
    }

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

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