@Override
  public void setAdditionalDefaultGroups(Set<String> groupNames) {
    try {
      if (groupNames == null) return;

      final Map<String, Role> nameToRole =
          Maps.uniqueIndex(roleService.loadAll(), Roles.roleToNameFunction());
      final List<String> groupIds =
          Lists.newArrayList(
              Collections2.transform(
                  groupNames,
                  new Function<String, String>() {
                    @Nullable
                    @Override
                    public String apply(@Nullable String groupName) {
                      if (groupName == null || !nameToRole.containsKey(groupName)) {
                        return null;
                      }
                      return nameToRole.get(groupName).getId();
                    }
                  }));
      fields.put(ADDITIONAL_DEFAULT_GROUPS, groupIds);
    } catch (NotFoundException e) {
      LOG.error("Unable to convert group names to ids", e);
      throw new IllegalStateException("Unable to convert group names to ids", e);
    }
  }
  @Override
  public void setGroupMapping(Map<String, String> mapping) {
    Map<String, String> internal;
    if (mapping == null) {
      internal = Collections.emptyMap();
    } else {
      // we store ids internally but external users use the group names
      try {
        final Map<String, Role> nameToRole =
            Maps.uniqueIndex(roleService.loadAll(), Roles.roleToNameFunction());

        internal =
            Maps.newHashMap(
                Maps.transformValues(
                    mapping,
                    new Function<String, String>() {
                      @Nullable
                      @Override
                      public String apply(@Nullable String groupName) {
                        if (groupName == null || !nameToRole.containsKey(groupName)) {
                          return null;
                        }
                        return nameToRole.get(groupName).getId();
                      }
                    }));
      } catch (NotFoundException e) {
        LOG.error("Unable to convert group names to ids", e);
        throw new IllegalStateException("Unable to convert group names to ids", e);
      }
    }

    fields.put(GROUP_MAPPING, internal);
  }