You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2021/01/07 02:13:20 UTC
[pulsar] branch branch-2.7 updated: Return correct authz and auth
errors from proxy to client (#9055)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.7 by this push:
new c0b002c Return correct authz and auth errors from proxy to client (#9055)
c0b002c is described below
commit c0b002c3cd1fbd8ca2396c774552cb7300f7d541
Author: Boyang Jerry Peng <je...@gmail.com>
AuthorDate: Sat Dec 26 14:59:23 2020 -0800
Return correct authz and auth errors from proxy to client (#9055)
Co-authored-by: Jerry Peng <je...@splunk.com>
(cherry picked from commit 8574e58642a06d8eedba33a4106b6b585cb5979b)
---
.../apache/pulsar/proxy/server/LookupProxyHandler.java | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java
index 8782793..f2d7242 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java
@@ -27,6 +27,7 @@ import java.net.URISyntaxException;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
+import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.common.protocol.Commands;
import org.apache.pulsar.common.api.proto.PulsarApi.CommandGetTopicsOfNamespace;
import org.apache.pulsar.common.api.proto.PulsarApi.CommandGetSchema;
@@ -231,7 +232,7 @@ public class LookupProxyHandler {
log.warn("[{}] Failed to get partitioned metadata for topic {} {}", clientAddress, topicName,
ex.getMessage(), ex);
proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse(
- ServerError.ServiceNotReady, ex.getMessage(), clientRequestId));
+ getServerError(ex), ex.getMessage(), clientRequestId));
return null;
});
} else {
@@ -259,7 +260,7 @@ public class LookupProxyHandler {
if (t != null) {
log.warn("[{}] failed to get Partitioned metadata : {}", topicName.toString(),
t.getMessage(), t);
- proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(ServerError.ServiceNotReady,
+ proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(getServerError(t),
t.getMessage(), clientRequestId));
} else {
proxyConnection.ctx().writeAndFlush(
@@ -443,5 +444,17 @@ public class LookupProxyHandler {
return InetSocketAddress.createUnresolved(brokerURI.getHost(), brokerURI.getPort());
}
+ private ServerError getServerError(Throwable error) {
+ ServerError responseError;
+ if (error instanceof PulsarClientException.AuthorizationException) {
+ responseError = ServerError.AuthorizationError;
+ } else if (error instanceof PulsarClientException.AuthenticationException) {
+ responseError = ServerError.AuthenticationError;
+ } else {
+ responseError = ServerError.ServiceNotReady;
+ }
+ return responseError;
+ }
+
private static final Logger log = LoggerFactory.getLogger(LookupProxyHandler.class);
}