2012-07-13 38 views
4

基于用户角色/权限使用GWT和Spring Security创建条件用户界面的最佳做法是什么?有GWT和Spring安全性的条件UI?

我知道你不能依赖客户端安全。我将在服务器端进行安全检查。条件用户界面仅用于外观。

回答

4

你将需要一个服务来获取用户角色从服务器(它们有)到客户端(不)的列表。在回调的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 
+0

这是一种很好的做法吗? – Braj 2014-06-02 21:27:31

+0

@Braj我不知道它的良好做法,但这是我做的。 – user1207177 2014-06-02 21:30:26

1

我们使用GWT.runAsync来关闭部分用户可能不需要看到的代码。当需要加载UI时,我们只需查看他们需要的内容,然后将其显示给他们。

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