首先ranger和hive是通过在hive中配置hive.security.authorization.manager参数,建立起的联系
在hive的lib目录下存在ranger-plugin-classloader-0.5.0.2.4.0.0-169.jar、ranger-hive-plugin-shim-0.5.0.2.4.0.0-169.jar这两jar包以及ranger-hive-plugin-impl目录
当实例化hive.security.authorization.manager指定的类时(org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizerFactory),也就是调用RangerHiveAuthorizerFactory的构造方法时,会调用RangerHiveAuthorizerFactory的init()方法;在RangerHiveAuthorizerFactory的init()中,会调用ranger-plugin-classloader-0.5.0.2.4.0.0-169.jar包中的RangerPluginClassLoader的getInstance方法,来获取自定义的URLClassLoader;在ranger-plugin-classloader-0.5.0.2.4.0.0-169.jar包中实现了RangerPluginClassLoader类,该类继承自URLClassLoader;使用RangerPluginClassLoaderUtil类getPluginFilesForServiceTypeAndPluginclass方法,根据组件名生成路径(路径如:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl);然后获取该路径(/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl)下的所有jar包的URL
[file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/ranger-plugins-cred-0.5.0.2.4.0.0-169.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/noggit-0.6.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/eclipselink-2.5.2-M1.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/ranger_solrj-0.5.0.2.4.0.0-169.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/ranger-plugins-audit-0.5.0.2.4.0.0-169.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/httpmime-4.2.5.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/gson-2.2.4.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/javax.persistence-2.1.0.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/ranger-hive-plugin-0.5.0.2.4.0.0-169.jar, file:/usr/hdp/2.4.0.0-169/hive/lib/ranger-hive-plugin-impl/ranger-plugins-common-0.5.0.2.4.0.0-169.jar]
调用super方法,将这些jar包的URL传入URLClassLoader子类中,并返回RangerPluginClassLoader实例(在RangerPluginClassLoader类中实现了findClass、loadClass、findResource、findResources方法)
注意:本文归作者所有,未经作者允许,不得转载