From 8ed8e7e21938588466aa78ce5d2dfda63c763f7f Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Tue, 10 Jan 2023 21:49:19 -0600 Subject: [PATCH 1/4] [cleanup][broker] Remove AuthorizationProvider methods deprecated in 2.7 --- .../authorization/AuthorizationProvider.java | 152 ------------------ .../auth/MockAuthorizationProvider.java | 69 -------- 2 files changed, 221 deletions(-) diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java index 9adc212019d63..1b84f0d089124 100644 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java +++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import org.apache.commons.lang3.StringUtils; import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.broker.authentication.AuthenticationDataSource; import org.apache.pulsar.broker.cache.ConfigurationCacheService; @@ -246,39 +245,6 @@ CompletableFuture revokeSubscriptionPermissionAsync(NamespaceName namespac CompletableFuture grantPermissionAsync(TopicName topicName, Set actions, String role, String authDataJson); - /** - * Grant authorization-action permission on a tenant to the given client. - * @param tenantName - * @param originalRole role not overriden by proxy role if request do pass through proxy - * @param role originalRole | proxyRole if the request didn't pass through proxy - * @param operation - * @param authData - * @return CompletableFuture - */ - @Deprecated - default CompletableFuture allowTenantOperationAsync(String tenantName, String originalRole, String role, - TenantOperation operation, - AuthenticationDataSource authData) { - return allowTenantOperationAsync( - tenantName, - StringUtils.isBlank(originalRole) ? role : originalRole, - operation, - authData - ); - } - - @Deprecated - default Boolean allowTenantOperation(String tenantName, String originalRole, String role, TenantOperation operation, - AuthenticationDataSource authData) { - try { - return allowTenantOperationAsync(tenantName, originalRole, role, operation, authData).get(); - } catch (InterruptedException e) { - throw new RestException(e); - } catch (ExecutionException e) { - throw new RestException(e.getCause()); - } - } - /** * Check if a given role is allowed to execute a given operation on the tenant. * @@ -339,44 +305,6 @@ default Boolean allowNamespaceOperation(NamespaceName namespaceName, } } - /** - * Grant authorization-action permission on a namespace to the given client. - * - * @param namespaceName - * @param role - * @param operation - * @param authData - * @return CompletableFuture - */ - @Deprecated - default CompletableFuture allowNamespaceOperationAsync(NamespaceName namespaceName, - String originalRole, - String role, - NamespaceOperation operation, - AuthenticationDataSource authData) { - return allowNamespaceOperationAsync( - namespaceName, - StringUtils.isBlank(originalRole) ? role : originalRole, - operation, - authData - ); - } - - @Deprecated - default Boolean allowNamespaceOperation(NamespaceName namespaceName, - String originalRole, - String role, - NamespaceOperation operation, - AuthenticationDataSource authData) { - try { - return allowNamespaceOperationAsync(namespaceName, originalRole, role, operation, authData).get(); - } catch (InterruptedException e) { - throw new RestException(e); - } catch (ExecutionException e) { - throw new RestException(e.getCause()); - } - } - /** * Check if a given role is allowed to execute a given policy operation on the namespace. * @@ -411,48 +339,6 @@ default Boolean allowNamespacePolicyOperation(NamespaceName namespaceName, } } - /** - * Grant authorization-action permission on a namespace to the given client. - * @param namespaceName - * @param originalRole role not overriden by proxy role if request do pass through proxy - * @param role originalRole | proxyRole if the request didn't pass through proxy - * @param operation - * @param authData - * @return CompletableFuture - */ - @Deprecated - default CompletableFuture allowNamespacePolicyOperationAsync(NamespaceName namespaceName, - PolicyName policy, - PolicyOperation operation, - String originalRole, - String role, - AuthenticationDataSource authData) { - return allowNamespacePolicyOperationAsync( - namespaceName, - policy, - operation, - StringUtils.isBlank(originalRole) ? role : originalRole, - authData - ); - } - - @Deprecated - default Boolean allowNamespacePolicyOperation(NamespaceName namespaceName, - PolicyName policy, - PolicyOperation operation, - String originalRole, - String role, - AuthenticationDataSource authData) { - try { - return allowNamespacePolicyOperationAsync( - namespaceName, policy, operation, originalRole, role, authData).get(); - } catch (InterruptedException e) { - throw new RestException(e); - } catch (ExecutionException e) { - throw new RestException(e.getCause()); - } - } - /** * Check if a given role is allowed to execute a given topic operation on the topic. * @@ -484,44 +370,6 @@ default Boolean allowTopicOperation(TopicName topicName, } } - /** - * Grant authorization-action permission on a topic to the given client. - * @param topic - * @param originalRole role not overriden by proxy role if request do pass through proxy - * @param role originalRole | proxyRole if the request didn't pass through proxy - * @param operation - * @param authData - * @return CompletableFuture - */ - @Deprecated - default CompletableFuture allowTopicOperationAsync(TopicName topic, - String originalRole, - String role, - TopicOperation operation, - AuthenticationDataSource authData) { - return allowTopicOperationAsync( - topic, - StringUtils.isBlank(originalRole) ? role : originalRole, - operation, - authData - ); - } - - @Deprecated - default Boolean allowTopicOperation(TopicName topicName, - String originalRole, - String role, - TopicOperation operation, - AuthenticationDataSource authData) { - try { - return allowTopicOperationAsync(topicName, originalRole, role, operation, authData).get(); - } catch (InterruptedException e) { - throw new RestException(e); - } catch (ExecutionException e) { - throw new RestException(e.getCause()); - } - } - /** * Check if a given role is allowed to execute a given topic operation on topic's policy. * diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockAuthorizationProvider.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockAuthorizationProvider.java index d8c884f353b01..1b2a6322cba3d 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockAuthorizationProvider.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockAuthorizationProvider.java @@ -121,19 +121,6 @@ public CompletableFuture grantPermissionAsync(TopicName topicName, Set allowTenantOperationAsync(String tenantName, String originalRole, String role, - TenantOperation operation, - AuthenticationDataSource authData) { - return roleAuthorizedAsync(role); - } - - @Override - public Boolean allowTenantOperation(String tenantName, String originalRole, String role, TenantOperation operation, - AuthenticationDataSource authData) { - return roleAuthorized(role); - } - @Override public CompletableFuture allowTenantOperationAsync(String tenantName, String role, TenantOperation operation, @@ -164,47 +151,10 @@ public Boolean allowNamespaceOperation(NamespaceName namespaceName, } - @Override - public CompletableFuture allowNamespaceOperationAsync(NamespaceName namespaceName, - String originalRole, - String role, - NamespaceOperation operation, - AuthenticationDataSource authData) { - return roleAuthorizedAsync(role); - } - - @Override - public Boolean allowNamespaceOperation(NamespaceName namespaceName, - String originalRole, - String role, - NamespaceOperation operation, - AuthenticationDataSource authData) { - return roleAuthorized(role); - } - - @Override - public CompletableFuture allowNamespacePolicyOperationAsync(NamespaceName namespaceName, - PolicyName policy, - PolicyOperation operation, - String role, - AuthenticationDataSource authData) { - return roleAuthorizedAsync(role); - } - - @Override - public Boolean allowNamespacePolicyOperation(NamespaceName namespaceName, - PolicyName policy, - PolicyOperation operation, - String role, - AuthenticationDataSource authData) { - return roleAuthorized(role); - } - @Override public CompletableFuture allowNamespacePolicyOperationAsync(NamespaceName namespaceName, PolicyName policy, PolicyOperation operation, - String originalRole, String role, AuthenticationDataSource authData) { return roleAuthorizedAsync(role); @@ -214,7 +164,6 @@ public CompletableFuture allowNamespacePolicyOperationAsync(NamespaceNa public Boolean allowNamespacePolicyOperation(NamespaceName namespaceName, PolicyName policy, PolicyOperation operation, - String originalRole, String role, AuthenticationDataSource authData) { return roleAuthorized(role); @@ -236,24 +185,6 @@ public Boolean allowTopicOperation(TopicName topicName, return roleAuthorized(role); } - @Override - public CompletableFuture allowTopicOperationAsync(TopicName topic, - String originalRole, - String role, - TopicOperation operation, - AuthenticationDataSource authData) { - return roleAuthorizedAsync(role); - } - - @Override - public Boolean allowTopicOperation(TopicName topicName, - String originalRole, - String role, - TopicOperation operation, - AuthenticationDataSource authData) { - return roleAuthorized(role); - } - CompletableFuture roleAuthorizedAsync(String role) { CompletableFuture promise = new CompletableFuture<>(); try { From 93505b074601950257f5e6eb57308879efe08240 Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Tue, 10 Jan 2023 22:26:41 -0600 Subject: [PATCH 2/4] [cleanup][broker] Remove AuthorizationProvider#initialize deprecated in 2.9 --- .../authorization/AuthorizationProvider.java | 20 ------------------- .../PulsarAuthorizationProvider.java | 3 --- 2 files changed, 23 deletions(-) diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java index 1b84f0d089124..80f74501816f1 100644 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java +++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java @@ -25,7 +25,6 @@ import java.util.concurrent.ExecutionException; import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.broker.authentication.AuthenticationDataSource; -import org.apache.pulsar.broker.cache.ConfigurationCacheService; import org.apache.pulsar.broker.resources.PulsarResources; import org.apache.pulsar.common.naming.NamespaceName; import org.apache.pulsar.common.naming.TopicName; @@ -85,23 +84,6 @@ default CompletableFuture isTenantAdmin(String tenant, String role, Ten && tenantInfo.getAdminRoles().contains(role)); } - /** - * Perform initialization for the authorization provider. - * - * @param conf - * broker config object - * @param configCache - * pulsar zk configuration cache service - * @throws IOException - * if the initialization fails - * - * @deprecated ConfigurationCacheService is not supported anymore as a way to get access to metadata. - * @see #initialize(ServiceConfiguration, PulsarResources) - */ - @Deprecated - default void initialize(ServiceConfiguration conf, ConfigurationCacheService configCache) throws IOException { - } - /** * Perform initialization for the authorization provider. * @@ -113,8 +95,6 @@ default void initialize(ServiceConfiguration conf, ConfigurationCacheService con * if the initialization fails */ default void initialize(ServiceConfiguration conf, PulsarResources pulsarResources) throws IOException { - // For compatibility, call the old deprecated initialize - initialize(conf, (ConfigurationCacheService) null); } /** diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java index a43591dd1d94f..95b38ca11dc20 100644 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java +++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java @@ -72,9 +72,6 @@ public void initialize(ServiceConfiguration conf, PulsarResources pulsarResource requireNonNull(pulsarResources, "PulsarResources can't be null"); this.conf = conf; this.pulsarResources = pulsarResources; - - // For compatibility, call the old deprecated initialize - initialize(conf, (ConfigurationCacheService) null); } /** From 58058b1a1676649c96d0f943189238b73f100f5b Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Tue, 10 Jan 2023 22:32:17 -0600 Subject: [PATCH 3/4] Remove unused import --- .../pulsar/broker/authorization/PulsarAuthorizationProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java index 95b38ca11dc20..ce6c07f40c124 100644 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java +++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java @@ -30,7 +30,6 @@ import org.apache.pulsar.broker.PulsarServerException; import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.broker.authentication.AuthenticationDataSource; -import org.apache.pulsar.broker.cache.ConfigurationCacheService; import org.apache.pulsar.broker.resources.PulsarResources; import org.apache.pulsar.common.naming.NamespaceName; import org.apache.pulsar.common.naming.TopicName; From bd9483517c554bcfe3b1cbcfbd4fea755a344660 Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Tue, 10 Jan 2023 22:32:59 -0600 Subject: [PATCH 4/4] [cleanup][broker] Remove unused, deprecated ConfigurationCacheService --- .../cache/ConfigurationCacheService.java | 26 ------------------- .../pulsar/broker/cache/package-info.java | 22 ---------------- .../BacklogQuotaManagerConfigurationTest.java | 2 -- .../pulsar/broker/service/ServerCnxTest.java | 2 -- 4 files changed, 52 deletions(-) delete mode 100644 pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/ConfigurationCacheService.java delete mode 100644 pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/package-info.java diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/ConfigurationCacheService.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/ConfigurationCacheService.java deleted file mode 100644 index 7fc9ea8d3f1a2..0000000000000 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/ConfigurationCacheService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.pulsar.broker.cache; - -/** - * ConfigurationCacheService is only kept for compatibility as it was exposed in AuthorizationProvider interface. - */ -@Deprecated -public class ConfigurationCacheService { -} diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/package-info.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/package-info.java deleted file mode 100644 index 5d8fe448344ef..0000000000000 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/cache/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * Pulsar Client API. - */ -package org.apache.pulsar.broker.cache; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BacklogQuotaManagerConfigurationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BacklogQuotaManagerConfigurationTest.java index f55489368834e..eec04beeeeb9f 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BacklogQuotaManagerConfigurationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BacklogQuotaManagerConfigurationTest.java @@ -20,7 +20,6 @@ import org.apache.pulsar.broker.PulsarService; import org.apache.pulsar.broker.ServiceConfiguration; -import org.apache.pulsar.broker.cache.ConfigurationCacheService; import org.apache.pulsar.broker.resources.PulsarResources; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -78,7 +77,6 @@ private void initializeServiceConfiguration() { private PulsarService getPulsarService() { PulsarService pulsarService = mock(PulsarService.class); - ConfigurationCacheService configurationCacheService = mock(ConfigurationCacheService.class); when(pulsarService.getConfiguration()).thenReturn(serviceConfiguration); when(pulsarService.getPulsarResources()).thenReturn(mock(PulsarResources.class)); return pulsarService; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java index 97b58d99e3d20..3e998bd6741b8 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java @@ -82,7 +82,6 @@ import org.apache.pulsar.broker.authentication.AuthenticationState; import org.apache.pulsar.broker.authorization.AuthorizationService; import org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider; -import org.apache.pulsar.broker.cache.ConfigurationCacheService; import org.apache.pulsar.broker.intercept.BrokerInterceptor; import org.apache.pulsar.broker.namespace.NamespaceService; import org.apache.pulsar.broker.resources.NamespaceResources; @@ -151,7 +150,6 @@ public class ServerCnxTest { private ClientChannelHelper clientChannelHelper; private PulsarService pulsar; private MetadataStoreExtended store; - private ConfigurationCacheService configCacheService; private NamespaceResources namespaceResources; protected NamespaceService namespaceService; private final int currentProtocolVersion = ProtocolVersion.values()[ProtocolVersion.values().length - 1]