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


##########
kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMDCFilter.java:
##########
@@ -70,15 +84,37 @@ public void doFilter(ServletRequest request, 
ServletResponse response, FilterCha
                 DATA_TL.remove();
 
                 UserGroupInformation ugi         = 
HttpUserGroupInformation.get();
-                String               method      = ((HttpServletRequest) 
request).getMethod();
-                StringBuffer         requestURL  = ((HttpServletRequest) 
request).getRequestURL();
-                String               queryString = ((HttpServletRequest) 
request).getQueryString();
+                String               method      = req.getMethod();
+                StringBuffer         requestURL  = req.getRequestURL();
+                String               queryString = req.getQueryString();
+
+                // Extract operation from query parameters if present
+                String operation = null;
+                if (path.contains("/_eek") && queryString != null) {
+                    for (String param : queryString.split("&")) {
+                        String[] kv = param.split("=", 2);
+                        if (kv.length == 2 && "eek_op".equals(kv[0])) {
+                            try {
+                                operation = URLDecoder.decode(kv[1], 
StandardCharsets.UTF_8.name());
+                            } catch (UnsupportedEncodingException | 
IllegalArgumentException e) {
+                                logger.error("encoding issue in UTF-8 for 
eek_op value: {}", kv[1], e);

Review Comment:
   The error message should be more specific about the type of encoding issue. 
Consider: 'Failed to decode eek_op parameter value using UTF-8 encoding: {}'.
   ```suggestion
                                   logger.error("Failed to decode eek_op 
parameter value using UTF-8 encoding: {}", kv[1], e);
   ```



##########
kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMDCFilter.java:
##########
@@ -70,15 +84,37 @@ public void doFilter(ServletRequest request, 
ServletResponse response, FilterCha
                 DATA_TL.remove();
 
                 UserGroupInformation ugi         = 
HttpUserGroupInformation.get();
-                String               method      = ((HttpServletRequest) 
request).getMethod();
-                StringBuffer         requestURL  = ((HttpServletRequest) 
request).getRequestURL();
-                String               queryString = ((HttpServletRequest) 
request).getQueryString();
+                String               method      = req.getMethod();
+                StringBuffer         requestURL  = req.getRequestURL();
+                String               queryString = req.getQueryString();
+
+                // Extract operation from query parameters if present
+                String operation = null;
+                if (path.contains("/_eek") && queryString != null) {
+                    for (String param : queryString.split("&")) {
+                        String[] kv = param.split("=", 2);
+                        if (kv.length == 2 && "eek_op".equals(kv[0])) {
+                            try {
+                                operation = URLDecoder.decode(kv[1], 
StandardCharsets.UTF_8.name());
+                            } catch (UnsupportedEncodingException | 
IllegalArgumentException e) {
+                                logger.error("encoding issue in UTF-8 for 
eek_op value: {}", kv[1], e);
+                                throw new ServletException("Unexpected 
encoding issue with UTF-8");

Review Comment:
   The error message is too generic and doesn't help identify the root cause. 
Consider: 'Failed to decode eek_op parameter: malformed URL encoding'.
   ```suggestion
                                   throw new ServletException("Failed to decode 
eek_op parameter: '" + kv[1] + "'. " + e.getClass().getSimpleName() + ": " + 
e.getMessage(), e);
   ```



-- 
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