This is an automated email from the ASF dual-hosted git repository.
zixuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 9bddd726d49 [refactor][broker] AuthenticationFilter.doFilter (#20598)
9bddd726d49 is described below
commit 9bddd726d49742b8bf55b5143a7a929afdc597f2
Author: tison <[email protected]>
AuthorDate: Mon Jun 19 17:02:22 2023 +0800
[refactor][broker] AuthenticationFilter.doFilter (#20598)
Signed-off-by: tison <[email protected]>
---
.../pulsar/broker/web/AuthenticationFilter.java | 37 ++++++++++------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/AuthenticationFilter.java
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/AuthenticationFilter.java
index 0670412e105..3b85d9b03e4 100644
---
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/AuthenticationFilter.java
+++
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/AuthenticationFilter.java
@@ -50,32 +50,27 @@ public class AuthenticationFilter implements Filter {
}
@Override
- public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
- throws IOException, ServletException {
- boolean allowed = false;
- Exception authenticationException = null;
+ public void doFilter(
+ ServletRequest request, ServletResponse response, FilterChain chain
+ ) throws IOException, ServletException {
+ final HttpServletRequest httpRequest = (HttpServletRequest) request;
+ final HttpServletResponse httpResponse = (HttpServletResponse)
response;
+
+ final boolean doFilter;
try {
- allowed = authenticationService
- .authenticateHttpRequest((HttpServletRequest) request,
(HttpServletResponse) response);
+ doFilter =
authenticationService.authenticateHttpRequest(httpRequest, httpResponse);
} catch (Exception e) {
- authenticationException = e;
- }
-
- if (allowed) {
- chain.doFilter(request, response);
- return;
- }
-
- if (authenticationException != null) {
- HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED,
"Authentication required");
- if (authenticationException instanceof AuthenticationException) {
- LOG.warn("[{}] Failed to authenticate HTTP request: {}",
request.getRemoteAddr(),
- authenticationException.getMessage());
+ if (e instanceof AuthenticationException) {
+ LOG.warn("[{}] Failed to authenticate HTTP request: {}",
request.getRemoteAddr(), e.getMessage());
} else {
- LOG.error("[{}] Error performing authentication for HTTP",
request.getRemoteAddr(),
- authenticationException);
+ LOG.error("[{}] Error performing authentication for HTTP",
request.getRemoteAddr(), e);
}
+ return;
+ }
+
+ if (doFilter) {
+ chain.doFilter(request, response);
}
}