mneethiraj commented on code in PR #1029:
URL: https://github.com/apache/ranger/pull/1029#discussion_r3457775383


##########
plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java:
##########
@@ -308,49 +325,7 @@ public AuthorizationResponse 
authorize(AuthorizationContext context) {
     @Override
     public void init(Map<String, Object> initInfo) {
         logger.info("init()");
-
-        try {
-            RangerBasePlugin me = solrPlugin;
-
-            if (me == null) {
-                synchronized (RangerSolrAuthorizer.class) {
-                    me = solrPlugin;
-
-                    logger.info("RangerSolrAuthorizer(): init called");
-
-                    if (me == null) {
-                        authToJAASFile();
-
-                        logger.info("Creating RangerSolrPlugin");
-
-                        me = new RangerBasePlugin("solr", "solr");
-
-                        logger.info("Calling solrPlugin.init()");
-
-                        me.init();
-                        me.setResultProcessor(new 
RangerSolrAuditHandler(me.getConfig()));
-
-                        solrPlugin = me;
-                    }
-                }
-            }
-
-            useProxyIP    = 
solrPlugin.getConfig().getBoolean(RangerSolrConstants.PROP_USE_PROXY_IP, 
useProxyIP);
-            proxyIPHeader = 
solrPlugin.getConfig().get(RangerSolrConstants.PROP_PROXY_IP_HEADER, 
proxyIPHeader);
-
-            // First get from the -D property
-            solrAppName = System.getProperty("solr.kerberos.jaas.appname", 
solrAppName);
-
-            // Override if required from Ranger properties
-            solrAppName = 
solrPlugin.getConfig().get(RangerSolrConstants.PROP_SOLR_APP_NAME, solrAppName);
-
-            logger.info("init(): useProxyIP={}", useProxyIP);
-            logger.info("init(): proxyIPHeader={}", proxyIPHeader);
-            logger.info("init(): solrAppName={}", solrAppName);
-            logger.info("init(): KerberosName.rules={}", 
MiscUtil.getKerberosNamesRules());
-        } catch (Throwable t) {
-            logger.error("Error creating and initializing RangerBasePlugin()", 
t);
-        }
+        ensureSolrPluginInitialized();

Review Comment:
   `ensureSolrPluginInitialized();` => `getPlugin(); // triggers initialization 
if needed`



##########
plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java:
##########
@@ -124,6 +134,13 @@ public void close() {
      */
     @Override
     public AuthorizationResponse authorize(AuthorizationContext context) {
+        if (!ensureSolrPluginInitialized()) {

Review Comment:
   Refer to comment later in `ensureSolrPluginInitialized()`. Replace line 137 
with the following:
   
   ```
   RangerBasePlugin solrPlugin = getgetPlugin();
   
   if (solrPlugin == null) {
   ```



##########
plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java:
##########
@@ -530,6 +505,58 @@ public String getDescription() {
         return "Handle Query Document Authorization";
     }
 
+    private boolean ensureSolrPluginInitialized() {

Review Comment:
   Method name `ensureSolrPluginInitialized()` implies the method will fail 
(with an exception?) if plugin is not initialized. I suggest renaming the 
method as `getPlugin()` with the following implementation:
   
   ```
   private RangerBasePlugin getPlugin() {
     RangerBasePlugin ret = solrPlugin;
   
     if (ret == null) {
       synchronized (RangerSolrAuthorizer.class) {
         ret = solrPlugin;
   
         if (ret == null) {
           initializeSolrPlugin();
   
           ret = solrPlugin;
         }
       }
     }
   
     return ret;
   }
   
   private void initializeSolrPlugin() {
     authToJAASFile();
   
     RangerBasePlugin plugin = new RangerBasePlugin("solr", "solr");
   
     plugin.init();
     plugin.setResultProcessor(new RangerSolrAuditHandler(plugin.getConfig()));
   
     useProxyIP    = 
plugin.getConfig().getBoolean(RangerSolrConstants.PROP_USE_PROXY_IP, 
useProxyIP);
     proxyIPHeader = 
plugin.getConfig().get(RangerSolrConstants.PROP_PROXY_IP_HEADER, proxyIPHeader);
     solrAppName.  = 
plugin.getConfig().get(RangerSolrConstants.PROP_SOLR_APP_NAME, 
System.getProperty("solr.kerberos.jaas.appname", solrAppName));
   
     this.solrPlugin = plugin;
   }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to