Yuki Takei 6 лет назад
Родитель
Сommit
0fdf95a270
1 измененных файлов с 13 добавлено и 13 удалено
  1. 13 13
      src/server/service/passport.js

+ 13 - 13
src/server/service/passport.js

@@ -677,16 +677,16 @@ class PassportService {
 
     // parse with lucene-query-parser
     // see https://github.com/thoward/lucene-query-parser.js/wiki
-    const expr = luceneQueryParser.parse(rule);
-    if (expr == null) {
+    const luceneRule = luceneQueryParser.parse(rule);
+    if (luceneRule == null) {
       return false;
     }
-    debug({ 'Parsed Rule': JSON.stringify(expr, null, 2) });
+    debug({ 'Parsed Rule': JSON.stringify(luceneRule, null, 2) });
 
     const attributes = this.extractAttributesFromSAMLResponse(response);
     debug({ 'Extracted Attributes': JSON.stringify(attributes, null, 2) });
 
-    return this.evaluateRule(attributes, expr);
+    return this.evaluateRuleForSamlAttributes(attributes, luceneRule);
   }
 
   /**
@@ -696,21 +696,21 @@ class PassportService {
    * @param {object} luceneRule Expression Tree Structure generated by lucene-query-parser
    * @see https://github.com/thoward/lucene-query-parser.js/wiki
    */
-  evaluateRule(attributes, luceneRule) {
+  evaluateRuleForSamlAttributes(attributes, luceneRule) {
     const { left, right, operator } = luceneRule;
+
+    // when combined rules
     if (right != null) {
-      return this.evaluateCombinedRules(attributes, left, right, operator);
+      return this.evaluateCombinedRulesForSamlAttributes(attributes, left, right, operator);
     }
     if (left != null) {
-      return this.evaluateRule(attributes, left);
+      return this.evaluateRuleForSamlAttributes(attributes, left);
     }
 
     const { field, term } = luceneRule;
-
     if (field === '<implicit>') {
       return attributes[term] != null;
     }
-
     return attributes[field].includes(term);
   }
 
@@ -723,15 +723,15 @@ class PassportService {
    * @param {string} luceneOperator operator string expression
    * @see https://github.com/thoward/lucene-query-parser.js/wiki
    */
-  evaluateCombinedRules(attributes, luceneRuleLeft, luceneRuleRight, luceneOperator) {
+  evaluateCombinedRulesForSamlAttributes(attributes, luceneRuleLeft, luceneRuleRight, luceneOperator) {
     if (luceneOperator === 'OR') {
-      return this.evaluateRule(attributes, luceneRuleLeft) || this.evaluateRule(attributes, luceneRuleRight);
+      return this.evaluateRuleForSamlAttributes(attributes, luceneRuleLeft) || this.evaluateRuleForSamlAttributes(attributes, luceneRuleRight);
     }
     if (luceneOperator === 'AND') {
-      return this.evaluateRule(attributes, luceneRuleLeft) && this.evaluateRule(attributes, luceneRuleRight);
+      return this.evaluateRuleForSamlAttributes(attributes, luceneRuleLeft) && this.evaluateRuleForSamlAttributes(attributes, luceneRuleRight);
     }
     if (luceneOperator === 'NOT') {
-      return this.evaluateRule(attributes, luceneRuleLeft) && !this.evaluateRule(attributes, luceneRuleRight);
+      return this.evaluateRuleForSamlAttributes(attributes, luceneRuleLeft) && !this.evaluateRuleForSamlAttributes(attributes, luceneRuleRight);
     }
 
     throw new Error(`Unsupported operator: ${luceneOperator}`);