在基于 GWT 的应用程序中添加访问控制

发布于 2024-09-25 11:59:58 字数 215 浏览 0 评论 0原文

我有一个基于 GWT 的应用程序。我想为其添加访问控制。有没有办法为 GWT 组件添加自定义访问控制?

我关于添加访问控制/权限的想法如下。

  1. 将访问控制注释(如果存在)添加到我需要添加访问控制的类(GWT 组件)。
  2. 当渲染此组件时,将调用检查访问控制规则的自定义方法,并根据其结果渲染组件。

关于如何实现这一目标的任何想法。

I have a GWT based application. I want to add access control to it. Is there a way to add custom access control for GWT components?

My idea about adding access control/permissions would be as following.

  1. Add access control annotation (if there exists one) to the class (GWT component) for which I need to add access control.
  2. When this component gets rendered, my custom method which checks for access control rules get called and depending on its results the component gets rendered.

Any ideas of how this can be achieved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放手` 2024-10-02 11:59:58

在 GWT 应用程序中,我以两种方式完成访问控制,两者都假设在服务器上强制执行访问控制 - 在每个 AJAX (GWT RPC) 调用中。 JavaScript 端本质上是不安全的,因此任何控件都是毫无意义的。

根据我需要的访问控制的细粒度,我可以使用保护 GWT RPC 端点的 servlet 容器基于 URL 的控制。即

/public/gwt.rpc.endpoint
/private/gwt.rpc.endpoint

使用 bog 标准 web.xml 或 spring security 保护私有的。然而,这导致我在启动 GWT 应用程序之前以“正常”基于表单的方式处理登录。

一种更细粒度的方法是在每个 GWT RPC 公开方法上使用异常:

interface MyService extends RemoteService {
  SomeData getPublicData();
  SomeSecret getPrivateData() throws AccessDeniedException; 
  Result login(String username, String password);
}

interface MyServiceAsync {
  void getPublicData(AsyncCallback<SomeData> callback);
  void getPrivateData(AsyncCallback<SomeSecret> callback);
  void login(String username, String password, AsyncCallback<Result> callback);
}

通过使 AccessDeniedException RPC 可序列化,我将在 AsyncCallback 中收到该异常 - 这使得可以在 GWT 应用程序内抛出登录对话框。

然而,实际的登录调用和服务器端会话处理我完全手动完成,不依赖任何框架(尽管您可以使用 Spring Security 来完成)。

In a GWT app I've done access control two ways, both assume that access control is enforced on the server - in every AJAX (GWT RPC) call. The javascript side is inherently unsafe, so any controls there would be pointless.

Depending on how fine grained access control I've needed, I've either used URL-based control by the servlet container protecting the GWT RPC end point. I.e.

/public/gwt.rpc.endpoint
/private/gwt.rpc.endpoint

Protect the private one using either bog standard web.xml, or spring security. However this then led me to handle logins the "normal" form-based way before launching the GWT application.

A more fine grained approach has been to use an exception on every GWT RPC exposed method:

interface MyService extends RemoteService {
  SomeData getPublicData();
  SomeSecret getPrivateData() throws AccessDeniedException; 
  Result login(String username, String password);
}

interface MyServiceAsync {
  void getPublicData(AsyncCallback<SomeData> callback);
  void getPrivateData(AsyncCallback<SomeSecret> callback);
  void login(String username, String password, AsyncCallback<Result> callback);
}

By making AccessDeniedException RPC serializable, I will receive that exception in the AsyncCallback - this makes it possible to throw up a login-dialog inside the GWT app.

However the actual login call and server side session handling I've then done completely manually not relying on any framework for that (though you could do it with Spring Security).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文