java - 使用 GWT 和 Spring Security 的条件 UI?

标签 java spring gwt spring-security gwt2

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

我知道您不能依赖客户端安全性。我将在服务器端进行安全检查。条件 UI 实际上只是为了外观。

最佳答案

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

关于java - 使用 GWT 和 Spring Security 的条件 UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11477325/

相关文章:

java - 如何通过 JMX 在 WebSphere Liberty 中创建数据源

Java 8 根据偶数求和或减去

java - bash 命令使用 java process builder 复制文件

java - UiBinder:我可以重写工厂方法吗?

java - 我可以在本地运行并调试使用 Google API 的 Web 应用程序吗? [GWT+GAE]

java - 如何在 lib 文件夹中创建一个包含所有依赖项的 Netbeans 样式的 Jar?

java - Spring + hibernate : No property findAddresses found for type UserProfile while fetching a list

java - 存储过程出站网关中的参数数量不定

java - spring-boot 更新到 1.3.1 后 webapp 无法启动

java - GWT mvp 示例项目 : cannot call method of presenter