如何在 Wicket 上使用 Google App Engine 安全性?

发布于 2024-11-25 09:35:02 字数 503 浏览 0 评论 0原文

我正在开发 Wicket GAE 应用程序,一切看起来都很好。但我有一个问题,如何正确地将 GAE 的安全性与 Wicket 集成?

我有两个与安全相关的用例:

  1. 允许经过身份验证的用户的页面:只有登录的用户才能看到它们 - 其他用户必须重定向到 Google 的身份验证(并且在成功后返回到同一页面)
  2. 允许某些用户执行操作的页面:任何用户都可以看到该页面,但只有特殊用户可以运行操作(例如:任何人都可以阅读新闻,但只有特定帖子的作者可以编辑)。

我想我可以通过“隐藏”表单和/或操作来完成第二个(欢迎其他建议)。第一个我找不到该怎么做。

GAE 指示使用基于 servlet 的身份验证或某些 API 调用,通过返回链接重定向到 Google 的身份验证。我猜这适用于 Wicket 的重定向,但它不应该是 401 重定向吗?而且,更重要的是:如何测试它?

如果我使用 Wicket 的安全性,我如何定义用户可以访问哪些页面以及如何发送到 Google 的身份验证?

I'm developing an Wicket GAE application, and everything looks fine. But I have one question, how to correctly integrate GAE's security with Wicket?

I have two security-related use cases:

  1. Pages allowed for authenticated users: only logged user can see them - other users must be redirected to Google's authentication (and, after success, get back to the same page)
  2. Pages with actions allowed for some users: any user can see the page, but only special users can run actions (ex: anyone can read the news, but only the author of the specific post can edit).

The second one I guess I can do by "hiding" the forms and/or actions (other suggestions are welcome). The first one I could not find how to do.

GAE instructs to use servlet-based authentication or some API calls to redirect to Google's auth with a return link. I guess this works with Wicket's redirection, but shouldn't it be a 401 redirect? And, more important: how to test it?

If I use Wicket's security, how can I define which pages user can access and how to send to Google's auth?

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

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

发布评论

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

评论(1

高冷爸爸 2024-12-02 09:35:02

visural-wicket 库的安全功能(完全公开 - 这是我的开源项目)可能允许您正在寻找的集成。

这篇博文解释了基本机制 -

http://www. richardnichols.net/2011/09/securing-wicket-with-visural-wicket/

您可以使用 Google 的 UserService 返回包装 Google 用户的 IClient 来与 Google 的安全性集成 -

public class GoogleUser implements IClient<String> {
    private final User user;
    private final boolean admin;
    public GoogleUser(User user, boolean admin) {
        this.user = user;
    }    
    public String getId() {
        return user.getUserId();
    }
    public User getUser() {
        return user;
    }
    public boolean isAdmin() {
        return admin;
    }
}

public class MyApp extends Application {

    public void init() {
        // ...
        getSecuritySettings().setAuthorizationStrategy(new com.visural.wicket.security.AuthorizationStrategy(new IClientProvider() {
            public IClient getCurrentClient() {
                UserService s = UserServiceFactory.getUserService();
                return new GoogleUser(s.getCurrentUser(), s.isUserAdmin());
            }
        }));
        // ...
    }
}

您然后可以在您的页面或组件中实现安全性,如下所示 -

public class MyPage extends WebPage implements ISecureRenderInstance {
    // ...

    public IPrivilege getRenderPrivilege() {
       return new IPrivilege<GoogleUser>() {
           public boolean isGrantedToClient(GoogleUser client) {
               return client != null && client.isAdmin()
           }
       };
       // instead of returning a anonymous class like this, you could also
       // package up common privileges into a singleton instance,
       // e.g. return Privilege.ADMIN;
    }
}

The security features of the visural-wicket library (full disclosure - this is my open source project) may allow the integration you're looking for.

This blog post explains the basic mechanism -

http://www.richardnichols.net/2011/09/securing-wicket-with-visural-wicket/

You can integrate with Google's security by using their UserService to return an IClient wrapping the google user -

public class GoogleUser implements IClient<String> {
    private final User user;
    private final boolean admin;
    public GoogleUser(User user, boolean admin) {
        this.user = user;
    }    
    public String getId() {
        return user.getUserId();
    }
    public User getUser() {
        return user;
    }
    public boolean isAdmin() {
        return admin;
    }
}

public class MyApp extends Application {

    public void init() {
        // ...
        getSecuritySettings().setAuthorizationStrategy(new com.visural.wicket.security.AuthorizationStrategy(new IClientProvider() {
            public IClient getCurrentClient() {
                UserService s = UserServiceFactory.getUserService();
                return new GoogleUser(s.getCurrentUser(), s.isUserAdmin());
            }
        }));
        // ...
    }
}

You can then implement security in your pages or components like this -

public class MyPage extends WebPage implements ISecureRenderInstance {
    // ...

    public IPrivilege getRenderPrivilege() {
       return new IPrivilege<GoogleUser>() {
           public boolean isGrantedToClient(GoogleUser client) {
               return client != null && client.isAdmin()
           }
       };
       // instead of returning a anonymous class like this, you could also
       // package up common privileges into a singleton instance,
       // e.g. return Privilege.ADMIN;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文