2010-11-29 42 views
1

我有一个GWT应用程序,用户可以使用他们的Google Apps帐户(OpenID登录)登录。现在我希望能够知道,如果用户登录是该域的管理员。如何获取Google Apps用户的管理员身份

这已经可与下面的代码:

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

回答

3

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

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

周杰伦

+0

谢谢Jay!我现在认为,这是正确的路要走。尽管我仍然遇到Provisioning API的一些问题。 +1 – JochenJung 2010-12-06 09:06:21

-1

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

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

不知道这是你在找什么!

+0

想象的那么好,但没有。此方法返回代码正在运行的AppEngine用户的Admin状态。该代码始终在同一个AppEngine帐户中运行,但可以从该帐户部署到不同的Google Apps域。我想拥有这个Apps域的管理员状态。 – JochenJung 2010-11-29 14:40:45

相关问题