我想将 ACL 应用于通过我的请求工厂的所有请求。因此,我重写了 RequestFactoryServlet 及其 doPost()-Methode。现在我可以从 session 中获取用户,检查他是否登录等等。 但我还想检查他的权限,只允许用户调用特定的方法。例如,仅允许管理员用户调用将数据写入数据库的方法。
现在我的问题:
- 重写 ReqeustFactoryServlet 的方法是否正确?
- 如何查明在 RequestFactoryServerlet 中调用了哪个方法?有一个方法可以从请求中读取某些内容:
String jsonRequestString = RPCServletUtils.readContent(request, JSON_CONTENT_TYPE, JSON_CHARSET);
但它只提供一个非常神秘的字符串。
我的代码如下所示:
public class MyRequestFactoryServlet extends RequestFactoryServlet {
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
HttpSession session = getThreadLocalRequest().getSession();
User user = (User)session.getAttribute("user");
// check rights for user and only allow some methods
super.doPost(request, response);
}
}
最佳答案
解决方案是使用您的 ServiceLayerDecorator
创建标准 RequestFactoryServlet
。
在您的ServiceLayerDecorator
中,您可以重写invoke
方法。
但是我更愿意直接在业务对象中执行 ACL。
关于java - GWT 请求工厂的 ACL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17027662/