com.google.api.services.admin.directory.model.Users Java Examples

The following examples show how to use com.google.api.services.admin.directory.model.Users. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DirectoryFacade.java    From connector-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of all the e-mails in the domain.
 */
private ImmutableSet<String> listAllEmailsInDomain() throws IOException {
  Set<String> allUserIds = new HashSet<>();
  String nextPageToken = null;
  do {
    logger.fine("Fetching the next page of users...");
    Users users = directory
        .users()
        .list()
        .setMaxResults(NUM_USERS_PER_PAGE)
        .setDomain(domain)
        .setPageToken(nextPageToken)
        .execute();
    List<User> userList = users.getUsers();
    if (userList != null) {
      logger.log(Level.FINE, "Fetched {0} users.", userList.size());
      allUserIds.addAll(
          userList
              .stream()
              .map(User::getPrimaryEmail)
              .collect(Collectors.toSet()));
    }
    nextPageToken = users.getNextPageToken();
    logger.log(Level.FINE, "Next users page token is \"{0}\".", nextPageToken);
  } while (nextPageToken != null);
  logger.log(Level.FINE, "Fetched a total of {0} users.", allUserIds.size());
  return ImmutableSet.copyOf(allUserIds);
}
 
Example #2
Source File: GoogleProvisioningConnector.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected String createUser(ProvisioningEntity provisioningEntity)
        throws IdentityProvisioningException {
    boolean isDebugEnabled = log.isDebugEnabled();
    if (isDebugEnabled) {
        log.debug("Triggering create operation for Google Provisioning Connector");
    }

    User createdUser = null;
    try {
        User newUser = new User();

        newUser = buildGoogleUser(provisioningEntity);

        Directory.Users.Insert request = getDirectoryService().users().insert(newUser);
        createdUser = request.execute();

    } catch (IOException e) {
        throw new IdentityProvisioningException("Error while creating user : "
                                                + provisioningEntity.getEntityName(), e);
    }

    if (isDebugEnabled) {
        log.debug("Returning created user's email : " + createdUser.getPrimaryEmail());
    }

    if (log.isTraceEnabled()) {
        log.trace("Ending createUser() of " + GoogleProvisioningConnector.class);
    }
    return createdUser.getPrimaryEmail();
}
 
Example #3
Source File: GoogleProvisioningConnector.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Delete provisioned user from google account
 *
 * @param provisioningEntity
 * @throws IdentityProvisioningException
 */
protected void deleteUser(ProvisioningEntity provisioningEntity)
        throws IdentityProvisioningException {
    boolean isDebugEnabled = log.isDebugEnabled();
    if (isDebugEnabled) {
        log.debug("Triggering delete operation for Google Provisioning Connector");
    }

    ProvisionedIdentifier provisionedIdentifier = provisioningEntity.getIdentifier();
    if (provisionedIdentifier != null && provisionedIdentifier.getIdentifier() != null) {
        User deletingUser = new User();
        deletingUser.setPrimaryEmail(provisionedIdentifier.getIdentifier());

        Directory.Users.Delete request;
        try {
            request = getDirectoryService().users().delete(
                    provisionedIdentifier.getIdentifier());
            request.execute();

        } catch (IOException e) {
            if (((GoogleJsonResponseException) e).getStatusCode() == 404) {
                log.warn("Exception while deleting user from google. User may be already deleted from google");
                if (log.isDebugEnabled()) {
                    log.debug("Exception while deleting user from google. User may be already deleted from google", e);
                }
            } else {
                throw new IdentityProvisioningException("Error while deleting Google user : "
                                                        + provisioningEntity.getEntityName(), e);
            }
        }

        if (isDebugEnabled) {
            log.debug("Deleted user :" + provisioningEntity.getEntityName()
                      + " with the primaryEmail : " + provisionedIdentifier.getIdentifier());
        }
    } else {
        throw new IdentityProvisioningException(
                "Cannot delete Google user, provisionedIdentifier is invalide.");
    }

    if (log.isTraceEnabled()) {
        log.trace("Ending deleteUser() of " + GoogleProvisioningConnector.class);
    }
}