如何获取 Google Apps 用户的管理员状态

发布于 2024-10-04 18:45:31 字数 1217 浏览 11 评论 0原文

我有一个 GWT 应用程序,用户可以使用其 Google Apps 帐户登录(OpenID 登录)。现在我想知道登录的用户是否是该域的管理员。

这已经适用于以下代码:

private boolean isAdmin (String username) {
  boolean ret= false;

  if (username.indexOf ("@") > 0) username= username.substring (0, username
    .indexOf ("@"));

  AppsForYourDomainClient client= null;
  try {
    client= new AppsForYourDomainClient ("[email protected]", "password",
      "orgapage.de");

    UserEntry user= client.retrieveUser (username);
    if (user.getLogin ().getAdmin ().equals (Boolean.TRUE)) ret= true;
    else ret= false;
  }
  catch (Exception ex2) {
    log.severe (ex2.getMessage ());
    ex2.printStackTrace ();
  }

  return ret;
}

问题是,我必须输入该域管理员的用户名和密码才能检查当前登录的用户。

有没有一种方法可以在不知道管理员密码的情况下执行此操作?也许使用 OAuth?

到目前为止,我发现检索管理员状态的唯一方法是上面的方法。以下是其文档:

http://code.google.com/ googleapps/domain/gdata_provisioning_api_v2.0_reference_java.html#Retrieve_Account_Example

I have a GWT application, where users can sign on with their Google Apps account (OpenID Login). Now I want to be able to know, if the user signed on is an admin for this domain.

This already works with the following code:

private boolean isAdmin (String username) {
  boolean ret= false;

  if (username.indexOf ("@") > 0) username= username.substring (0, username
    .indexOf ("@"));

  AppsForYourDomainClient client= null;
  try {
    client= new AppsForYourDomainClient ("[email protected]", "password",
      "orgapage.de");

    UserEntry user= client.retrieveUser (username);
    if (user.getLogin ().getAdmin ().equals (Boolean.TRUE)) ret= true;
    else ret= false;
  }
  catch (Exception ex2) {
    log.severe (ex2.getMessage ());
    ex2.printStackTrace ();
  }

  return ret;
}

The problem is, that I have to enter the username and password of an admin of this domain to check for the current logged in user.

Is there a way to do this without having to know the password of an admin? Maybe with OAuth?

The only way to retrieve the admin status, I found so far, is the one above. Here is the documentation of it:

http://code.google.com/googleapps/domain/gdata_provisioning_api_v2.0_reference_java.html#Retrieve_Account_Example

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

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

发布评论

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

评论(2

萌能量女王 2024-10-11 18:45:31

如果您使用 Google Apps Marketplace,则可以通过两足 OAuth 请求对 Google Apps 域的只读配置 API 访问权限。这将允许您使用上面的示例代码,而不需要域管理员用户名/密码。请参阅以下文档:

http://code.google.com/googleapps/marketplace/data_access。 html
http://code.google.com/googleapps/marketplace/manifest.html

杰伊

If you use the Google Apps Marketplace, you can request read-only Provisioning API access to the Google Apps domain via Two-Legged OAuth. This would allow you to use your sample code above instead of needing a domain admin username/pass. See the docs at:

http://code.google.com/googleapps/marketplace/data_access.html
http://code.google.com/googleapps/marketplace/manifest.html

Jay

以可爱出名 2024-10-11 18:45:31

UserService 有一个名为 isUserAdmin 的方法,用于确定当前用户是否是应用程序的管理员。

http ://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/UserService.html#isUserAdmin()

不确定这是否是您要找的内容!

The UserService has a method called isUserAdmin for determining if the current user is an admin for the application.

http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/UserService.html#isUserAdmin()

Not sure if this is what you are looking for!

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