【问题标题】:Conditional UI with GWT and Spring Security?带有 GWT 和 Spring Security 的条件 UI?
【发布时间】:2012-07-13 19:44:27
【问题描述】:

根据用户角色/权限使用 GWT 和 Spring Security 创建条件 UI 的最佳实践是什么?

我知道您不能依赖客户端安全性。我将在服务器端进行安全检查。 Conditional UI 真的只是为了外观。

【问题讨论】:

    标签: java spring gwt spring-security gwt2


    【解决方案1】:

    您将需要一项服务来从服务器(有)获取用户角色列表到客户端(没有)。在回调的 onSuccess 方法中,您将有类似以下的代码:

    if (roles.contains("role1")) {
        GWT.runAsync(new RunAsyncCallback() {
            public void onFailure(Throwable caught) {
                Window.alert("Code download failed");
            }
    
            public void onSuccess() {
                // code here if the user has role1
            }
        });
    }
    if (roles.contains("role2")) {
        GWT.runAsync(new RunAsyncCallback() {
            public void onFailure(Throwable caught) {
                Window.alert("Code download failed");
            }
    
            public void onSuccess() {
                // code here if the user has role2
            }
        });
    }
    // and so on
    

    【讨论】:

      【解决方案2】:

      我们使用 GWT.runAsync 来分块用户可能不需要查看的代码部分。当需要加载 UI 时,我们只是检查他们需要什么,然后将其显示给他们。

      我们已将大部分必要的业务逻辑抽象为我们为每个用户下载的设置,例如“showTeacherControls”、“showAdvisorControls”和“showStudentControls”。然后客户端可以检查这些标志以确定要显示的内容。

      【讨论】:

        猜你喜欢
        • 2016-08-03
        • 2018-01-29
        • 2017-07-22
        • 2010-12-09
        • 2011-09-28
        • 2023-03-06
        • 2017-10-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多