24
24
package org .opengrok .web ;
25
25
26
26
import java .io .IOException ;
27
- import java .time .Duration ;
28
- import java .time .Instant ;
29
27
import java .util .logging .Level ;
30
28
import java .util .logging .Logger ;
31
29
import javax .servlet .Filter ;
37
35
import javax .servlet .http .HttpServletRequest ;
38
36
import javax .servlet .http .HttpServletResponse ;
39
37
40
- import io .micrometer .core .instrument .DistributionSummary ;
41
- import io .micrometer .core .instrument .Timer ;
42
- import org .opengrok .indexer .Metrics ;
43
38
import org .opengrok .indexer .configuration .Project ;
44
39
import org .opengrok .indexer .logger .LoggerFactory ;
45
40
import org .opengrok .indexer .web .PageConfig ;
@@ -50,9 +45,6 @@ public class AuthorizationFilter implements Filter {
50
45
51
46
private static final Logger LOGGER = LoggerFactory .getLogger (AuthorizationFilter .class );
52
47
53
- private final DistributionSummary requests = Metrics .getRegistry ().summary (StatisticsFilter .REQUESTS_METRIC );
54
- private final Timer requestsForbidden = Metrics .getRegistry ().timer ("requests.forbidden" );
55
-
56
48
@ Override
57
49
public void init (FilterConfig fc ) {
58
50
}
@@ -62,7 +54,7 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
62
54
HttpServletRequest httpReq = (HttpServletRequest ) sr ;
63
55
HttpServletResponse httpRes = (HttpServletResponse ) sr1 ;
64
56
65
- // All RESTful API requests are allowed for now (also see LocalhostFilter) .
57
+ // All RESTful API requests are allowed here for now because they go through LocalhostFilter.
66
58
// The /search endpoint will go through authorization via SearchEngine.search()
67
59
// so does not have to be exempted here.
68
60
if (httpReq .getServletPath ().startsWith (RestApp .API_PATH )) {
@@ -79,39 +71,24 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
79
71
80
72
Project p = config .getProject ();
81
73
if (p != null && !config .isAllowed (p )) {
82
- Instant start = Instant .now ();
83
- try {
84
- if (LOGGER .isLoggable (Level .INFO )) {
85
- if (httpReq .getRemoteUser () != null ) {
86
- LOGGER .log (Level .INFO , "Access denied for user ''{0}'' for URI: {1}" ,
87
- new Object [] {Laundromat .launderLog (httpReq .getRemoteUser ()),
88
- Laundromat .launderLog (httpReq .getRequestURI ())});
89
- } else {
90
- LOGGER .log (Level .INFO , "Access denied for URI: {0}" ,
91
- Laundromat .launderLog (httpReq .getRequestURI ()));
92
- }
93
- }
94
-
95
- /*
96
- * Add the request to the statistics. This is called just once for a
97
- * single request otherwise the next filter will count the same
98
- * request twice ({@link StatisticsFilter#collectStats}).
99
- *
100
- * In this branch of the if statement the filter processing stopped
101
- * and does not follow to the StatisticsFilter.
102
- */
103
- requests .record (1 );
104
-
105
- if (!config .getEnv ().getIncludeFiles ().getForbiddenIncludeFileContent (false ).isEmpty ()) {
106
- sr .getRequestDispatcher ("/eforbidden" ).forward (sr , sr1 );
107
- return ;
74
+ if (LOGGER .isLoggable (Level .INFO )) {
75
+ if (httpReq .getRemoteUser () != null ) {
76
+ LOGGER .log (Level .INFO , "Access denied for user ''{0}'' for URI: {1}" ,
77
+ new Object [] {Laundromat .launderLog (httpReq .getRemoteUser ()),
78
+ Laundromat .launderLog (httpReq .getRequestURI ())});
79
+ } else {
80
+ LOGGER .log (Level .INFO , "Access denied for URI: {0}" ,
81
+ Laundromat .launderLog (httpReq .getRequestURI ()));
108
82
}
83
+ }
109
84
110
- httpRes .sendError (HttpServletResponse .SC_FORBIDDEN , "Access forbidden" );
85
+ if (!config .getEnv ().getIncludeFiles ().getForbiddenIncludeFileContent (false ).isEmpty ()) {
86
+ sr .getRequestDispatcher ("/eforbidden" ).forward (sr , sr1 );
111
87
return ;
112
- } finally {
113
- requestsForbidden .record (Duration .between (start , Instant .now ()));
114
88
}
89
+
90
+ httpRes .sendError (HttpServletResponse .SC_FORBIDDEN , "Access forbidden" );
91
+ return ;
115
92
}
116
93
fc .doFilter (sr , sr1 );
117
94
}
0 commit comments