You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/12/08 03:18:05 UTC

[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #3308: [KYUUBI #3300] [Authz] Support overriding usergroup with UserStore in AccessRequest

yaooqinn commented on code in PR #3308:
URL: https://github.com/apache/incubator-kyuubi/pull/3308#discussion_r1042884950


##########
extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/AccessRequest.scala:
##########
@@ -72,4 +74,43 @@ object AccessRequest {
     }
     req
   }
+
+  private def getUserGroups(user: UserGroupInformation, userName: String): util.Set[String] = {
+    val enableOverrideUserGroupFromUserStore = SparkRangerAdminPlugin.getConfig.getBoolean(
+      s"ranger.plugin.${SparkRangerAdminPlugin.getConfig.getServiceType}" +
+        ".enable.override.usergroup.from.userstore",
+      false);
+    if (!enableOverrideUserGroupFromUserStore) {
+      user.getGroupNames.toSet.asJava
+    }
+
+    try {
+      val userGroupsFromUserStore: util.Set[String] = {
+        val getUserStoreEnricher = SparkRangerAdminPlugin.getClass.getMethod(
+          "getUserStoreEnricher")
+        getUserStoreEnricher.setAccessible(true)
+        val storeEnricher = getUserStoreEnricher.invoke(SparkRangerAdminPlugin)
+
+        val getRangerUserStore = storeEnricher.getClass.getMethod("getRangerUserStore")
+        getRangerUserStore.setAccessible(true)
+        val userStore = getRangerUserStore.invoke(storeEnricher)
+
+        val getUserGroupMapping = userStore.getClass.getMethod("getUserGroupMapping")
+        getUserGroupMapping.setAccessible(true)
+
+        val userGroupMappingMap: mutable.Map[String, util.Set[String]] =
+          mapAsScalaMap(getUserGroupMapping.invoke(userStore)
+            .asInstanceOf[util.HashMap[String, util.Set[String]]])
+
+        userGroupMappingMap.get(userName).orNull

Review Comment:
   nit: user.getShortUserName



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org