Skip to content

Commit

Permalink
Update RangerRESTAPIFilter.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaab authored Jan 8, 2025
1 parent 18f0352 commit dfbb6da
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
import java.util.regex.Pattern;

public class RangerRESTAPIFilter extends LoggingFilter {
static volatile boolean initDone;
Logger logger = LoggerFactory.getLogger(RangerRESTAPIFilter.class);

static volatile boolean initDone;

boolean logStdOut = true;
HashMap<String, String> regexPathMap = new HashMap<>();
HashMap<String, Pattern> regexPatternMap = new HashMap<>();
Expand All @@ -70,7 +72,7 @@ public ContainerRequest filter(ContainerRequest request) {
try {
request = super.filter(request);
} catch (Throwable t) {
logger.error("Error FILTER logging. path={}", path, t);
logger.error("Error FILTER logging. path = {}", path, t);
}
}
}
Expand Down Expand Up @@ -122,21 +124,23 @@ void init() {

private void loadPathPatterns() throws ClassNotFoundException {
String pkg = "org.apache.ranger.service";
// List<Class> cList = findClasses(new File(dir), pkg);

@SuppressWarnings("rawtypes")
List<Class> cList = findClasses(pkg);

for (@SuppressWarnings("rawtypes") Class klass : cList) {
Annotation[] annotations = klass.getAnnotations();
for (Annotation annotation : annotations) {
if (!(annotation instanceof Path)) {
continue;
}

Path path = (Path) annotation;

if (path.value().startsWith("crud")) {
continue;
}
// logger.info("path=" + path.value());
// Loop over the class methods

for (Method m : klass.getMethods()) {
Annotation[] methodAnnotations = m.getAnnotations();
String httpMethod = null;
Expand Down Expand Up @@ -172,13 +176,13 @@ private void loadPathPatterns() throws ClassNotFoundException {
Pattern regexPattern = Pattern.compile(regEx);

if (regexPatternMap.containsKey(regEx)) {
logger.warn("Duplicate regex={}, fullPath={}", regEx, fullPath);
logger.warn("Duplicate regex = {}, fullPath = {}", regEx, fullPath);
}
regexList.add(regEx);
regexPathMap.put(regEx, fullPath);
regexPatternMap.put(regEx, regexPattern);

logger.info("path={}, servicePath={}, fullPath={}, regEx={}", path.value(), servicePath, fullPath, regEx);
logger.info("path = {}, servicePath = {}, fullPath = {}, regEx = {}", path.value(), servicePath, fullPath, regEx);
}
}
}
Expand All @@ -196,8 +200,6 @@ private void loadPathPatterns() throws ClassNotFoundException {
if (matcher.matches()) {
foundMatch = true;
foundMatches = true;
// logger.info("rX " + rX + " matched with rY=" + rY
// + ". Moving rX to the top. Loop count=" + i);
break;
}
}
Expand All @@ -209,7 +211,7 @@ private void loadPathPatterns() throws ClassNotFoundException {
}
regexList = tmpList;
if (!foundMatches) {
logger.info("Done rearranging. loopCount={}", i);
logger.info("Done rearranging. loopCount = {}", i);
break;
}
}
Expand All @@ -218,9 +220,6 @@ private void loadPathPatterns() throws ClassNotFoundException {
}

logger.info("Loaded {} API methods.", regexList.size());
// for (String regEx : regexList) {
// logger.info("regEx=" + regEx);
// }
}

@SuppressWarnings("rawtypes")
Expand All @@ -229,9 +228,6 @@ private List<Class> findClasses(String packageName) throws ClassNotFoundExceptio

ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);

// scanner.addIncludeFilter(new
// AnnotationTypeFilter(<TYPE_YOUR_ANNOTATION_HERE>.class));

for (BeanDefinition bd : scanner.findCandidateComponents(packageName)) {
classes.add(Class.forName(bd.getBeanClassName()));
}
Expand Down

0 comments on commit dfbb6da

Please sign in to comment.