By default, Google Cloud Search only recognizes Google identities in Google Cloud Directory. Use identity connectors to sync enterprise identities to the Google identities Cloud Search uses.
Google provides these options for developing identity connectors:
The Identity Connector SDK: Best for Java programmers. The SDK is a wrapper around the REST API that lets you quickly create connectors. To use the SDK, see Create an identity connector using the Identity Connector SDK.
A low-level REST API and API libraries: Best for non-Java programmers. To create an identity connector using the REST API, see Directory API: User Accounts for mapping users and Google Cloud Identity documentation for mapping groups.
Create an identity connector using the Identity Connector SDK
A typical identity connector performs these tasks:
- Configures the connector.
- Retrieves users from your identity system and sends them to Google.
- Retrieves groups from your identity system and sends them to Google.
Set up dependencies
Include these dependencies in your build file.
Maven
<dependency>
<groupId>com.google.enterprise.cloudsearch</groupId>
<artifactId>google-cloudsearch-identity-connector-sdk</artifactId>
<version>v1-0.0.3</version>
</dependency>
Gradle
compile group: 'com.google.enterprise.cloudsearch',
name: 'google-cloudsearch-identity-connector-sdk',
version: 'v1-0.0.3'
Create your connector configuration
Every connector uses a configuration file for parameters like your repository ID.
Define parameters as key-value pairs, such as
api.sourceId=1234567890abcdef.
The Google Cloud Search SDK includes Google-supplied parameters for all connectors. You must declare the following in your configuration file:
- Content connector: Declare
api.sourceIdandapi.serviceAccountPrivateKeyFile. These identify your repository and the private key needed for access.
- Identity connector: Declare
api.identitySourceIdto identify your external identity source. For user syncing, also declareapi.customerId(the unique ID for your Google Workspace account).
Declare other Google-supplied parameters only to override their default values. For details on generating IDs and keys, see Google-supplied parameters.
You can also define repository-specific parameters in your configuration file.
Pass the configuration file to the connector
Set the config system property to pass the configuration file. Use the -D
argument when starting the connector. For example:
java -classpath myconnector.jar -Dconfig=MyConfig.properties MyConnector
If you omit this argument, the SDK attempts to use a file named
connector-config.properties in the local directory.
Create a full sync identity connector using a template class
The SDK includes a FullSyncIdentityConnector template to sync all users and
groups from your repository. This section explains how to use it.
This section refers to code from the IdentityConnectorSample.java sample,
which reads identities from CSV files.
Implement the connector entry point
The entry point is the main() method. It creates an
Application
instance and calls
start()
to run the connector.
Before calling application.start(), use
IdentityApplication.Builder
to instantiate the FullSyncIdentityConnector template.
The SDK calls initConfig() after your main() method calls
Application.build(). The initConfig() method:
- Ensures the
Configurationis not already initialized. - Initializes the
Configurationobject with Google-supplied key-value pairs.
Implement the Repository interface
The Repository object syncs repository identities to Google identities. When
using a template, you only need to override certain methods. For
FullSyncIdentityConnector, override these methods:
init(): For setup and initialization.listUsers(): To sync all users.listGroups(): To sync all groups.- (Optional)
close(): For cleanup during shutdown.
Get custom configuration parameters
Retrieve custom parameters from the Configuration object, typically in the
init() method. The following snippet shows how to retrieve CSV paths:
To get and parse a parameter containing several values, use one of the
Configuration class's type parsers to parse the data into discrete chunks.
The following snippet, from the tutorial connector, uses the
getMultiValue
method to get a list of GitHub repository names:
Get the mapping for all users
Override listUsers() to retrieve user mappings. This method accepts a
checkpoint to resume syncing if interrupted. For each user:
- Get the mapping between the Google identity and the external identity.
- Package the pair into the iterator returned by
listUsers().
Get a user mapping
This snippet demonstrates retrieving identity mappings from a CSV file:
Package a user mapping into an iterator
The listUsers() method returns a
CheckpointCloseableIterable
of
IdentityUser
objects.
Get a group
Override listGroups() to retrieve groups and their members. This method
accepts a checkpoint. For each group:
- Get the group and its members.
- Package them into the iterator returned by
listGroups().
Get the group identity
This snippet demonstrates retrieving groups and members from a CSV file:
Package the group and members into an iterator
The listGroups() method returns a CheckpointCloseableIterable of
IdentityGroup
objects.
Next Steps
- (Optional) Implement
close()to release resources. - (Optional) Create a content connector.