KannarFr commented on code in PR #17411:
URL: https://github.com/apache/pulsar/pull/17411#discussion_r999299016


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -1089,12 +1091,25 @@ protected void handleSubscribe(final CommandSubscribe 
subscribe) {
                 }
                 Optional<Map<String, String>> subscriptionProperties = 
SubscriptionOption.getPropertiesMap(
                         subscribe.getSubscriptionPropertiesList());
+
+                boolean createTopicIfDoesNotExist = forceTopicCreation || 
(isAuthorizedToCreateTopic
+                        && 
service.isAllowAutoTopicCreation(topicName.toString()));
                 service.getTopic(topicName.toString(), 
createTopicIfDoesNotExist)
                         .thenCompose(optTopic -> {
                             if (!optTopic.isPresent()) {
-                                return FutureUtil
-                                        .failedFuture(new 
TopicNotFoundException(
-                                                "Topic " + topicName + " does 
not exist"));
+                                if (isAuthorizedToCreateTopic) {
+                                    return FutureUtil
+                                            .failedFuture(new 
TopicNotFoundException(
+                                                    "Topic " + topicName + " 
does not exist"));
+                                } else {
+                                    String msg = "Topic to subscribe does not 
exists and the Client is not"
+                                            + " authorized to create topic";
+                                    log.warn("[{}] {} with role {}", 
remoteAddress, msg, getPrincipal());
+                                    consumers.remove(consumerId, 
consumerFuture);
+                                    
ctx.writeAndFlush(Commands.newError(requestId, ServerError.AuthorizationError,
+                                            msg));
+                                    return null;

Review Comment:
   Ok, does e34524abd0a9cea41e7968f518e6929647e4e140 LGTY?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -1307,7 +1326,25 @@ protected void handleProducer(final CommandProducer 
cmdProducer) {
                         producerId, schema == null ? "absent" : "present");
             }
 
-            service.getOrCreateTopic(topicName.toString()).thenCompose((Topic 
topic) -> {
+            boolean createTopicIfDoesNotExist = isAuthorizedToCreateTopic
+                    && service.isAllowAutoTopicCreation(topicName.toString());
+            service.getTopic(topicName.toString(), 
createTopicIfDoesNotExist).thenCompose(optTopic -> {
+                if (optTopic.isEmpty()) {
+                    if (isAuthorizedToCreateTopic) {
+                        return FutureUtil
+                                .failedFuture(new TopicNotFoundException(
+                                        "Topic " + topicName + " does not 
exist"));
+                    } else {
+                        String msg = "Topic to produce does not exists and the 
Client is not"
+                                + " authorized to create topic";
+                        log.warn("[{}] {} with role {}", remoteAddress, msg, 
getPrincipal());
+                        ctx.writeAndFlush(Commands.newError(requestId, 
ServerError.AuthorizationError,
+                                msg));
+                        return null;

Review Comment:
   See previous thread.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to