JochenJung
JochenJung

Reputation: 7213

How to get the admin status of a Google Apps user

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

Upvotes: 1

Views: 929

Answers (2)

Jay
Jay

Reputation: 156

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

Upvotes: 3

Amey
Amey

Reputation: 2214

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!

Upvotes: -1

Related Questions