简体   繁体   English

GWT RequestFactory-1个EntityProxy的不同视图

[英]GWT RequestFactory - different views of 1 EntityProxy

I have one DocumentEntityProxy with the following methods : 我有一个具有以下方法的DocumentEntityProxy:

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

What I want to achieve is that if you are a standard user you can only use getAttribute1() and setAttribute1() if you are an admin user you can use all methods. 我要实现的是,如果您是标准用户,则只能使用getAttribute1()和setAttribute1();如果您是管理员用户,则可以使用所有方法。 In this example I have only three attributes and 2 different kind of users but in a real project there are a lot more of course. 在此示例中,我只有三个属性和两个不同类型的用户,但是在实际项目中,当然还有很多。

What is the best way to achieve that ? 实现此目标的最佳方法是什么?

Thanks in advance for your help. 在此先感谢您的帮助。

You could work with inhertance: 您可以继承:

class UserEntity {
  String getAttribute1() { }
  void setAttribute1(String s) { }
}

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

And the proxies: 和代理:

@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);
}

To secure access to the entity types you can have two finder methods (returning userEntity or adminEntity) and limit access to the methods in back-end, eg with SpringSecurity's @Secured annotation. 为了保护对实体类型的访问,您可以使用两种查找器方法(返回userEntity或adminEntity),并在后端限制对方法的访问,例如,使用SpringSecurity的@Secured批注。

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

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