Skip to content

Commit daf96a2

Browse files
yangxuzemneethiraj
authored andcommitted
RANGER-5403: fix intermittent HDFS authorization failures
Signed-off-by: Madhan Neethiraj <[email protected]>
1 parent 0f980ba commit daf96a2

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

agents-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerPathResourceMatcher.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,23 @@ static class RecursivePathResourceMatcher extends AbstractPathResourceMatcher {
596596
final IOCase ioCase;
597597
final BiFunction<String, String, Boolean> primaryFunction;
598598
final BiFunction<String, String, Boolean> fallbackFunction;
599-
String valueWithoutSeparator;
600-
String valueWithSeparator;
599+
final String valueWithoutSeparator;
600+
final String valueWithSeparator;
601601

602602
RecursivePathResourceMatcher(String value, Map<String, String> options, char pathSeparatorChar, boolean optIgnoreCase, int priority) {
603603
super(value, options, pathSeparatorChar, true, priority);
604604

605605
this.ioCase = optIgnoreCase ? IOCase.INSENSITIVE : IOCase.SENSITIVE;
606606
this.primaryFunction = optIgnoreCase ? StringUtils::equalsIgnoreCase : StringUtils::equals;
607607
this.fallbackFunction = optIgnoreCase ? StringUtils::startsWithIgnoreCase : StringUtils::startsWith;
608+
609+
if (this.value == null || getNeedsDynamicEval()) {
610+
valueWithoutSeparator = null;
611+
valueWithSeparator = null;
612+
} else {
613+
valueWithoutSeparator = getStringToCompare(this.value);
614+
valueWithSeparator = valueWithoutSeparator + pathSeparatorChar;
615+
}
608616
}
609617

610618
String getStringToCompare(String policyValue) {
@@ -626,11 +634,6 @@ boolean isMatch(String resourceValue, Map<String, Object> evalContext) {
626634

627635
noSeparator = expandedPolicyValue != null ? getStringToCompare(expandedPolicyValue) : null;
628636
} else {
629-
if (valueWithoutSeparator == null && value != null) {
630-
valueWithoutSeparator = getStringToCompare(value);
631-
valueWithSeparator = valueWithoutSeparator + pathSeparatorChar;
632-
}
633-
634637
noSeparator = valueWithoutSeparator;
635638
}
636639

@@ -669,11 +672,6 @@ public boolean isChildMatch(String resourceValue, Map<String, Object> evalContex
669672

670673
noSeparator = expandedPolicyValue != null ? getStringToCompare(expandedPolicyValue) : null;
671674
} else {
672-
if (valueWithoutSeparator == null && value != null) {
673-
valueWithoutSeparator = getStringToCompare(value);
674-
valueWithSeparator = valueWithoutSeparator + pathSeparatorChar;
675-
}
676-
677675
noSeparator = valueWithoutSeparator;
678676
}
679677

agents-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerURLResourceMatcher.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,21 @@ int getPriority() {
268268
}
269269

270270
abstract static class RecursiveMatcher extends AbstractStringResourceMatcher {
271-
final char levelSeparatorChar;
272-
String valueWithoutSeparator;
273-
String valueWithSeparator;
271+
final char levelSeparatorChar;
272+
final String valueWithoutSeparator;
273+
final String valueWithSeparator;
274274

275275
RecursiveMatcher(String value, Map<String, String> options, char levelSeparatorChar) {
276276
super(value, options);
277277
this.levelSeparatorChar = levelSeparatorChar;
278+
279+
if (this.value == null || getNeedsDynamicEval()) {
280+
valueWithoutSeparator = null;
281+
valueWithSeparator = null;
282+
} else {
283+
valueWithoutSeparator = getStringToCompare(this.value);
284+
valueWithSeparator = valueWithoutSeparator + levelSeparatorChar;
285+
}
278286
}
279287

280288
String getStringToCompare(String policyValue) {
@@ -300,11 +308,6 @@ boolean isMatch(String resourceValue, Map<String, Object> evalContext) {
300308

301309
noSeparator = expandedPolicyValue != null ? getStringToCompare(expandedPolicyValue) : null;
302310
} else {
303-
if (valueWithoutSeparator == null && value != null) {
304-
valueWithoutSeparator = getStringToCompare(value);
305-
valueWithSeparator = valueWithoutSeparator + levelSeparatorChar;
306-
}
307-
308311
noSeparator = valueWithoutSeparator;
309312
}
310313

@@ -343,11 +346,6 @@ boolean isMatch(String resourceValue, Map<String, Object> evalContext) {
343346

344347
noSeparator = expandedPolicyValue != null ? getStringToCompare(expandedPolicyValue) : null;
345348
} else {
346-
if (valueWithoutSeparator == null && value != null) {
347-
valueWithoutSeparator = getStringToCompare(value);
348-
valueWithSeparator = valueWithoutSeparator + levelSeparatorChar;
349-
}
350-
351349
noSeparator = valueWithoutSeparator;
352350
}
353351

0 commit comments

Comments
 (0)