This is an automated email from the ASF dual-hosted git repository.

dhavalshah9131 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git

commit 0f70a24f45b394043239d1898d7276b67400bfd2
Author: Dineshkumar Yadav <dineshkumar.ya...@outlook.com>
AuthorDate: Wed Sep 13 21:18:45 2023 +0530

    RANGER-4407 : Add server side validation for service audit filter
---
 .../java/org/apache/ranger/biz/ServiceDBStore.java |  7 +++++--
 .../src/views/ServiceManager/ServiceDefinition.jsx | 21 ++++++++++++++++----
 .../views/ServiceManager/ServiceViewDetails.jsx    | 23 +++++++++++++++++-----
 3 files changed, 40 insertions(+), 11 deletions(-)

diff --git 
a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java 
b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 84b096e9b..cfb7a6f23 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -3608,10 +3608,13 @@ public class ServiceDBStore extends 
AbstractServiceStore {
                                                
MessageEnums.INVALID_INPUT_DATA);
                        }
 
-                       if (StringUtils.equals(svcConfDef.getName(), 
RANGER_PLUGIN_AUDIT_FILTERS) && 
!configs.containsKey(RANGER_PLUGIN_AUDIT_FILTERS)) {
-                               if (svcConfDef.getDefaultvalue() != null) {
+                       if (StringUtils.equals(svcConfDef.getName(), 
RANGER_PLUGIN_AUDIT_FILTERS)) {
+                               if (svcConfDef.getDefaultvalue() != null && 
!configs.containsKey(RANGER_PLUGIN_AUDIT_FILTERS)) {
                                        
configs.put(RANGER_PLUGIN_AUDIT_FILTERS, svcConfDef.getDefaultvalue());
                                }
+                               if 
(!stringUtil.isEmpty(configs.get(RANGER_PLUGIN_AUDIT_FILTERS)) && 
JsonUtils.jsonToAuditFilterList(configs.get(RANGER_PLUGIN_AUDIT_FILTERS)) == 
null) {
+                                       throw 
restErrorUtil.createRESTException("Invalid value for " + svcConfDef.getName());
+                               }
                        }
                }
                Map<String, String> validConfigs = new HashMap<String, 
String>();
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceDefinition.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceDefinition.jsx
index 696c25c8c..bedce6f4b 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceDefinition.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceDefinition.jsx
@@ -19,7 +19,7 @@
 
 import React, { Component } from "react";
 import { Link } from "react-router-dom";
-import { Badge, Button, Col, Modal, Row, Table } from "react-bootstrap";
+import { Alert, Badge, Button, Col, Modal, Row, Table } from "react-bootstrap";
 import { difference, isEmpty, keys, map, omit, pick } from "lodash";
 import { RangerPolicyType } from "Utils/XAEnums";
 import ExportPolicy from "./ExportPolicy";
@@ -193,9 +193,22 @@ class ServiceDefinition extends Component {
       return tableRow;
     }
 
-    auditFilters = JSON.parse(
-      auditFilters["ranger.plugin.audit.filters"].replace(/'/g, '"')
-    );
+    try {
+      auditFilters = JSON.parse(
+        auditFilters["ranger.plugin.audit.filters"].replace(/'/g, '"')
+      );
+    } catch (error) {
+      tableRow.push(
+        <tr key="error-service-audit-filter">
+          <td className="text-center" colSpan="8">
+            <Alert variant="danger">
+              Error occured while parsing service audit filter!
+            </Alert>
+          </td>
+        </tr>
+      );
+      return tableRow;
+    }
 
     auditFilters.map((a, index) =>
       tableRow.push(
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceViewDetails.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceViewDetails.jsx
index 52279345f..8016d4489 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceViewDetails.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/ServiceManager/ServiceViewDetails.jsx
@@ -18,8 +18,8 @@
  */
 
 import React from "react";
-import { Row, Col, Table, Badge } from "react-bootstrap";
-import { difference, isEmpty, keys, map, omit, pick, upperCase } from "lodash";
+import { Alert, Row, Col, Table, Badge } from "react-bootstrap";
+import { difference, isEmpty, keys, map, omit, pick } from "lodash";
 
 export const ServiceViewDetails = (props) => {
   let { serviceData, serviceDefData } = props;
@@ -135,9 +135,22 @@ export const ServiceViewDetails = (props) => {
       return tableRow;
     }
 
-    auditFilters = JSON.parse(
-      auditFilters["ranger.plugin.audit.filters"].replace(/'/g, '"')
-    );
+    try {
+      auditFilters = JSON.parse(
+        auditFilters["ranger.plugin.audit.filters"].replace(/'/g, '"')
+      );
+    } catch (error) {
+      tableRow.push(
+        <tr key="error-service-audit-filter">
+          <td className="text-center" colSpan="8">
+            <Alert variant="danger">
+              Error occured while parsing service audit filter!
+            </Alert>
+          </td>
+        </tr>
+      );
+      return tableRow;
+    }
 
     auditFilters?.map((a, index) =>
       tableRow.push(

Reply via email to