| 
									
										
										
										
											2021-08-20 10:58:07 -07:00
										 |  |  | package auth;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | import static auth.AuthUtils.*;
 | 
					
						
							|  |  |  | import static utils.ConfigUtil.*;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 18:56:32 -07:00
										 |  |  | import auth.sso.SsoManager;
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | import client.AuthServiceClient;
 | 
					
						
							|  |  |  | import com.datahub.authentication.Actor;
 | 
					
						
							|  |  |  | import com.datahub.authentication.ActorType;
 | 
					
						
							| 
									
										
										
										
											2022-10-06 18:56:32 -07:00
										 |  |  | import com.datahub.authentication.Authentication;
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  | import com.datahub.plugins.auth.authorization.Authorizer;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | import com.google.inject.AbstractModule;
 | 
					
						
							|  |  |  | import com.google.inject.Provides;
 | 
					
						
							|  |  |  | import com.google.inject.Singleton;
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  | import com.google.inject.name.Named;
 | 
					
						
							| 
									
										
										
										
											2024-11-05 09:42:21 -06:00
										 |  |  | import com.linkedin.entity.client.EntityClientConfig;
 | 
					
						
							| 
									
										
										
										
											2023-09-21 22:00:14 -05:00
										 |  |  | import com.linkedin.entity.client.SystemEntityClient;
 | 
					
						
							|  |  |  | import com.linkedin.entity.client.SystemRestliEntityClient;
 | 
					
						
							| 
									
										
										
										
											2024-04-16 10:12:48 -05:00
										 |  |  | import com.linkedin.metadata.models.registry.EmptyEntityRegistry;
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | import com.linkedin.metadata.restli.DefaultRestliClientFactory;
 | 
					
						
							| 
									
										
										
										
											2022-12-26 10:09:08 -06:00
										 |  |  | import com.linkedin.parseq.retry.backoff.ExponentialBackoff;
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | import com.linkedin.util.Configuration;
 | 
					
						
							| 
									
										
										
										
											2023-09-21 22:00:14 -05:00
										 |  |  | import config.ConfigurationProvider;
 | 
					
						
							| 
									
										
										
										
											2022-10-06 18:56:32 -07:00
										 |  |  | import controllers.SsoCallbackController;
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  | import io.datahubproject.metadata.context.ActorContext;
 | 
					
						
							| 
									
										
										
										
											2024-09-11 15:06:24 -05:00
										 |  |  | import io.datahubproject.metadata.context.AuthorizationContext;
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  | import io.datahubproject.metadata.context.EntityRegistryContext;
 | 
					
						
							|  |  |  | import io.datahubproject.metadata.context.OperationContext;
 | 
					
						
							|  |  |  | import io.datahubproject.metadata.context.OperationContextConfig;
 | 
					
						
							| 
									
										
										
										
											2024-12-18 12:45:38 -06:00
										 |  |  | import io.datahubproject.metadata.context.RetrieverContext;
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  | import io.datahubproject.metadata.context.SearchContext;
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  | import io.datahubproject.metadata.context.ValidationContext;
 | 
					
						
							|  |  |  | import java.nio.charset.StandardCharsets;
 | 
					
						
							|  |  |  | import java.util.Collections;
 | 
					
						
							|  |  |  | import javax.annotation.Nonnull;
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  | import lombok.extern.slf4j.Slf4j;
 | 
					
						
							| 
									
										
										
										
											2022-03-15 17:41:08 -07:00
										 |  |  | import org.apache.commons.codec.digest.DigestUtils;
 | 
					
						
							| 
									
										
										
										
											2022-10-06 18:56:32 -07:00
										 |  |  | import org.apache.http.impl.client.CloseableHttpClient;
 | 
					
						
							|  |  |  | import org.apache.http.impl.client.HttpClients;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | import org.pac4j.core.config.Config;
 | 
					
						
							|  |  |  | import org.pac4j.core.context.session.SessionStore;
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  | import org.pac4j.core.profile.ProfileManager;
 | 
					
						
							|  |  |  | import org.pac4j.core.util.serializer.JavaSerializer;
 | 
					
						
							| 
									
										
										
										
											2021-08-16 12:19:44 +07:00
										 |  |  | import org.pac4j.play.LogoutController;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | import org.pac4j.play.http.PlayHttpActionAdapter;
 | 
					
						
							| 
									
										
										
										
											2022-07-15 00:52:51 +08:00
										 |  |  | import org.pac4j.play.store.PlayCacheSessionStore;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | import org.pac4j.play.store.PlayCookieSessionStore;
 | 
					
						
							| 
									
										
										
										
											2022-03-08 14:27:19 -08:00
										 |  |  | import org.pac4j.play.store.ShiroAesDataEncrypter;
 | 
					
						
							| 
									
										
										
										
											2023-09-21 22:00:14 -05:00
										 |  |  | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | import play.Environment;
 | 
					
						
							| 
									
										
										
										
											2022-07-15 00:52:51 +08:00
										 |  |  | import play.cache.SyncCacheApi;
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | import utils.ConfigUtil;
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | /** Responsible for configuring, validating, and providing authentication related components. */
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  | @Slf4j
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | public class AuthModule extends AbstractModule {
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Pac4j Stores Session State in a browser-side cookie in encrypted fashion. This configuration
 | 
					
						
							|  |  |  |    * value provides a stable encryption base from which to derive the encryption key.
 | 
					
						
							|  |  |  |    *
 | 
					
						
							|  |  |  |    * <p>We hash this value (SHA256), then take the first 16 bytes as the AES key.
 | 
					
						
							|  |  |  |    */
 | 
					
						
							|  |  |  |   private static final String PAC4J_AES_KEY_BASE_CONF = "play.http.secret.key";
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   private static final String PAC4J_SESSIONSTORE_PROVIDER_CONF = "pac4j.sessionStore.provider";
 | 
					
						
							|  |  |  |   private static final String ENTITY_CLIENT_RETRY_INTERVAL = "entityClient.retryInterval";
 | 
					
						
							|  |  |  |   private static final String ENTITY_CLIENT_NUM_RETRIES = "entityClient.numRetries";
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |   private static final String ENTITY_CLIENT_RESTLI_GET_BATCH_SIZE =
 | 
					
						
							|  |  |  |       "entityClient.restli.get.batchSize";
 | 
					
						
							|  |  |  |   private static final String ENTITY_CLIENT_RESTLI_GET_BATCH_CONCURRENCY =
 | 
					
						
							|  |  |  |       "entityClient.restli.get.batchConcurrency";
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |   private static final String GET_SSO_SETTINGS_ENDPOINT = "auth/getSsoSettings";
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |   private final com.typesafe.config.Config configs;
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   public AuthModule(final Environment environment, final com.typesafe.config.Config configs) {
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     this.configs = configs;
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Override
 | 
					
						
							|  |  |  |   protected void configure() {
 | 
					
						
							| 
									
										
										
										
											2022-03-08 14:27:19 -08:00
										 |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |      * In Pac4J, you are given the option to store the profiles of authenticated users in either (i)
 | 
					
						
							|  |  |  |      * PlayCacheSessionStore - saves your data in the Play cache or (ii) PlayCookieSessionStore
 | 
					
						
							|  |  |  |      * saves your data in the Play session cookie However there is problem
 | 
					
						
							|  |  |  |      * (https://github.com/datahub-project/datahub/issues/4448) observed when storing the Pac4j
 | 
					
						
							|  |  |  |      * profile in cookie. Whenever the profile returned by Pac4j is greater than 4096 characters,
 | 
					
						
							|  |  |  |      * the response will be rejected by the browser. Default to PlayCacheCookieStore so that
 | 
					
						
							|  |  |  |      * datahub-frontend container remains as a stateless service
 | 
					
						
							| 
									
										
										
										
											2022-03-08 14:27:19 -08:00
										 |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     String sessionStoreProvider = configs.getString(PAC4J_SESSIONSTORE_PROVIDER_CONF);
 | 
					
						
							| 
									
										
										
										
											2022-07-15 00:52:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     if (sessionStoreProvider.equals("PlayCacheSessionStore")) {
 | 
					
						
							|  |  |  |       final PlayCacheSessionStore playCacheSessionStore =
 | 
					
						
							|  |  |  |           new PlayCacheSessionStore(getProvider(SyncCacheApi.class));
 | 
					
						
							|  |  |  |       bind(SessionStore.class).toInstance(playCacheSessionStore);
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |       bind(PlayCacheSessionStore.class).toInstance(playCacheSessionStore);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     } else {
 | 
					
						
							|  |  |  |       PlayCookieSessionStore playCacheCookieStore;
 | 
					
						
							|  |  |  |       try {
 | 
					
						
							|  |  |  |         // To generate a valid encryption key from an input value, we first
 | 
					
						
							|  |  |  |         // hash the input to generate a fixed-length string. Then, we convert
 | 
					
						
							|  |  |  |         // it to hex and slice the first 16 bytes, because AES key length must strictly
 | 
					
						
							|  |  |  |         // have a specific length.
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |         final String aesKeyBase = configs.getString(PAC4J_AES_KEY_BASE_CONF);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |         final String aesKeyHash =
 | 
					
						
							|  |  |  |             DigestUtils.sha256Hex(aesKeyBase.getBytes(StandardCharsets.UTF_8));
 | 
					
						
							|  |  |  |         final String aesEncryptionKey = aesKeyHash.substring(0, 16);
 | 
					
						
							|  |  |  |         playCacheCookieStore =
 | 
					
						
							|  |  |  |             new PlayCookieSessionStore(new ShiroAesDataEncrypter(aesEncryptionKey.getBytes()));
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |         playCacheCookieStore.setSerializer(new JavaSerializer());
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |       } catch (Exception e) {
 | 
					
						
							|  |  |  |         throw new RuntimeException("Failed to instantiate Pac4j cookie session store!", e);
 | 
					
						
							|  |  |  |       }
 | 
					
						
							|  |  |  |       bind(SessionStore.class).toInstance(playCacheCookieStore);
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |       bind(PlayCookieSessionStore.class).toInstance(playCacheCookieStore);
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     try {
 | 
					
						
							|  |  |  |       bind(SsoCallbackController.class)
 | 
					
						
							|  |  |  |           .toConstructor(
 | 
					
						
							|  |  |  |               SsoCallbackController.class.getConstructor(
 | 
					
						
							|  |  |  |                   SsoManager.class,
 | 
					
						
							| 
									
										
										
										
											2024-04-16 10:12:48 -05:00
										 |  |  |                   OperationContext.class,
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |                   SystemEntityClient.class,
 | 
					
						
							|  |  |  |                   AuthServiceClient.class,
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |                   org.pac4j.core.config.Config.class,
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |                   com.typesafe.config.Config.class));
 | 
					
						
							|  |  |  |     } catch (NoSuchMethodException | SecurityException e) {
 | 
					
						
							|  |  |  |       throw new RuntimeException(
 | 
					
						
							|  |  |  |           "Failed to bind to SsoCallbackController. Cannot find constructor", e);
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     // logout
 | 
					
						
							|  |  |  |     final LogoutController logoutController = new LogoutController();
 | 
					
						
							|  |  |  |     logoutController.setDefaultUrl("/");
 | 
					
						
							|  |  |  |     bind(LogoutController.class).toInstance(logoutController);
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |   protected Config provideConfig(@Nonnull SessionStore sessionStore) {
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |     Config config = new Config();
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     config.setSessionStoreFactory(parameters -> sessionStore);
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |     config.setHttpActionAdapter(new PlayHttpActionAdapter());
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     config.setProfileManagerFactory(ProfileManager::new);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |     return config;
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |   protected SsoManager provideSsoManager(
 | 
					
						
							|  |  |  |       Authentication systemAuthentication, CloseableHttpClient httpClient) {
 | 
					
						
							|  |  |  |     SsoManager manager =
 | 
					
						
							|  |  |  |         new SsoManager(
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |             configs, systemAuthentication, getSsoSettingsRequestUrl(configs), httpClient);
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |     manager.initializeSsoProvider();
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     return manager;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							|  |  |  |   protected Authentication provideSystemAuthentication() {
 | 
					
						
							|  |  |  |     // Returns an instance of Authentication used to authenticate system initiated calls to Metadata
 | 
					
						
							|  |  |  |     // Service.
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     String systemClientId = configs.getString(SYSTEM_CLIENT_ID_CONFIG_PATH);
 | 
					
						
							|  |  |  |     String systemSecret = configs.getString(SYSTEM_CLIENT_SECRET_CONFIG_PATH);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     final Actor systemActor =
 | 
					
						
							|  |  |  |         new Actor(ActorType.USER, systemClientId); // TODO: Change to service actor once supported.
 | 
					
						
							|  |  |  |     return new Authentication(
 | 
					
						
							|  |  |  |         systemActor,
 | 
					
						
							|  |  |  |         String.format("Basic %s:%s", systemClientId, systemSecret),
 | 
					
						
							|  |  |  |         Collections.emptyMap());
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							|  |  |  |   @Named("systemOperationContext")
 | 
					
						
							| 
									
										
										
										
											2024-04-16 10:12:48 -05:00
										 |  |  |   protected OperationContext provideOperationContext(
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |       final Authentication systemAuthentication,
 | 
					
						
							|  |  |  |       final ConfigurationProvider configurationProvider) {
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  |     ActorContext systemActorContext =
 | 
					
						
							| 
									
										
										
										
											2025-01-02 17:25:23 -06:00
										 |  |  |         ActorContext.builder()
 | 
					
						
							|  |  |  |             .systemAuth(true)
 | 
					
						
							|  |  |  |             .authentication(systemAuthentication)
 | 
					
						
							|  |  |  |             .enforceExistenceEnabled(
 | 
					
						
							|  |  |  |                 configurationProvider.getAuthentication().isEnforceExistenceEnabled())
 | 
					
						
							|  |  |  |             .build();
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     OperationContextConfig systemConfig =
 | 
					
						
							|  |  |  |         OperationContextConfig.builder()
 | 
					
						
							| 
									
										
										
										
											2024-03-23 06:15:36 -05:00
										 |  |  |             .viewAuthorizationConfiguration(configurationProvider.getAuthorization().getView())
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  |             .allowSystemAuthentication(true)
 | 
					
						
							|  |  |  |             .build();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return OperationContext.builder()
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |         .operationContextConfig(systemConfig)
 | 
					
						
							|  |  |  |         .systemActorContext(systemActorContext)
 | 
					
						
							|  |  |  |         // Authorizer.EMPTY is fine since it doesn't actually apply to system auth
 | 
					
						
							|  |  |  |         .authorizationContext(AuthorizationContext.builder().authorizer(Authorizer.EMPTY).build())
 | 
					
						
							|  |  |  |         .searchContext(SearchContext.EMPTY)
 | 
					
						
							|  |  |  |         .entityRegistryContext(EntityRegistryContext.builder().build(EmptyEntityRegistry.EMPTY))
 | 
					
						
							|  |  |  |         .validationContext(ValidationContext.builder().alternateValidation(false).build())
 | 
					
						
							| 
									
										
										
										
											2024-12-18 12:45:38 -06:00
										 |  |  |         .retrieverContext(RetrieverContext.EMPTY)
 | 
					
						
							| 
									
										
										
										
											2025-01-02 17:25:23 -06:00
										 |  |  |         .build(
 | 
					
						
							|  |  |  |             systemAuthentication,
 | 
					
						
							|  |  |  |             configurationProvider.getAuthentication().isEnforceExistenceEnabled());
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							|  |  |  |   protected ConfigurationProvider provideConfigurationProvider() {
 | 
					
						
							|  |  |  |     AnnotationConfigApplicationContext context =
 | 
					
						
							|  |  |  |         new AnnotationConfigApplicationContext(ConfigurationProvider.class);
 | 
					
						
							|  |  |  |     return context.getBean(ConfigurationProvider.class);
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2023-09-21 22:00:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							|  |  |  |   protected SystemEntityClient provideEntityClient(
 | 
					
						
							| 
									
										
										
										
											2024-02-28 16:57:26 -06:00
										 |  |  |       @Named("systemOperationContext") final OperationContext systemOperationContext,
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |       final ConfigurationProvider configurationProvider) {
 | 
					
						
							| 
									
										
										
										
											2024-05-13 14:37:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     return new SystemRestliEntityClient(
 | 
					
						
							|  |  |  |         buildRestliClient(),
 | 
					
						
							| 
									
										
										
										
											2024-11-05 09:42:21 -06:00
										 |  |  |         EntityClientConfig.builder()
 | 
					
						
							|  |  |  |             .backoffPolicy(new ExponentialBackoff(configs.getInt(ENTITY_CLIENT_RETRY_INTERVAL)))
 | 
					
						
							|  |  |  |             .retryCount(configs.getInt(ENTITY_CLIENT_NUM_RETRIES))
 | 
					
						
							|  |  |  |             .batchGetV2Size(configs.getInt(ENTITY_CLIENT_RESTLI_GET_BATCH_SIZE))
 | 
					
						
							|  |  |  |             .batchGetV2Concurrency(2)
 | 
					
						
							|  |  |  |             .build(),
 | 
					
						
							|  |  |  |         configurationProvider.getCache().getClient().getEntityClient());
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							|  |  |  |   protected AuthServiceClient provideAuthClient(
 | 
					
						
							|  |  |  |       Authentication systemAuthentication, CloseableHttpClient httpClient) {
 | 
					
						
							|  |  |  |     // Init a GMS auth client
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     final String metadataServiceHost = getMetadataServiceHost(configs);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     final int metadataServicePort = getMetadataServicePort(configs);
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |     final boolean metadataServiceUseSsl = doesMetadataServiceUseSsl(configs);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     return new AuthServiceClient(
 | 
					
						
							|  |  |  |         metadataServiceHost,
 | 
					
						
							|  |  |  |         metadataServicePort,
 | 
					
						
							|  |  |  |         metadataServiceUseSsl,
 | 
					
						
							|  |  |  |         systemAuthentication,
 | 
					
						
							|  |  |  |         httpClient);
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |   @Provides
 | 
					
						
							|  |  |  |   @Singleton
 | 
					
						
							|  |  |  |   protected CloseableHttpClient provideHttpClient() {
 | 
					
						
							|  |  |  |     return HttpClients.createDefault();
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   private com.linkedin.restli.client.Client buildRestliClient() {
 | 
					
						
							|  |  |  |     final String metadataServiceHost =
 | 
					
						
							|  |  |  |         utils.ConfigUtil.getString(
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |             configs,
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  |             METADATA_SERVICE_HOST_CONFIG_PATH,
 | 
					
						
							|  |  |  |             utils.ConfigUtil.DEFAULT_METADATA_SERVICE_HOST);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     final int metadataServicePort =
 | 
					
						
							|  |  |  |         utils.ConfigUtil.getInt(
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |             configs,
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  |             utils.ConfigUtil.METADATA_SERVICE_PORT_CONFIG_PATH,
 | 
					
						
							|  |  |  |             utils.ConfigUtil.DEFAULT_METADATA_SERVICE_PORT);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |     final boolean metadataServiceUseSsl =
 | 
					
						
							|  |  |  |         utils.ConfigUtil.getBoolean(
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |             configs,
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  |             utils.ConfigUtil.METADATA_SERVICE_USE_SSL_CONFIG_PATH,
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |             ConfigUtil.DEFAULT_METADATA_SERVICE_USE_SSL);
 | 
					
						
							|  |  |  |     final String metadataServiceSslProtocol =
 | 
					
						
							|  |  |  |         utils.ConfigUtil.getString(
 | 
					
						
							| 
									
										
										
										
											2024-10-28 09:05:16 -05:00
										 |  |  |             configs,
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  |             utils.ConfigUtil.METADATA_SERVICE_SSL_PROTOCOL_CONFIG_PATH,
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |             ConfigUtil.DEFAULT_METADATA_SERVICE_SSL_PROTOCOL);
 | 
					
						
							|  |  |  |     return DefaultRestliClientFactory.getRestLiClient(
 | 
					
						
							|  |  |  |         metadataServiceHost,
 | 
					
						
							|  |  |  |         metadataServicePort,
 | 
					
						
							|  |  |  |         metadataServiceUseSsl,
 | 
					
						
							|  |  |  |         metadataServiceSslProtocol);
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |   protected boolean doesMetadataServiceUseSsl(com.typesafe.config.Config configs) {
 | 
					
						
							|  |  |  |     return configs.hasPath(METADATA_SERVICE_USE_SSL_CONFIG_PATH)
 | 
					
						
							|  |  |  |         ? configs.getBoolean(METADATA_SERVICE_USE_SSL_CONFIG_PATH)
 | 
					
						
							|  |  |  |         : Boolean.parseBoolean(
 | 
					
						
							|  |  |  |             Configuration.getEnvironmentVariable(GMS_USE_SSL_ENV_VAR, DEFAULT_GMS_USE_SSL));
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-11-22 16:33:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 14:34:10 -06:00
										 |  |  |   protected String getMetadataServiceHost(com.typesafe.config.Config configs) {
 | 
					
						
							|  |  |  |     return configs.hasPath(METADATA_SERVICE_HOST_CONFIG_PATH)
 | 
					
						
							|  |  |  |         ? configs.getString(METADATA_SERVICE_HOST_CONFIG_PATH)
 | 
					
						
							|  |  |  |         : Configuration.getEnvironmentVariable(GMS_HOST_ENV_VAR, DEFAULT_GMS_HOST);
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   protected Integer getMetadataServicePort(com.typesafe.config.Config configs) {
 | 
					
						
							|  |  |  |     return configs.hasPath(METADATA_SERVICE_PORT_CONFIG_PATH)
 | 
					
						
							|  |  |  |         ? configs.getInt(METADATA_SERVICE_PORT_CONFIG_PATH)
 | 
					
						
							|  |  |  |         : Integer.parseInt(
 | 
					
						
							|  |  |  |             Configuration.getEnvironmentVariable(GMS_PORT_ENV_VAR, DEFAULT_GMS_PORT));
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   protected String getSsoSettingsRequestUrl(com.typesafe.config.Config configs) {
 | 
					
						
							|  |  |  |     final String protocol = doesMetadataServiceUseSsl(configs) ? "https" : "http";
 | 
					
						
							|  |  |  |     final String metadataServiceHost = getMetadataServiceHost(configs);
 | 
					
						
							|  |  |  |     final Integer metadataServicePort = getMetadataServicePort(configs);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return String.format(
 | 
					
						
							|  |  |  |         "%s://%s:%s/%s",
 | 
					
						
							|  |  |  |         protocol, metadataServiceHost, metadataServicePort, GET_SSO_SETTINGS_ENDPOINT);
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:02:42 +05:30
										 |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2021-03-11 13:38:35 -08:00
										 |  |  | }
 |