如何获取 Google Apps 用户的管理员状态
我有一个 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?
到目前为止,我发现检索管理员状态的唯一方法是上面的方法。以下是其文档:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 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
UserService
有一个名为isUserAdmin
的方法,用于确定当前用户是否是应用程序的管理员。http ://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/UserService.html#isUserAdmin()
不确定这是否是您要找的内容!
The
UserService
has a method calledisUserAdmin
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!