Skip to content

Commit dfbb6da

Browse files
authored
Update RangerRESTAPIFilter.java
1 parent 18f0352 commit dfbb6da

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
import java.util.regex.Pattern;
4545

4646
public class RangerRESTAPIFilter extends LoggingFilter {
47-
static volatile boolean initDone;
4847
Logger logger = LoggerFactory.getLogger(RangerRESTAPIFilter.class);
48+
49+
static volatile boolean initDone;
50+
4951
boolean logStdOut = true;
5052
HashMap<String, String> regexPathMap = new HashMap<>();
5153
HashMap<String, Pattern> regexPatternMap = new HashMap<>();
@@ -70,7 +72,7 @@ public ContainerRequest filter(ContainerRequest request) {
7072
try {
7173
request = super.filter(request);
7274
} catch (Throwable t) {
73-
logger.error("Error FILTER logging. path={}", path, t);
75+
logger.error("Error FILTER logging. path = {}", path, t);
7476
}
7577
}
7678
}
@@ -122,21 +124,23 @@ void init() {
122124

123125
private void loadPathPatterns() throws ClassNotFoundException {
124126
String pkg = "org.apache.ranger.service";
125-
// List<Class> cList = findClasses(new File(dir), pkg);
127+
126128
@SuppressWarnings("rawtypes")
127129
List<Class> cList = findClasses(pkg);
130+
128131
for (@SuppressWarnings("rawtypes") Class klass : cList) {
129132
Annotation[] annotations = klass.getAnnotations();
130133
for (Annotation annotation : annotations) {
131134
if (!(annotation instanceof Path)) {
132135
continue;
133136
}
137+
134138
Path path = (Path) annotation;
139+
135140
if (path.value().startsWith("crud")) {
136141
continue;
137142
}
138-
// logger.info("path=" + path.value());
139-
// Loop over the class methods
143+
140144
for (Method m : klass.getMethods()) {
141145
Annotation[] methodAnnotations = m.getAnnotations();
142146
String httpMethod = null;
@@ -172,13 +176,13 @@ private void loadPathPatterns() throws ClassNotFoundException {
172176
Pattern regexPattern = Pattern.compile(regEx);
173177

174178
if (regexPatternMap.containsKey(regEx)) {
175-
logger.warn("Duplicate regex={}, fullPath={}", regEx, fullPath);
179+
logger.warn("Duplicate regex = {}, fullPath = {}", regEx, fullPath);
176180
}
177181
regexList.add(regEx);
178182
regexPathMap.put(regEx, fullPath);
179183
regexPatternMap.put(regEx, regexPattern);
180184

181-
logger.info("path={}, servicePath={}, fullPath={}, regEx={}", path.value(), servicePath, fullPath, regEx);
185+
logger.info("path = {}, servicePath = {}, fullPath = {}, regEx = {}", path.value(), servicePath, fullPath, regEx);
182186
}
183187
}
184188
}
@@ -196,8 +200,6 @@ private void loadPathPatterns() throws ClassNotFoundException {
196200
if (matcher.matches()) {
197201
foundMatch = true;
198202
foundMatches = true;
199-
// logger.info("rX " + rX + " matched with rY=" + rY
200-
// + ". Moving rX to the top. Loop count=" + i);
201203
break;
202204
}
203205
}
@@ -209,7 +211,7 @@ private void loadPathPatterns() throws ClassNotFoundException {
209211
}
210212
regexList = tmpList;
211213
if (!foundMatches) {
212-
logger.info("Done rearranging. loopCount={}", i);
214+
logger.info("Done rearranging. loopCount = {}", i);
213215
break;
214216
}
215217
}
@@ -218,9 +220,6 @@ private void loadPathPatterns() throws ClassNotFoundException {
218220
}
219221

220222
logger.info("Loaded {} API methods.", regexList.size());
221-
// for (String regEx : regexList) {
222-
// logger.info("regEx=" + regEx);
223-
// }
224223
}
225224

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

230229
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
231230

232-
// scanner.addIncludeFilter(new
233-
// AnnotationTypeFilter(<TYPE_YOUR_ANNOTATION_HERE>.class));
234-
235231
for (BeanDefinition bd : scanner.findCandidateComponents(packageName)) {
236232
classes.add(Class.forName(bd.getBeanClassName()));
237233
}

0 commit comments

Comments
 (0)