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