afernandez commented on a change in pull request #3697: DI-1113. ADDENDUM. 
Authentication: Enable user impersonation for Superset to HiveServer2 using 
hive.server2.proxy.user (a.fernandez)
URL: 
https://github.com/apache/incubator-superset/pull/3697#discussion_r148913483
 
 

 ##########
 File path: superset/models/core.py
 ##########
 @@ -615,23 +615,35 @@ def get_effective_user(self, url, user_name=None):
             effective_username = url.username
             if user_name:
                 effective_username = user_name
-            elif hasattr(g, 'user') and g.user.username:
+            elif hasattr(g, 'user') and hasattr(g.user, 'username') and 
g.user.username is not None:
                 effective_username = g.user.username
         return effective_username
 
     def get_sqla_engine(self, schema=None, nullpool=False, user_name=None):
         extra = self.get_extra()
         url = make_url(self.sqlalchemy_uri_decrypted)
-        params = extra.get('engine_params', {})
-        if nullpool:
-            params['poolclass'] = NullPool
         url = self.db_engine_spec.adjust_database_uri(url, schema)
         effective_username = self.get_effective_user(url, user_name)
+        # If using MySQL or Presto for example, will set url.username
+        # If using Hive, will not do anything yet since that relies on a 
configuration parameter instead.
         self.db_engine_spec.modify_url_for_impersonation(url, 
self.impersonate_user, effective_username)
 
         masked_url = self.get_password_masked_url(url)
         logging.info("Database.get_sqla_engine(). Masked URL: 
{0}".format(masked_url))
 
+        params = extra.get('engine_params', {})
+        if nullpool:
+            params['poolclass'] = NullPool
+
+        # If using Hive, this will set 
hive.server2.proxy.user=$effective_username
+        configuration = {}
+        configuration.update(
+            self.db_engine_spec.get_configuration_for_impersonation(str(url),
+                                                                    
self.impersonate_user,
+                                                                    
effective_username))
+        if configuration:
 
 Review comment:
   @mistercrunch fixed the long line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to