protected void configureServlets()

in src/main/java/com/googlesource/gerrit/plugins/oauth/HttpModule.java [38:140]


  protected void configureServlets() {
    PluginConfig cfg =
        cfgFactory.getFromGerritConfig(pluginName + GoogleOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(GoogleOAuthService.CONFIG_SUFFIX))
          .to(GoogleOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + GitHubOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(GitHubOAuthService.CONFIG_SUFFIX))
          .to(GitHubOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + BitbucketOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(BitbucketOAuthService.CONFIG_SUFFIX))
          .to(BitbucketOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + CasOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(CasOAuthService.CONFIG_SUFFIX))
          .to(CasOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + FacebookOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(FacebookOAuthService.CONFIG_SUFFIX))
          .to(FacebookOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + GitLabOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(GitLabOAuthService.CONFIG_SUFFIX))
          .to(GitLabOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + LemonLDAPOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(LemonLDAPOAuthService.CONFIG_SUFFIX))
          .to(LemonLDAPOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + DexOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(DexOAuthService.CONFIG_SUFFIX))
          .to(DexOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + KeycloakOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(KeycloakOAuthService.CONFIG_SUFFIX))
          .to(KeycloakOAuthService.class);
    }

    boolean office365LegacyProviderBound = false;
    cfg =
        cfgFactory.getFromGerritConfig(
            pluginName + AzureActiveDirectoryService.CONFIG_SUFFIX_LEGACY);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      office365LegacyProviderBound = true;
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(AzureActiveDirectoryService.CONFIG_SUFFIX))
          .to(AzureActiveDirectoryService.class);
    }
    cfg = cfgFactory.getFromGerritConfig(pluginName + AzureActiveDirectoryService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      // ?: Check if the legacy Office365 is already bound, we can only have one of these bound at
      // one time
      if (office365LegacyProviderBound) {
        // -> Yes, the legacy Office365 is already bound and we are trying to bind the
        // AzureActiveDirectoryService.CONFIG_SUFFIX at the same time.
        throw new ProvisionException("Legacy Office365 OAuth provider is already bound!");
      }
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(AzureActiveDirectoryService.CONFIG_SUFFIX))
          .to(AzureActiveDirectoryService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + AirVantageOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(AirVantageOAuthService.CONFIG_SUFFIX))
          .to(AirVantageOAuthService.class);
    }

    cfg = cfgFactory.getFromGerritConfig(pluginName + PhabricatorOAuthService.CONFIG_SUFFIX);
    if (cfg.getString(InitOAuth.CLIENT_ID) != null) {
      bind(OAuthServiceProvider.class)
          .annotatedWith(Exports.named(PhabricatorOAuthService.CONFIG_SUFFIX))
          .to(PhabricatorOAuthService.class);
    }
  }