@@ -221,8 +221,16 @@ protected CompletableFuture<List<String>> internalGetPartitionedTopicListAsync()
221221
222222 protected CompletableFuture <Map <String , Set <AuthAction >>> internalGetPermissionsOnTopic () {
223223 // This operation should be reading from zookeeper and it should be allowed without having admin privileges
224- return validateAdminAccessForTenantAsync (namespaceName .getTenant ())
225- .thenCompose (__ -> internalCheckTopicExists (topicName ))
224+ CompletableFuture <Void > validateAccessForTenantCf =
225+ validateAdminAccessForTenantAsync (namespaceName .getTenant ());
226+
227+ var checkIfTopicExists = !pulsar ().getConfiguration ().isAllowAclChangesOnNonExistentTopics ();
228+ if (checkIfTopicExists ) {
229+ validateAccessForTenantCf = validateAccessForTenantCf
230+ .thenCompose (__ -> internalCheckTopicExists (topicName ));
231+ }
232+
233+ return validateAccessForTenantCf
226234 .thenCompose (__ -> getAuthorizationService ().getPermissionsAsync (topicName ));
227235 }
228236
@@ -273,9 +281,16 @@ private CompletableFuture<Void> grantPermissionsAsync(TopicName topicUri, String
273281 protected void internalGrantPermissionsOnTopic (final AsyncResponse asyncResponse , String role ,
274282 Set <AuthAction > actions ) {
275283 // This operation should be reading from zookeeper and it should be allowed without having admin privileges
276- validateAdminAccessForTenantAsync (namespaceName .getTenant ())
277- .thenCompose (__ -> validatePoliciesReadOnlyAccessAsync ())
278- .thenCompose (__ -> internalCheckTopicExists (topicName ))
284+ CompletableFuture <Void > validateAccessForTenantCf = validateAdminAccessForTenantAsync (namespaceName .getTenant ())
285+ .thenCompose (__ -> validatePoliciesReadOnlyAccessAsync ());
286+
287+ var checkIfTopicExists = !pulsar ().getConfiguration ().isAllowAclChangesOnNonExistentTopics ();
288+ if (checkIfTopicExists ) {
289+ validateAccessForTenantCf = validateAccessForTenantCf
290+ .thenCompose (__ -> internalCheckTopicExists (topicName ));
291+ }
292+
293+ validateAccessForTenantCf
279294 .thenCompose (unused1 -> grantPermissionsAsync (topicName , role , actions ))
280295 .thenAccept (unused -> asyncResponse .resume (Response .noContent ().build ()))
281296 .exceptionally (ex -> {
@@ -288,9 +303,17 @@ protected void internalGrantPermissionsOnTopic(final AsyncResponse asyncResponse
288303
289304 protected void internalRevokePermissionsOnTopic (AsyncResponse asyncResponse , String role ) {
290305 // This operation should be reading from zookeeper and it should be allowed without having admin privileges
291- validateAdminAccessForTenantAsync (namespaceName .getTenant ())
292- .thenCompose (__ -> validatePoliciesReadOnlyAccessAsync ())
293- .thenCompose (__ -> internalCheckTopicExists (topicName ))
306+ CompletableFuture <Void > validateAccessForTenantCf =
307+ validateAdminAccessForTenantAsync (namespaceName .getTenant ())
308+ .thenCompose (__ -> validatePoliciesReadOnlyAccessAsync ());
309+
310+ var checkIfTopicExists = !pulsar ().getConfiguration ().isAllowAclChangesOnNonExistentTopics ();
311+ if (checkIfTopicExists ) {
312+ validateAccessForTenantCf = validateAccessForTenantCf
313+ .thenCompose (__ -> internalCheckTopicExists (topicName ));
314+ }
315+
316+ validateAccessForTenantCf
294317 .thenCompose (unused1 -> getPartitionedTopicMetadataAsync (topicName , true , false )
295318 .thenCompose (metadata -> {
296319 int numPartitions = metadata .partitions ;
0 commit comments