Class GoogleAppsSdkUtils
java.lang.Object
edu.internet2.middleware.changelogconsumer.googleapps.GoogleAppsSdkUtils
GoogleAppsSdkUtils is a helper class that interfaces with the Google SDK Admin API and handles exponential back-off.
see https://developers.google.com/admin-sdk/directory/v1/guides/delegation
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.api.services.admin.directory.model.Group
addGroup
(com.google.api.services.admin.directory.Directory directoryClient, com.google.api.services.admin.directory.model.Group group) addGroup adds a group to Google.static com.google.api.services.admin.directory.model.Member
addGroupMember
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, com.google.api.services.admin.directory.model.Member member) addGroupMember add an additional member to a group.static com.google.api.services.admin.directory.model.User
addUser
(com.google.api.services.admin.directory.Directory directoryClient, com.google.api.services.admin.directory.model.User user) addUser creates a user to Google.static com.google.api.client.googleapis.auth.oauth2.GoogleCredential
getGoogleDirectoryCredential
(String serviceAccountEmail, String serviceAccountPKCS12FilePath, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory) getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.static com.google.api.client.googleapis.auth.oauth2.GoogleCredential
getGoogleDirectoryCredential
(String serviceAccountEmail, String serviceAccountPKCS12FilePath, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory, String[] directoryScopes) getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.static com.google.api.client.googleapis.auth.oauth2.GoogleCredential
getGoogleDirectoryCredential
(String serviceAccountEmail, PrivateKey serviceAccountPrivateKey, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory, String[] directoryScopes) getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.static com.google.api.client.googleapis.auth.oauth2.GoogleCredential
getGoogleGroupssettingsCredential
(String serviceAccountEmail, String serviceAccountPKCS12FilePath, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory) getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.static com.google.api.client.googleapis.auth.oauth2.GoogleCredential
getGoogleGroupssettingsCredential
(String serviceAccountEmail, PrivateKey serviceAccountPrivateKey, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory) getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.static void
removeGroup
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey) removeGroup removes a group from Google.static void
removeGroupMember
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, String memberKey) removeGroupMember removes a member of a group.static void
removeUser
(com.google.api.services.admin.directory.Directory directoryClient, String userKey) removeGroup removes a group from Google.static List<com.google.api.services.admin.directory.model.Group>
retrieveAllGroups
(com.google.api.services.admin.directory.Directory directoryClient) static List<com.google.api.services.admin.directory.model.User>
retrieveAllUsers
(com.google.api.services.admin.directory.Directory directoryClient) retrieveAllUsers returns all of the users from Google.static com.google.api.services.admin.directory.model.Group
retrieveGroup
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey) retrieveGroup returns a requested group.static com.google.api.services.admin.directory.model.Member
retrieveGroupMember
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, String userKey) retrieveGroupMember returns a requested group member.static List<com.google.api.services.admin.directory.model.Member>
retrieveGroupMembers
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey) retrieveGroupMembers returns a list of members of a group.static com.google.api.services.groupssettings.model.Groups
retrieveGroupSettings
(com.google.api.services.groupssettings.Groupssettings groupssettingClient, String groupKey) retrieveGroup returns a requested group.static com.google.api.services.admin.directory.model.User
retrieveUser
(com.google.api.services.admin.directory.Directory directoryClient, String userKey) static com.google.api.services.admin.directory.model.Group
updateGroup
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, com.google.api.services.admin.directory.model.Group group) addGroup adds a group to Google.static com.google.api.services.admin.directory.model.Member
updateGroupMember
(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, String userKey, com.google.api.services.admin.directory.model.Member member) addGroup adds a group to Google.static com.google.api.services.groupssettings.model.Groups
updateGroupSettings
(com.google.api.services.groupssettings.Groupssettings groupssettingsClient, String groupKey, com.google.api.services.groupssettings.model.Groups groupSettings) addGroup adds a group to Google.
-
Constructor Details
-
GoogleAppsSdkUtils
public GoogleAppsSdkUtils()
-
-
Method Details
-
getGoogleDirectoryCredential
public static com.google.api.client.googleapis.auth.oauth2.GoogleCredential getGoogleDirectoryCredential(String serviceAccountEmail, String serviceAccountPKCS12FilePath, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory) throws GeneralSecurityException, IOException getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.- Parameters:
serviceAccountEmail
- the application's account email address provided by GoogleserviceAccountPKCS12FilePath
- path of a private key (.p12) file provided by GoogleserviceAccountUser
- a impersonation user accounthttpTransport
- a httpTransport objectjsonFactory
- a jsonFactory object- Returns:
- a Google Credential
- Throws:
GeneralSecurityException
IOException
-
getGoogleDirectoryCredential
public static com.google.api.client.googleapis.auth.oauth2.GoogleCredential getGoogleDirectoryCredential(String serviceAccountEmail, String serviceAccountPKCS12FilePath, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory, String[] directoryScopes) throws GeneralSecurityException, IOException getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.- Parameters:
serviceAccountEmail
- the application's account email address provided by GoogleserviceAccountPKCS12FilePath
- path of a private key (.p12) file provided by GoogleserviceAccountUser
- a impersonation user accounthttpTransport
- a httpTransport objectjsonFactory
- a jsonFactory object- Returns:
- a Google Credential
- Throws:
GeneralSecurityException
IOException
-
getGoogleDirectoryCredential
public static com.google.api.client.googleapis.auth.oauth2.GoogleCredential getGoogleDirectoryCredential(String serviceAccountEmail, PrivateKey serviceAccountPrivateKey, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory, String[] directoryScopes) throws GeneralSecurityException, IOException getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.- Parameters:
serviceAccountEmail
- the application's account email address provided by GoogleserviceAccountPrivateKey
- private key provided by GoogleserviceAccountUser
- a impersonation user accounthttpTransport
- a httpTransport objectjsonFactory
- a jsonFactory object- Returns:
- a Google Credential
- Throws:
GeneralSecurityException
IOException
-
getGoogleGroupssettingsCredential
public static com.google.api.client.googleapis.auth.oauth2.GoogleCredential getGoogleGroupssettingsCredential(String serviceAccountEmail, String serviceAccountPKCS12FilePath, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory) throws GeneralSecurityException, IOException getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.- Parameters:
serviceAccountEmail
- the application's account email address provided by GoogleserviceAccountPKCS12FilePath
- path of a private key (.p12) file provided by GoogleserviceAccountUser
- a impersonation user accounthttpTransport
- a httpTransport objectjsonFactory
- a jsonFactory object- Returns:
- a Google Credential
- Throws:
GeneralSecurityException
IOException
-
getGoogleGroupssettingsCredential
public static com.google.api.client.googleapis.auth.oauth2.GoogleCredential getGoogleGroupssettingsCredential(String serviceAccountEmail, PrivateKey serviceAccountPrivateKey, String serviceAccountUser, com.google.api.client.http.HttpTransport httpTransport, com.google.api.client.json.JsonFactory jsonFactory) throws GeneralSecurityException, IOException getGoogleDirectoryCredential creates a credential object that authenticates the REST API calls.- Parameters:
serviceAccountEmail
- the application's account email address provided by GoogleserviceAccountPrivateKey
- private key provided by GoogleserviceAccountUser
- a impersonation user accounthttpTransport
- a httpTransport objectjsonFactory
- a jsonFactory object- Returns:
- a Google Credential
- Throws:
GeneralSecurityException
IOException
-
addUser
public static com.google.api.services.admin.directory.model.User addUser(com.google.api.services.admin.directory.Directory directoryClient, com.google.api.services.admin.directory.model.User user) throws IOException addUser creates a user to Google.- Parameters:
directoryClient
- a Directory (service) objectuser
- a populated User object- Returns:
- the new User object created/returned by Google
- Throws:
IOException
-
removeUser
public static void removeUser(com.google.api.services.admin.directory.Directory directoryClient, String userKey) throws IOException removeGroup removes a group from Google.- Parameters:
directoryClient
- a Directory (service) objectuserKey
- an identifier for a user (e-mail address is the most popular)- Throws:
IOException
-
addGroup
public static com.google.api.services.admin.directory.model.Group addGroup(com.google.api.services.admin.directory.Directory directoryClient, com.google.api.services.admin.directory.model.Group group) throws IOException addGroup adds a group to Google.- Parameters:
directoryClient
- a Directory clientgroup
- a populated Group object- Returns:
- the new Group object created/returned by Google
- Throws:
IOException
-
removeGroup
public static void removeGroup(com.google.api.services.admin.directory.Directory directoryClient, String groupKey) throws IOException removeGroup removes a group from Google.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a group (e-mail address is the most popular)- Throws:
IOException
-
updateGroup
public static com.google.api.services.admin.directory.model.Group updateGroup(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, com.google.api.services.admin.directory.model.Group group) throws IOException addGroup adds a group to Google.- Parameters:
directoryClient
- a Directory clientgroup
- a populated Group object- Returns:
- the new Group object created/returned by Google
- Throws:
IOException
-
updateGroupSettings
public static com.google.api.services.groupssettings.model.Groups updateGroupSettings(com.google.api.services.groupssettings.Groupssettings groupssettingsClient, String groupKey, com.google.api.services.groupssettings.model.Groups groupSettings) throws IOException addGroup adds a group to Google.- Parameters:
groupssettingsClient
- a Groupssettings clientgroupSettings
- a populated Groups (group settings) object- Returns:
- the new Group object created/returned by Google
- Throws:
IOException
-
retrieveAllUsers
public static List<com.google.api.services.admin.directory.model.User> retrieveAllUsers(com.google.api.services.admin.directory.Directory directoryClient) throws IOException retrieveAllUsers returns all of the users from Google.- Parameters:
directoryClient
- a Directory client- Returns:
- a list of all the users in the directory
- Throws:
IOException
-
retrieveUser
public static com.google.api.services.admin.directory.model.User retrieveUser(com.google.api.services.admin.directory.Directory directoryClient, String userKey) throws IOException - Parameters:
directoryClient
- a Directory (service) objectuserKey
- an identifier for a user (e-mail address is the most popular)- Returns:
- the User object returned by Google.
- Throws:
IOException
-
retrieveAllGroups
public static List<com.google.api.services.admin.directory.model.Group> retrieveAllGroups(com.google.api.services.admin.directory.Directory directoryClient) throws IOException - Parameters:
directoryClient
- a Directory client- Returns:
- a list of all the groups in the directory
- Throws:
IOException
-
retrieveGroup
public static com.google.api.services.admin.directory.model.Group retrieveGroup(com.google.api.services.admin.directory.Directory directoryClient, String groupKey) throws IOException retrieveGroup returns a requested group.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a group (e-mail address is the most popular)- Returns:
- the Group object from Google
- Throws:
IOException
-
retrieveGroupSettings
public static com.google.api.services.groupssettings.model.Groups retrieveGroupSettings(com.google.api.services.groupssettings.Groupssettings groupssettingClient, String groupKey) throws IOException retrieveGroup returns a requested group.- Parameters:
groupssettingClient
- a Groupssettings clientgroupKey
- an identifier for a group (e-mail address is the most popular)- Returns:
- the Groups object from Google
- Throws:
IOException
-
retrieveGroupMember
public static com.google.api.services.admin.directory.model.Member retrieveGroupMember(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, String userKey) throws IOException retrieveGroupMember returns a requested group member.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a group (e-mail address is the most popular)userKey
- an identifier for a group (e-mail address is the most popular)- Returns:
- the Group object from Google
- Throws:
IOException
-
updateGroupMember
public static com.google.api.services.admin.directory.model.Member updateGroupMember(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, String userKey, com.google.api.services.admin.directory.model.Member member) throws IOException addGroup adds a group to Google.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a group (e-mail address is the most popular)userKey
- an identifier for a user (e-mail address is the most popular)member
- a populated member object- Returns:
- the new Group object created/returned by Google
- Throws:
IOException
-
retrieveGroupMembers
public static List<com.google.api.services.admin.directory.model.Member> retrieveGroupMembers(com.google.api.services.admin.directory.Directory directoryClient, String groupKey) throws IOException retrieveGroupMembers returns a list of members of a group.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a group (e-mail address is the most popular)- Returns:
- a list of Members in the Group
- Throws:
IOException
-
addGroupMember
public static com.google.api.services.admin.directory.model.Member addGroupMember(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, com.google.api.services.admin.directory.model.Member member) throws IOException addGroupMember add an additional member to a group.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a group (e-mail address is the most popular)member
- a Member object- Returns:
- a Member object stored on Google.
- Throws:
IOException
-
removeGroupMember
public static void removeGroupMember(com.google.api.services.admin.directory.Directory directoryClient, String groupKey, String memberKey) throws IOException removeGroupMember removes a member of a group.- Parameters:
directoryClient
- a Directory clientgroupKey
- an identifier for a user (e-mail address is the most popular)memberKey
- an identifier for a user (e-mail address is the most popular)- Throws:
com.google.api.client.googleapis.json.GoogleJsonResponseException
IOException
-