Search in sources :

Example 1 with UserEmail

use of com.google.api.services.directory.model.UserEmail in project workbench by all-of-us.

the class DirectoryServiceImpl method addCustomSchemaAndEmails.

public static void addCustomSchemaAndEmails(User user, String username, String contactEmail) {
    // GSuite custom fields for Workbench user accounts.
    // See the Moodle integration doc (broad.io/aou-moodle) for more details, as this
    // was primarily set up for Moodle SSO integration.
    Map<String, Object> aouCustomFields = new HashMap<>();
    // The value of this field must match one of the allowed values in the Moodle installation.
    // Since this value is unlikely to ever change, we use a hard-coded constant rather than an env
    // variable.
    aouCustomFields.put(GSUITE_FIELD_INSTITUTION, INSTITUTION_FIELD_VALUE);
    if (contactEmail != null) {
        // This gives us a structured place to store researchers' contact email addresses, in
        // case we want to pass it to other systems (e.g. Zendesk or Moodle) via SAML mapped fields.
        aouCustomFields.put(GSUITE_FIELD_CONTACT_EMAIL, contactEmail);
    }
    // In addition to the custom schema value, we store each user's contact email as a secondary
    // email address with type "home". This makes it show up nicely in GSuite admin as the
    // user's "Secondary email".
    List<UserEmail> emails = Lists.newArrayList(new UserEmail().setType("work").setAddress(username).setPrimary(true));
    if (contactEmail != null) {
        emails.add(new UserEmail().setType("home").setAddress(contactEmail));
    }
    user.setEmails(emails).setRecoveryEmail(contactEmail).setCustomSchemas(Collections.singletonMap(GSUITE_AOU_SCHEMA_NAME, aouCustomFields));
}
Also used : HashMap(java.util.HashMap) UserEmail(com.google.api.services.directory.model.UserEmail)

Aggregations

UserEmail (com.google.api.services.directory.model.UserEmail)1 HashMap (java.util.HashMap)1