Copilot commented on code in PR #584:
URL: https://github.com/apache/ranger/pull/584#discussion_r2129033507


##########
agents-common/src/main/java/org/apache/ranger/plugin/service/RangerDefaultRequestProcessor.java:
##########
@@ -98,6 +103,63 @@ public void preProcess(RangerAccessRequest request) {
                     reqImpl.setClusterType(pluginContext.getClusterType());
                 }
 
+                RangerPluginConfig config = 
policyEngine.getPluginContext().getConfig();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("RangerPluginConfig = " + 
config.getPropertyPrefix());
+                }
+                if (config != null) {
+                    boolean isNameTransformationSupported = 
config.getBoolean(config.getPropertyPrefix() + 
RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_NAME_TRANSFORMATION, false);
+
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("isNameTransformationSupported = " + 
isNameTransformationSupported);
+                    }
+                    if (isNameTransformationSupported) {
+                        String user = request.getUser();
+                        if 
(policyEngine.getPluginContext().getUserNameCaseConversion().equalsIgnoreCase(UgsyncCommonConstants.UGSYNC_LOWER_CASE_CONVERSION_VALUE))
 {
+                            user = user.toLowerCase();
+                        } else if 
(policyEngine.getPluginContext().getUserNameCaseConversion().equalsIgnoreCase(UgsyncCommonConstants.UGSYNC_UPPER_CASE_CONVERSION_VALUE))
 {

Review Comment:
   Calling `equalsIgnoreCase` on a potentially null 
`getUserNameCaseConversion()` may cause an NPE. Consider storing the conversion 
string in a local variable or using a null-safe comparison before invoking 
`equalsIgnoreCase`.
   ```suggestion
                           String userNameCaseConversion = 
policyEngine.getPluginContext().getUserNameCaseConversion();
                           if (userNameCaseConversion != null && 
userNameCaseConversion.equalsIgnoreCase(UgsyncCommonConstants.UGSYNC_LOWER_CASE_CONVERSION_VALUE))
 {
                               user = user.toLowerCase();
                           } else if (userNameCaseConversion != null && 
userNameCaseConversion.equalsIgnoreCase(UgsyncCommonConstants.UGSYNC_UPPER_CASE_CONVERSION_VALUE))
 {
   ```



##########
agents-common/src/main/java/org/apache/ranger/plugin/model/UgsyncNameTransformRules.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *=-0987654321`o6 bftware distributed under the License is distributed on an

Review Comment:
   The license header contains garbled text; please remove or correct the stray 
characters to restore a valid ASF header.
   ```suggestion
    * Software distributed under the License is distributed on an
   ```



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/ServicePolicies.java:
##########
@@ -70,6 +70,7 @@ public static ServicePolicies copyHeader(ServicePolicies 
source) {
         ret.setPolicyVersion(source.getPolicyVersion());
         ret.setAuditMode(source.getAuditMode());
         ret.setServiceDef(source.getServiceDef());
+        ret.setServiceConfig(source.getServiceConfig());

Review Comment:
   [nitpick] This performs a shallow copy of `serviceConfig`, which may lead to 
shared mutable state between the original and the copy. Consider defensively 
copying the map to avoid unintended side effects.
   ```suggestion
           ret.setServiceConfig(source.getServiceConfig() != null ? new 
HashMap<>(source.getServiceConfig()) : null);
   ```



-- 
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: dev-unsubscr...@ranger.apache.org

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

Reply via email to