【问题标题】:GWT RequestFactory - different views of 1 EntityProxyGWT RequestFactory - 1 EntityProxy 的不同视图
【发布时间】:2012-07-04 16:43:37
【问题描述】:

我有一个 DocumentEntityProxy 使用以下方法:

String getAttribute1();
void setAttribute1(String s);
String getAttribute2();
void setAttribute2(String s);
String getAttribute3();
void setAttribute3(String s);

我想要实现的是,如果您是标准用户,则只能使用 getAttribute1() 和 setAttribute1() 如果您是管理员用户,则可以使用所有方法。在这个例子中,我只有三个属性和两种不同类型的用户,但在实际项目中当然还有更多。

实现这一目标的最佳方法是什么?

提前感谢您的帮助。

【问题讨论】:

    标签: java requestfactory


    【解决方案1】:

    您可以使用继承:

    class UserEntity {
      String getAttribute1() { }
      void setAttribute1(String s) { }
    }
    
    class AdminEntity extends UserEntity {
      String getAttribute2() { }
      void setAttribute2(String s) { }
    }
    

    还有代理:

    @ProxyFor(UserEntity.class)
    interface UserEntityProxy extends EntityProxy {
      String getAttribute1();
      void setAttribute1(String s);
    }
    
    @ProxyFor(AdminEntity.class)
    interface AdminEntityProxy extends UserEntityProxy {
      String getAttribute2();
      void setAttribute2(String s);
    }
    

    为了保护对实体类型的访问,您可以使用两种查找器方法(返回 userEntity 或 adminEntity)并限制对后端方法的访问,例如使用 SpringSecurity 的 @Secured 注解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多