You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2023/04/09 00:12:57 UTC
[pulsar] branch branch-2.9 updated: [refactor][fn] Use AuthorizationServer more in Function Worker API (#19975)
This is an automated email from the ASF dual-hosted git repository.
mmarshall pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.9 by this push:
new 012c726b877 [refactor][fn] Use AuthorizationServer more in Function Worker API (#19975)
012c726b877 is described below
commit 012c726b877dbd92d68105e578f96c51e776db9c
Author: Michael Marshall <mm...@apache.org>
AuthorDate: Sat Apr 8 00:49:09 2023 -0500
[refactor][fn] Use AuthorizationServer more in Function Worker API (#19975)
The current function worker interfaces introduced by #8560 are hard to extend. It is better to pass an object that we can add fields to as needed.
* Introduce a new `Authentication` class to wrap all of the relevant authentication "data". This class is somewhat unfortunate in that we already have many classes that hold authentication information. However, my goal with this class is to wrap all of the relevant auth info. This class is only currently used in the Function Worker API, but I plan to add it to the rest of the Admin HTTP endpoints.
* Deprecate all of the methods that are no longer needed. Add a default implementation to call the new methods that supersede those methods.
* Add `proxyRoles` setting to function worker.
There are tests to cover the changes.
This PR changes several interfaces in completely backwards compatible ways. It's possible we'll want to improve the abstraction for the `Authentication` class by making it an interface.
- [x] `doc`
This change has Javadoc updates to document the changes.
PR in forked repository: https://github.com/michaeljmarshall/pulsar/pull/37
(cherry picked from commit 55acbe6cef2a0fbd356ad7d085c87e398b7c69db)
(cherry picked from commit 54c97adfcde183a93a9a67b2b2be0ccec4a82b36)
(cherry picked from commit cf4092664e50c08a53c1fb68c3a29ca53e13695c)
---
conf/functions_worker.yml | 2 +
.../authentication/AuthenticationParameters.java | 67 ++++
.../broker/authorization/AuthorizationService.java | 129 +++++-
.../org/apache/pulsar/broker/PulsarService.java | 1 +
.../pulsar/broker/admin/impl/BrokerStatsBase.java | 1 +
.../pulsar/broker/admin/impl/FunctionsBase.java | 44 +--
.../apache/pulsar/broker/admin/impl/SinksBase.java | 28 +-
.../pulsar/broker/admin/impl/SourcesBase.java | 29 +-
.../apache/pulsar/broker/admin/v2/Functions.java | 31 +-
.../org/apache/pulsar/broker/admin/v2/Worker.java | 20 +-
.../apache/pulsar/broker/admin/v2/WorkerStats.java | 4 +-
.../pulsar/broker/web/PulsarWebResource.java | 9 +
.../pulsar/functions/worker/WorkerConfig.java | 6 +
.../src/test/resources/test_worker_config.yml | 3 +
.../functions/worker/rest/FunctionApiResource.java | 18 +
.../functions/worker/rest/api/ComponentImpl.java | 432 +++++++++------------
.../functions/worker/rest/api/FunctionsImpl.java | 101 ++---
.../functions/worker/rest/api/FunctionsImplV2.java | 79 ++--
.../functions/worker/rest/api/SinksImpl.java | 100 ++---
.../functions/worker/rest/api/SourcesImpl.java | 100 ++---
.../functions/worker/rest/api/WorkerImpl.java | 136 +++----
.../worker/rest/api/v2/FunctionsApiV2Resource.java | 37 +-
.../worker/rest/api/v2/WorkerApiV2Resource.java | 36 +-
.../rest/api/v2/WorkerStatsApiV2Resource.java | 20 +-
.../worker/rest/api/v3/FunctionsApiV3Resource.java | 50 +--
.../worker/rest/api/v3/SinksApiV3Resource.java | 32 +-
.../worker/rest/api/v3/SourcesApiV3Resource.java | 34 +-
.../functions/worker/service/api/Component.java | 165 +++-----
.../functions/worker/service/api/Functions.java | 97 +++--
.../functions/worker/service/api/FunctionsV2.java | 55 ++-
.../pulsar/functions/worker/service/api/Sinks.java | 91 +++--
.../functions/worker/service/api/Sources.java | 93 +++--
.../functions/worker/service/api/Workers.java | 22 +-
.../pulsar/functions/worker/WorkerUtilsTest.java | 14 +
.../worker/rest/api/FunctionsImplTest.java | 181 +++++----
.../functions/worker/rest/api/WorkerImplTest.java | 118 ++++++
.../rest/api/v2/FunctionApiV2ResourceTest.java | 49 ++-
.../rest/api/v3/FunctionApiV3ResourceTest.java | 36 +-
.../worker/rest/api/v3/SinkApiV3ResourceTest.java | 33 +-
.../rest/api/v3/SourceApiV3ResourceTest.java | 34 +-
40 files changed, 1403 insertions(+), 1134 deletions(-)
diff --git a/conf/functions_worker.yml b/conf/functions_worker.yml
index a0449cbb236..16bddca1b30 100644
--- a/conf/functions_worker.yml
+++ b/conf/functions_worker.yml
@@ -285,6 +285,8 @@ authenticationProviders:
authorizationProvider: org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider
# Set of role names that are treated as "super-user", meaning they will be able to access any admin-api
superUserRoles:
+# Set of role names that are treated as "proxy" roles. These are the roles that can supply the originalPrincipal.
+proxyRoles:
#### tls configuration for worker service
# Enable TLS
diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationParameters.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationParameters.java
new file mode 100644
index 00000000000..b954090405f
--- /dev/null
+++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationParameters.java
@@ -0,0 +1,67 @@
+/**
+ * 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.authentication;
+
+import lombok.Builder;
+
+/**
+ * A class to collect all the common fields used for authentication. Because the authentication data source is
+ * not always consistent when using the Pulsar Protocol and the Pulsar Proxy
+ * (see <a href="https://github.com/apache/pulsar/issues/19332">19332</a>), this class is currently restricted
+ * to use only in authenticating HTTP requests.
+ */
+@Builder
+@lombok.Value
+public class AuthenticationParameters {
+
+ /**
+ * The original principal (or role) of the client.
+ * <p>
+ * For HTTP Authentication, there are two possibilities. When the client connects directly to the broker, this
+ * field is null (assuming the client hasn't supplied the original principal header). When the client connects
+ * through the proxy, the proxy calculates the original principal based on the client's authentication data and
+ * supplies it in this field.
+ * </p>
+ */
+ String originalPrincipal;
+
+ /**
+ * The client role.
+ * <p>
+ * For HTTP Authentication, there are three possibilities. When the client connects directly to the broker, this
+ * is the client's role. When the client connects through the proxy using mTLS, this is the role of the proxy.
+ * In this case, the {@link #originalPrincipal} is also supplied and is the role of the original client as
+ * determined by the proxy. When the client connects through the proxy using any other form of authentication,
+ * this is the role of the original client. In this case, the {@link #originalPrincipal} is also the role of
+ * the original client.
+ * </p>
+ */
+ String clientRole;
+
+ /**
+ * The authentication data source used to generate the {@link #clientRole}.
+ * <p>
+ * For HTTP Authentication, there are three possibilities. When the client connects directly to the broker, this
+ * is the client's {@link AuthenticationDataSource}. When the client connects through the proxy using mTLS, this
+ * is the proxy's {@link AuthenticationDataSource}. When the client connects through the proxy using any other
+ * form of authentication, this is the original client's {@link AuthenticationDataSource}.
+ * </p>
+ */
+ AuthenticationDataSource clientAuthenticationDataSource;
+}
diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationService.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationService.java
index ccb7beb2ddc..cbe1ec2df1b 100644
--- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationService.java
+++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationService.java
@@ -28,6 +28,7 @@ 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.authentication.AuthenticationParameters;
import org.apache.pulsar.broker.resources.PulsarResources;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.naming.TopicName;
@@ -55,6 +56,7 @@ public class AuthorizationService {
private static final Logger log = LoggerFactory.getLogger(AuthorizationService.class);
private AuthorizationProvider provider;
+ private final PulsarResources resources;
private final ServiceConfiguration conf;
public AuthorizationService(ServiceConfiguration conf, PulsarResources pulsarResources)
@@ -66,6 +68,7 @@ public class AuthorizationService {
provider = (AuthorizationProvider) Class.forName(providerClassname)
.getDeclaredConstructor().newInstance();
provider.initialize(conf, pulsarResources);
+ this.resources = pulsarResources;
log.info("{} has been loaded.", providerClassname);
} else {
throw new PulsarServerException("No authorization providers are present.");
@@ -77,6 +80,23 @@ public class AuthorizationService {
}
}
+ public CompletableFuture<Boolean> isSuperUser(AuthenticationParameters authParams) {
+ if (!isValidOriginalPrincipal(authParams)) {
+ return CompletableFuture.completedFuture(false);
+ }
+ if (isProxyRole(authParams.getClientRole())) {
+ CompletableFuture<Boolean> isRoleAuthorizedFuture = isSuperUser(authParams.getClientRole(),
+ authParams.getClientAuthenticationDataSource());
+ // The current paradigm is to pass the client auth data when we don't have access to the original auth data.
+ CompletableFuture<Boolean> isOriginalAuthorizedFuture = isSuperUser(authParams.getOriginalPrincipal(),
+ authParams.getClientAuthenticationDataSource());
+ return isRoleAuthorizedFuture.thenCombine(isOriginalAuthorizedFuture,
+ (isRoleAuthorized, isOriginalAuthorized) -> isRoleAuthorized && isOriginalAuthorized);
+ } else {
+ return isSuperUser(authParams.getClientRole(), authParams.getClientAuthenticationDataSource());
+ }
+ }
+
public CompletableFuture<Boolean> isSuperUser(String user, AuthenticationDataSource authenticationData) {
if (provider != null) {
return provider.isSuperUser(user, authenticationData, conf);
@@ -312,17 +332,120 @@ public class AuthorizationService {
public CompletableFuture<Boolean> allowFunctionOpsAsync(NamespaceName namespaceName, String role,
AuthenticationDataSource authenticationData) {
- return provider.allowFunctionOpsAsync(namespaceName, role, authenticationData);
+ return isSuperUserOrAdmin(namespaceName, role, authenticationData)
+ .thenCompose(isSuperUserOrAdmin -> isSuperUserOrAdmin
+ ? CompletableFuture.completedFuture(true)
+ : provider.allowFunctionOpsAsync(namespaceName, role, authenticationData)
+ );
+ }
+
+ public CompletableFuture<Boolean> allowFunctionOpsAsync(NamespaceName namespaceName,
+ AuthenticationParameters authParams) {
+ if (!isValidOriginalPrincipal(authParams)) {
+ return CompletableFuture.completedFuture(false);
+ }
+ if (isProxyRole(authParams.getClientRole())) {
+ CompletableFuture<Boolean> isRoleAuthorizedFuture = allowFunctionOpsAsync(namespaceName,
+ authParams.getClientRole(), authParams.getClientAuthenticationDataSource());
+ // The current paradigm is to pass the client auth data when we don't have access to the original auth data.
+ CompletableFuture<Boolean> isOriginalAuthorizedFuture = allowFunctionOpsAsync(
+ namespaceName, authParams.getOriginalPrincipal(), authParams.getClientAuthenticationDataSource());
+ return isRoleAuthorizedFuture.thenCombine(isOriginalAuthorizedFuture,
+ (isRoleAuthorized, isOriginalAuthorized) -> isRoleAuthorized && isOriginalAuthorized);
+ } else {
+ return allowFunctionOpsAsync(namespaceName, authParams.getClientRole(),
+ authParams.getClientAuthenticationDataSource());
+ }
}
public CompletableFuture<Boolean> allowSourceOpsAsync(NamespaceName namespaceName, String role,
AuthenticationDataSource authenticationData) {
- return provider.allowSourceOpsAsync(namespaceName, role, authenticationData);
+ return isSuperUserOrAdmin(namespaceName, role, authenticationData)
+ .thenCompose(isSuperUserOrAdmin -> isSuperUserOrAdmin
+ ? CompletableFuture.completedFuture(true)
+ : provider.allowSourceOpsAsync(namespaceName, role, authenticationData)
+ );
+ }
+
+ public CompletableFuture<Boolean> allowSourceOpsAsync(NamespaceName namespaceName,
+ AuthenticationParameters authParams) {
+ if (!isValidOriginalPrincipal(authParams)) {
+ return CompletableFuture.completedFuture(false);
+ }
+ if (isProxyRole(authParams.getClientRole())) {
+ CompletableFuture<Boolean> isRoleAuthorizedFuture = allowSourceOpsAsync(namespaceName,
+ authParams.getClientRole(), authParams.getClientAuthenticationDataSource());
+ // The current paradigm is to pass the client auth data when we don't have access to the original auth data.
+ CompletableFuture<Boolean> isOriginalAuthorizedFuture = allowSourceOpsAsync(
+ namespaceName, authParams.getOriginalPrincipal(), authParams.getClientAuthenticationDataSource());
+ return isRoleAuthorizedFuture.thenCombine(isOriginalAuthorizedFuture,
+ (isRoleAuthorized, isOriginalAuthorized) -> isRoleAuthorized && isOriginalAuthorized);
+ } else {
+ return allowSourceOpsAsync(namespaceName, authParams.getClientRole(),
+ authParams.getClientAuthenticationDataSource());
+ }
}
public CompletableFuture<Boolean> allowSinkOpsAsync(NamespaceName namespaceName, String role,
AuthenticationDataSource authenticationData) {
- return provider.allowSinkOpsAsync(namespaceName, role, authenticationData);
+ return isSuperUserOrAdmin(namespaceName, role, authenticationData)
+ .thenCompose(isSuperUserOrAdmin -> isSuperUserOrAdmin
+ ? CompletableFuture.completedFuture(true)
+ : provider.allowSinkOpsAsync(namespaceName, role, authenticationData)
+ );
+ }
+
+ public CompletableFuture<Boolean> allowSinkOpsAsync(NamespaceName namespaceName,
+ AuthenticationParameters authParams) {
+ if (!isValidOriginalPrincipal(authParams)) {
+ return CompletableFuture.completedFuture(false);
+ }
+ if (isProxyRole(authParams.getClientRole())) {
+ CompletableFuture<Boolean> isRoleAuthorizedFuture = allowSinkOpsAsync(namespaceName,
+ authParams.getClientRole(), authParams.getClientAuthenticationDataSource());
+ // The current paradigm is to pass the client auth data when we don't have access to the original auth data.
+ CompletableFuture<Boolean> isOriginalAuthorizedFuture = allowSinkOpsAsync(
+ namespaceName, authParams.getOriginalPrincipal(), authParams.getClientAuthenticationDataSource());
+ return isRoleAuthorizedFuture.thenCombine(isOriginalAuthorizedFuture,
+ (isRoleAuthorized, isOriginalAuthorized) -> isRoleAuthorized && isOriginalAuthorized);
+ } else {
+ return allowSinkOpsAsync(namespaceName, authParams.getClientRole(),
+ authParams.getClientAuthenticationDataSource());
+ }
+ }
+
+ /**
+ * Functions, sources, and sinks each have their own method in this class. This method first checks for
+ * tenant admin access, then for namespace level permission.
+ */
+ private CompletableFuture<Boolean> isSuperUserOrAdmin(NamespaceName namespaceName,
+ String role,
+ AuthenticationDataSource authenticationData) {
+ return isSuperUser(role, authenticationData)
+ .thenCompose(isSuperUserOrAdmin -> isSuperUserOrAdmin
+ ? CompletableFuture.completedFuture(true)
+ : isTenantAdmin(namespaceName.getTenant(), role, authenticationData));
+ }
+
+ private CompletableFuture<Boolean> isTenantAdmin(String tenant, String role,
+ AuthenticationDataSource authData) {
+ return resources.getTenantResources()
+ .getTenantAsync(tenant)
+ .thenCompose(op -> {
+ if (op.isPresent()) {
+ return isTenantAdmin(tenant, role, op.get(), authData);
+ } else {
+ CompletableFuture<Boolean> future = new CompletableFuture<>();
+ future.completeExceptionally(new RestException(Response.Status.NOT_FOUND,
+ "Tenant does not exist"));
+ return future;
+ }
+ });
+ }
+
+ private boolean isValidOriginalPrincipal(AuthenticationParameters authParams) {
+ return isValidOriginalPrincipal(authParams.getClientRole(),
+ authParams.getOriginalPrincipal(), authParams.getClientAuthenticationDataSource());
}
/**
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
index 38e8f34ab46..3d324b5491a 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
@@ -1723,6 +1723,7 @@ public class PulsarService implements AutoCloseable, ShutdownService {
// inherit super users
workerConfig.setSuperUserRoles(brokerConfig.getSuperUserRoles());
+ workerConfig.setProxyRoles(brokerConfig.getProxyRoles());
// inherit the nar package locations
if (isBlank(workerConfig.getFunctionsWorkerServiceNarPackage())) {
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
index e92b4dccf67..3e6a9e552f5 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
@@ -159,6 +159,7 @@ public class BrokerStatsBase extends AdminResource {
protected Map<Long, Collection<ResourceUnit>> internalBrokerResourceAvailability(NamespaceName namespace) {
try {
+ validateSuperUserAccess();
LoadManager lm = pulsar().getLoadManager().get();
if (lm instanceof SimpleLoadManagerImpl) {
return ((SimpleLoadManagerImpl) lm).getResourceAvailabilityFor(namespace).asMap();
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/FunctionsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/FunctionsBase.java
index 401553a4e56..20fe7e8a5ef 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/FunctionsBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/FunctionsBase.java
@@ -181,7 +181,7 @@ public class FunctionsBase extends AdminResource {
final @FormDataParam("functionConfig") FunctionConfig functionConfig) {
functions().registerFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionConfig, clientAppId(), clientAuthData());
+ functionPkgUrl, functionConfig, authParams());
}
@PUT
@@ -307,7 +307,7 @@ public class FunctionsBase extends AdminResource {
final @FormDataParam("updateOptions") UpdateOptionsImpl updateOptions) throws IOException {
functions().updateFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionConfig, clientAppId(), clientAuthData(), updateOptions);
+ functionPkgUrl, functionConfig, authParams(), updateOptions);
}
@@ -328,7 +328,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) {
- functions().deregisterFunction(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().deregisterFunction(tenant, namespace, functionName, authParams());
}
@GET
@@ -350,7 +350,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) throws IOException {
- return functions().getFunctionInfo(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ return functions().getFunctionInfo(tenant, namespace, functionName, authParams());
}
@GET
@@ -374,7 +374,7 @@ public class FunctionsBase extends AdminResource {
+ " the stats of all instances is returned") final @PathParam("instanceId")
String instanceId) throws IOException {
return functions().getFunctionInstanceStatus(tenant, namespace, functionName,
- instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ instanceId, uri.getRequestUri(), authParams());
}
@GET
@@ -398,7 +398,7 @@ public class FunctionsBase extends AdminResource {
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) throws IOException {
return functions().getFunctionStatus(tenant, namespace, functionName, uri.getRequestUri(),
- clientAppId(), clientAuthData());
+ authParams());
}
@GET
@@ -422,7 +422,7 @@ public class FunctionsBase extends AdminResource {
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) throws IOException {
return functions().getFunctionStats(tenant, namespace, functionName,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@GET
@@ -446,7 +446,7 @@ public class FunctionsBase extends AdminResource {
+ " (if instance-id is not provided, the stats of all instances is returned") final @PathParam(
"instanceId") String instanceId) throws IOException {
return functions().getFunctionsInstanceStats(tenant, namespace, functionName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@GET
@@ -465,7 +465,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("tenant") String tenant,
@ApiParam(value = "The namespace of a Pulsar Function")
final @PathParam("namespace") String namespace) {
- return functions().listFunctions(tenant, namespace, clientAppId(), clientAuthData());
+ return functions().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -494,7 +494,7 @@ public class FunctionsBase extends AdminResource {
+ " consumes from which you want to inject the data to") final @FormDataParam("topic")
String topic) {
return functions().triggerFunction(tenant, namespace, functionName, triggerValue,
- triggerStream, topic, clientAppId(), clientAuthData());
+ triggerStream, topic, authParams());
}
@GET
@@ -518,7 +518,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("functionName") String functionName,
@ApiParam(value = "The stats key")
final @PathParam("key") String key) {
- return functions().getFunctionState(tenant, namespace, functionName, key, clientAppId(), clientAuthData());
+ return functions().getFunctionState(tenant, namespace, functionName, key, authParams());
}
@POST
@@ -538,7 +538,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("functionName") String functionName,
final @PathParam("key") String key,
final @FormDataParam("state") FunctionState stateJson) {
- functions().putFunctionState(tenant, namespace, functionName, key, stateJson, clientAppId(), clientAuthData());
+ functions().putFunctionState(tenant, namespace, functionName, key, stateJson, authParams());
}
@POST
@@ -559,7 +559,7 @@ public class FunctionsBase extends AdminResource {
"The instanceId of a Pulsar Function (if instance-id is not provided, all instances are restarted")
final @PathParam("instanceId") String instanceId) {
functions().restartFunctionInstance(tenant, namespace, functionName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -578,7 +578,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) {
- functions().restartFunctionInstances(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().restartFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -598,7 +598,7 @@ public class FunctionsBase extends AdminResource {
"The instanceId of a Pulsar Function (if instance-id is not provided, all instances are stopped. ")
final @PathParam("instanceId") String instanceId) {
functions().stopFunctionInstance(tenant, namespace, functionName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -617,7 +617,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) {
- functions().stopFunctionInstances(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().stopFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -637,7 +637,7 @@ public class FunctionsBase extends AdminResource {
+ " (if instance-id is not provided, all instances sre started. ") final @PathParam("instanceId")
String instanceId) {
functions().startFunctionInstance(tenant, namespace, functionName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -656,7 +656,7 @@ public class FunctionsBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) {
- functions().startFunctionInstances(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().startFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -668,7 +668,7 @@ public class FunctionsBase extends AdminResource {
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadFunction(final @FormDataParam("data") InputStream uploadedInputStream,
final @FormDataParam("path") String path) {
- functions().uploadFunction(uploadedInputStream, path, clientAppId(), clientAuthData());
+ functions().uploadFunction(uploadedInputStream, path, authParams());
}
@GET
@@ -678,7 +678,7 @@ public class FunctionsBase extends AdminResource {
)
@Path("/download")
public StreamingOutput downloadFunction(final @QueryParam("path") String path) {
- return functions().downloadFunction(path, clientAppId(), clientAuthData());
+ return functions().downloadFunction(path, authParams());
}
@GET
@@ -695,7 +695,7 @@ public class FunctionsBase extends AdminResource {
@ApiParam(value = "The name of a Pulsar Function")
final @PathParam("functionName") String functionName) {
- return functions().downloadFunction(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ return functions().downloadFunction(tenant, namespace, functionName, authParams());
}
@GET
@@ -736,6 +736,6 @@ public class FunctionsBase extends AdminResource {
final @FormDataParam("delete") boolean delete) {
functions().updateFunctionOnWorkerLeader(tenant, namespace, functionName, uploadedInputStream,
- delete, uri.getRequestUri(), clientAppId(), clientAuthData());
+ delete, uri.getRequestUri(), authParams());
}
}
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SinksBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SinksBase.java
index 6f01b149afb..6536b829205 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SinksBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SinksBase.java
@@ -152,7 +152,7 @@ public class SinksBase extends AdminResource {
)
final @FormDataParam("sinkConfig") SinkConfig sinkConfig) {
sinks().registerSink(tenant, namespace, sinkName, uploadedInputStream, fileDetail,
- sinkPkgUrl, sinkConfig, clientAppId(), clientAuthData());
+ sinkPkgUrl, sinkConfig, authParams());
}
@PUT
@@ -254,7 +254,7 @@ public class SinksBase extends AdminResource {
@ApiParam(value = "Update options for the Pulsar Sink")
final @FormDataParam("updateOptions") UpdateOptionsImpl updateOptions) {
sinks().updateSink(tenant, namespace, sinkName, uploadedInputStream, fileDetail,
- sinkPkgUrl, sinkConfig, clientAppId(), clientAuthData(), updateOptions);
+ sinkPkgUrl, sinkConfig, authParams(), updateOptions);
}
@@ -278,7 +278,7 @@ public class SinksBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Sink")
final @PathParam("sinkName") String sinkName) {
- sinks().deregisterFunction(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().deregisterFunction(tenant, namespace, sinkName, authParams());
}
@GET
@@ -298,7 +298,7 @@ public class SinksBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Sink")
final @PathParam("sinkName") String sinkName) throws IOException {
- return sinks().getSinkInfo(tenant, namespace, sinkName);
+ return sinks().getSinkInfo(tenant, namespace, sinkName, authParams());
}
@GET
@@ -325,7 +325,7 @@ public class SinksBase extends AdminResource {
@ApiParam(value = "The instanceId of a Pulsar Sink")
final @PathParam("instanceId") String instanceId) throws IOException {
return sinks().getSinkInstanceStatus(
- tenant, namespace, sinkName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ tenant, namespace, sinkName, instanceId, uri.getRequestUri(), authParams());
}
@GET
@@ -348,7 +348,7 @@ public class SinksBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Sink")
final @PathParam("sinkName") String sinkName) throws IOException {
- return sinks().getSinkStatus(tenant, namespace, sinkName, uri.getRequestUri(), clientAppId(), clientAuthData());
+ return sinks().getSinkStatus(tenant, namespace, sinkName, uri.getRequestUri(), authParams());
}
@GET
@@ -368,7 +368,7 @@ public class SinksBase extends AdminResource {
final @PathParam("tenant") String tenant,
@ApiParam(value = "The namespace of a Pulsar Sink")
final @PathParam("namespace") String namespace) {
- return sinks().listFunctions(tenant, namespace, clientAppId(), clientAuthData());
+ return sinks().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -394,7 +394,7 @@ public class SinksBase extends AdminResource {
@ApiParam(value = "The instanceId of a Pulsar Sink")
final @PathParam("instanceId") String instanceId) {
sinks().restartFunctionInstance(tenant, namespace, sinkName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -415,7 +415,7 @@ public class SinksBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Sink")
final @PathParam("sinkName") String sinkName) {
- sinks().restartFunctionInstances(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().restartFunctionInstances(tenant, namespace, sinkName, authParams());
}
@POST
@@ -439,7 +439,7 @@ public class SinksBase extends AdminResource {
@ApiParam(value = "The instanceId of a Pulsar Sink")
final @PathParam("instanceId") String instanceId) {
sinks().stopFunctionInstance(tenant, namespace,
- sinkName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ sinkName, instanceId, uri.getRequestUri(), authParams());
}
@POST
@@ -460,7 +460,7 @@ public class SinksBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Sink")
final @PathParam("sinkName") String sinkName) {
- sinks().stopFunctionInstances(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().stopFunctionInstances(tenant, namespace, sinkName, authParams());
}
@POST
@@ -484,7 +484,7 @@ public class SinksBase extends AdminResource {
@ApiParam(value = "The instanceId of a Pulsar Sink")
final @PathParam("instanceId") String instanceId) {
sinks().startFunctionInstance(tenant, namespace, sinkName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -505,7 +505,7 @@ public class SinksBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Sink")
final @PathParam("sinkName") String sinkName) {
- sinks().startFunctionInstances(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().startFunctionInstances(tenant, namespace, sinkName, authParams());
}
@GET
@@ -554,6 +554,6 @@ public class SinksBase extends AdminResource {
})
@Path("/reloadBuiltInSinks")
public void reloadSinks() {
- sinks().reloadConnectors(clientAppId(), clientAuthData());
+ sinks().reloadConnectors(authParams());
}
}
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SourcesBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SourcesBase.java
index 8ac70687c28..024776d040b 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SourcesBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SourcesBase.java
@@ -130,7 +130,7 @@ public class SourcesBase extends AdminResource {
)
final @FormDataParam("sourceConfig") SourceConfig sourceConfig) {
sources().registerSource(tenant, namespace, sourceName, uploadedInputStream, fileDetail,
- sourcePkgUrl, sourceConfig, clientAppId(), clientAuthData());
+ sourcePkgUrl, sourceConfig, authParams());
}
@PUT
@@ -213,7 +213,7 @@ public class SourcesBase extends AdminResource {
@ApiParam(value = "Update options for Pulsar Source")
final @FormDataParam("updateOptions") UpdateOptionsImpl updateOptions) {
sources().updateSource(tenant, namespace, sourceName, uploadedInputStream, fileDetail,
- sourcePkgUrl, sourceConfig, clientAppId(), clientAuthData(), updateOptions);
+ sourcePkgUrl, sourceConfig, authParams(), updateOptions);
}
@@ -236,7 +236,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Source")
final @PathParam("sourceName") String sourceName) {
- sources().deregisterFunction(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().deregisterFunction(tenant, namespace, sourceName, authParams());
}
@GET
@@ -257,7 +257,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Source")
final @PathParam("sourceName") String sourceName) throws IOException {
- return sources().getSourceInfo(tenant, namespace, sourceName);
+ return sources().getSourceInfo(tenant, namespace, sourceName, authParams());
}
@GET
@@ -280,7 +280,7 @@ public class SourcesBase extends AdminResource {
+ " (if instance-id is not provided, the stats of all instances is returned).") final @PathParam(
"instanceId") String instanceId) throws IOException {
return sources().getSourceInstanceStatus(
- tenant, namespace, sourceName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ tenant, namespace, sourceName, instanceId, uri.getRequestUri(), authParams());
}
@GET
@@ -302,8 +302,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Source")
final @PathParam("sourceName") String sourceName) throws IOException {
- return sources().getSourceStatus(tenant, namespace, sourceName, uri.getRequestUri(), clientAppId(),
- clientAuthData());
+ return sources().getSourceStatus(tenant, namespace, sourceName, uri.getRequestUri(), authParams());
}
@GET
@@ -325,7 +324,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("tenant") String tenant,
@ApiParam(value = "The namespace of a Pulsar Source")
final @PathParam("namespace") String namespace) {
- return sources().listFunctions(tenant, namespace, clientAppId(), clientAuthData());
+ return sources().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -348,7 +347,7 @@ public class SourcesBase extends AdminResource {
+ " (if instance-id is not provided, the stats of all instances is returned).") final @PathParam(
"instanceId") String instanceId) {
sources().restartFunctionInstance(tenant, namespace, sourceName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -369,7 +368,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Source")
final @PathParam("sourceName") String sourceName) {
- sources().restartFunctionInstances(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().restartFunctionInstances(tenant, namespace, sourceName, authParams());
}
@POST
@@ -390,7 +389,7 @@ public class SourcesBase extends AdminResource {
@ApiParam(value = "The instanceId of a Pulsar Source (if instance-id is not provided,"
+ " the stats of all instances is returned).") final @PathParam("instanceId") String instanceId) {
sources().stopFunctionInstance(tenant, namespace, sourceName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -411,7 +410,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Source")
final @PathParam("sourceName") String sourceName) {
- sources().stopFunctionInstances(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().stopFunctionInstances(tenant, namespace, sourceName, authParams());
}
@POST
@@ -432,7 +431,7 @@ public class SourcesBase extends AdminResource {
@ApiParam(value = "The instanceId of a Pulsar Source (if instance-id is not provided,"
+ " the stats of all instances is returned).") final @PathParam("instanceId") String instanceId) {
sources().startFunctionInstance(tenant, namespace, sourceName, instanceId,
- uri.getRequestUri(), clientAppId(), clientAuthData());
+ uri.getRequestUri(), authParams());
}
@POST
@@ -453,7 +452,7 @@ public class SourcesBase extends AdminResource {
final @PathParam("namespace") String namespace,
@ApiParam(value = "The name of a Pulsar Source")
final @PathParam("sourceName") String sourceName) {
- sources().startFunctionInstances(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().startFunctionInstances(tenant, namespace, sourceName, authParams());
}
@GET
@@ -506,6 +505,6 @@ public class SourcesBase extends AdminResource {
})
@Path("/reloadBuiltInSources")
public void reloadSources() {
- sources().reloadConnectors(clientAppId(), clientAuthData());
+ sources().reloadConnectors(authParams());
}
}
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Functions.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Functions.java
index 1164e371bd7..7269728c26c 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Functions.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Functions.java
@@ -75,7 +75,7 @@ public class Functions extends AdminResource {
final @FormDataParam("functionDetails") String functionDetailsJson) {
return functions().registerFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionDetailsJson, clientAppId());
+ functionPkgUrl, functionDetailsJson, authParams());
}
@PUT
@@ -96,7 +96,7 @@ public class Functions extends AdminResource {
final @FormDataParam("functionDetails") String functionDetailsJson) {
return functions().updateFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionDetailsJson, clientAppId());
+ functionPkgUrl, functionDetailsJson, authParams());
}
@@ -113,7 +113,7 @@ public class Functions extends AdminResource {
public Response deregisterFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- return functions().deregisterFunction(tenant, namespace, functionName, clientAppId());
+ return functions().deregisterFunction(tenant, namespace, functionName, authParams());
}
@GET
@@ -132,8 +132,7 @@ public class Functions extends AdminResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) throws IOException {
- return functions().getFunctionInfo(
- tenant, namespace, functionName, clientAppId());
+ return functions().getFunctionInfo(tenant, namespace, functionName, authParams());
}
@GET
@@ -154,7 +153,7 @@ public class Functions extends AdminResource {
final @PathParam("instanceId") String instanceId) throws IOException {
return functions().getFunctionInstanceStatus(tenant, namespace, functionName, instanceId, uri.getRequestUri(),
- clientAppId());
+ authParams());
}
@GET
@@ -172,7 +171,7 @@ public class Functions extends AdminResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) throws IOException {
return functions().getFunctionStatusV2(
- tenant, namespace, functionName, uri.getRequestUri(), clientAppId());
+ tenant, namespace, functionName, uri.getRequestUri(), authParams());
}
@GET
@@ -188,7 +187,7 @@ public class Functions extends AdminResource {
@Path("/{tenant}/{namespace}")
public Response listFunctions(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace) {
- return functions().listFunctions(tenant, namespace, clientAppId());
+ return functions().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -211,7 +210,7 @@ public class Functions extends AdminResource {
final @FormDataParam("dataStream") InputStream triggerStream,
final @FormDataParam("topic") String topic) {
return functions().triggerFunction(tenant, namespace, functionName,
- triggerValue, triggerStream, topic, clientAppId());
+ triggerValue, triggerStream, topic, authParams());
}
@GET
@@ -230,7 +229,7 @@ public class Functions extends AdminResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName,
final @PathParam("key") String key) {
- return functions().getFunctionState(tenant, namespace, functionName, key, clientAppId());
+ return functions().getFunctionState(tenant, namespace, functionName, key, authParams());
}
@POST
@@ -247,7 +246,7 @@ public class Functions extends AdminResource {
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
return functions().restartFunctionInstance(tenant, namespace, functionName,
- instanceId, uri.getRequestUri(), clientAppId());
+ instanceId, uri.getRequestUri(), authParams());
}
@POST
@@ -260,7 +259,7 @@ public class Functions extends AdminResource {
public Response restartFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- return functions().restartFunctionInstances(tenant, namespace, functionName, clientAppId());
+ return functions().restartFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -275,7 +274,7 @@ public class Functions extends AdminResource {
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
return functions().stopFunctionInstance(tenant, namespace, functionName,
- instanceId, uri.getRequestUri(), clientAppId());
+ instanceId, uri.getRequestUri(), authParams());
}
@POST
@@ -288,7 +287,7 @@ public class Functions extends AdminResource {
public Response stopFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- return functions().stopFunctionInstances(tenant, namespace, functionName, clientAppId());
+ return functions().stopFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -300,7 +299,7 @@ public class Functions extends AdminResource {
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFunction(final @FormDataParam("data") InputStream uploadedInputStream,
final @FormDataParam("path") String path) {
- return functions().uploadFunction(uploadedInputStream, path, clientAppId());
+ return functions().uploadFunction(uploadedInputStream, path, authParams());
}
@GET
@@ -310,7 +309,7 @@ public class Functions extends AdminResource {
)
@Path("/download")
public Response downloadFunction(final @QueryParam("path") String path) {
- return functions().downloadFunction(path, clientAppId());
+ return functions().downloadFunction(path, authParams());
}
@GET
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Worker.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Worker.java
index 616f46621c1..9bbec276d29 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Worker.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Worker.java
@@ -66,7 +66,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
@Path("/cluster")
@Produces(MediaType.APPLICATION_JSON)
public List<WorkerInfo> getCluster() {
- return workers().getCluster(clientAppId());
+ return workers().getCluster(authParams());
}
@GET
@@ -81,7 +81,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
@Path("/cluster/leader")
@Produces(MediaType.APPLICATION_JSON)
public WorkerInfo getClusterLeader() {
- return workers().getClusterLeader(clientAppId());
+ return workers().getClusterLeader(authParams());
}
@GET
@@ -96,7 +96,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
@Path("/assignments")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Collection<String>> getAssignments() {
- return workers().getAssignments(clientAppId());
+ return workers().getAssignments(authParams());
}
@GET
@@ -112,7 +112,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
@Path("/connectors")
@Produces(MediaType.APPLICATION_JSON)
public List<ConnectorDefinition> getConnectorsList() throws IOException {
- return workers().getListOfConnectors(clientAppId());
+ return workers().getListOfConnectors(authParams());
}
@PUT
@@ -126,7 +126,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
})
@Path("/rebalance")
public void rebalance() {
- workers().rebalance(uri.getRequestUri(), clientAppId());
+ workers().rebalance(uri.getRequestUri(), authParams());
}
@PUT
@@ -142,7 +142,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
})
@Path("/leader/drain")
public void drainAtLeader(@QueryParam("workerId") String workerId) {
- workers().drain(uri.getRequestUri(), workerId, clientAppId(), true);
+ workers().drain(uri.getRequestUri(), workerId, authParams(), true);
}
@PUT
@@ -158,7 +158,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
})
@Path("/drain")
public void drain() {
- workers().drain(uri.getRequestUri(), null, clientAppId(), false);
+ workers().drain(uri.getRequestUri(), null, authParams(), false);
}
@GET
@@ -172,7 +172,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
})
@Path("/leader/drain")
public LongRunningProcessStatus getDrainStatusFromLeader(@QueryParam("workerId") String workerId) {
- return workers().getDrainStatus(uri.getRequestUri(), workerId, clientAppId(), true);
+ return workers().getDrainStatus(uri.getRequestUri(), workerId, authParams(), true);
}
@GET
@@ -186,7 +186,7 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
})
@Path("/drain")
public LongRunningProcessStatus getDrainStatus() {
- return workers().getDrainStatus(uri.getRequestUri(), null, clientAppId(), false);
+ return workers().getDrainStatus(uri.getRequestUri(), null, authParams(), false);
}
@GET
@@ -199,6 +199,6 @@ public class Worker extends AdminResource implements Supplier<WorkerService> {
})
@Path("/cluster/leader/ready")
public Boolean isLeaderReady() {
- return workers().isLeaderReady(clientAppId());
+ return workers().isLeaderReady(authParams());
}
}
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/WorkerStats.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/WorkerStats.java
index 6b9837c52be..e80d8241219 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/WorkerStats.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/WorkerStats.java
@@ -56,7 +56,7 @@ public class WorkerStats extends AdminResource {
})
@Produces(MediaType.APPLICATION_JSON)
public Collection<Metrics> getMetrics() throws Exception {
- return workers().getWorkerMetrics(clientAppId());
+ return workers().getWorkerMetrics(authParams());
}
@GET
@@ -72,6 +72,6 @@ public class WorkerStats extends AdminResource {
})
@Produces(MediaType.APPLICATION_JSON)
public List<WorkerFunctionInstanceStats> getStats() throws IOException {
- return workers().getFunctionsMetrics(clientAppId());
+ return workers().getFunctionsMetrics(authParams());
}
}
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
index 2bb24eef9d4..776346d03dd 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
@@ -53,6 +53,7 @@ import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.broker.authorization.AuthorizationService;
import org.apache.pulsar.broker.namespace.LookupOptions;
import org.apache.pulsar.broker.namespace.NamespaceService;
@@ -133,6 +134,14 @@ public abstract class PulsarWebResource {
return PolicyPath.splitPath(source, slice);
}
+ public AuthenticationParameters authParams() {
+ return AuthenticationParameters.builder()
+ .originalPrincipal(originalPrincipal())
+ .clientRole(clientAppId())
+ .clientAuthenticationDataSource(clientAuthData())
+ .build();
+ }
+
/**
* Gets a caller id (IP + role).
*
diff --git a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/WorkerConfig.java b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/WorkerConfig.java
index 25f6eb1d98f..05ce8756bce 100644
--- a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/WorkerConfig.java
+++ b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/WorkerConfig.java
@@ -483,6 +483,12 @@ public class WorkerConfig implements Serializable, PulsarConfiguration {
)
private Set<String> superUserRoles = Sets.newTreeSet();
+ @FieldContext(
+ category = CATEGORY_WORKER_SECURITY,
+ doc = "Role names that are treated as `proxy roles`. These are the only roles that can supply the "
+ + "originalPrincipal.")
+ private Set<String> proxyRoles = new TreeSet<>();
+
private Properties properties = new Properties();
public boolean getTlsEnabled() {
diff --git a/pulsar-functions/src/test/resources/test_worker_config.yml b/pulsar-functions/src/test/resources/test_worker_config.yml
index f0ecf2bd71b..a2977880370 100644
--- a/pulsar-functions/src/test/resources/test_worker_config.yml
+++ b/pulsar-functions/src/test/resources/test_worker_config.yml
@@ -23,6 +23,9 @@ pulsarServiceUrl: pulsar://localhost:6650
functionMetadataTopicName: test-function-metadata-topic
numFunctionPackageReplicas: 3
maxPendingAsyncRequests: 200
+proxyRoles:
+ - "proxyA"
+ - "proxyB"
properties:
# Fake Bookkeeper Client config to be applied to the DLog Bookkeeper Client
bookkeeper_testKey: "fakeValue"
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/FunctionApiResource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/FunctionApiResource.java
index 18ac5b20136..ec89a7bf140 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/FunctionApiResource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/FunctionApiResource.java
@@ -25,12 +25,14 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.broker.web.AuthenticationFilter;
import org.apache.pulsar.functions.worker.WorkerService;
public class FunctionApiResource implements Supplier<WorkerService> {
public static final String ATTRIBUTE_FUNCTION_WORKER = "function-worker";
+ public static final String ORIGINAL_PRINCIPAL_HEADER = "X-Original-Principal";
private WorkerService workerService;
@Context
@@ -48,12 +50,28 @@ public class FunctionApiResource implements Supplier<WorkerService> {
return this.workerService;
}
+ public AuthenticationParameters authParams() {
+ return AuthenticationParameters.builder()
+ .originalPrincipal(httpRequest.getHeader(ORIGINAL_PRINCIPAL_HEADER))
+ .clientRole(clientAppId())
+ .clientAuthenticationDataSource(clientAuthData())
+ .build();
+ }
+
+ /**
+ * @deprecated use {@link #authParams()} instead.
+ */
+ @Deprecated
public String clientAppId() {
return httpRequest != null
? (String) httpRequest.getAttribute(AuthenticationFilter.AuthenticatedRoleAttributeName)
: null;
}
+ /**
+ * @deprecated use {@link #authParams()} instead.
+ */
+ @Deprecated
public AuthenticationDataHttps clientAuthData() {
return (AuthenticationDataHttps) httpRequest.getAttribute(AuthenticationFilter.AuthenticatedDataAttributeName);
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java
index bad35e5443e..785aa528b5b 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java
@@ -43,8 +43,8 @@ import org.apache.bookkeeper.clients.config.StorageClientSettings;
import org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException;
import org.apache.bookkeeper.clients.exceptions.StreamNotFoundException;
import org.apache.commons.io.IOUtils;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.admin.internal.FunctionsImpl;
import org.apache.pulsar.client.api.Message;
@@ -62,7 +62,6 @@ import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.FunctionInstanceStatsDataImpl;
import org.apache.pulsar.common.policies.data.FunctionStatsImpl;
-import org.apache.pulsar.common.policies.data.TenantInfoImpl;
import org.apache.pulsar.common.util.Codec;
import org.apache.pulsar.common.util.RestException;
import org.apache.pulsar.functions.instance.InstanceUtils;
@@ -360,23 +359,14 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
public void deregisterFunction(final String tenant,
final String namespace,
final String componentName,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to deregister {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "deregister",
+ authParams);
// validate parameters
try {
@@ -426,23 +416,14 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
public FunctionConfig getFunctionInfo(final String tenant,
final String namespace,
final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to get {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "get",
+ authParams);
// validate parameters
try {
@@ -472,9 +453,8 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final String componentName,
final String instanceId,
final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
- changeFunctionInstanceStatus(tenant, namespace, componentName, instanceId, false, uri, clientRole, clientAuthenticationDataHttps);
+ final AuthenticationParameters authParams) {
+ changeFunctionInstanceStatus(tenant, namespace, componentName, instanceId, false, uri, authParams);
}
@Override
@@ -483,11 +463,11 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final String componentName,
final String instanceId,
final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
- changeFunctionInstanceStatus(tenant, namespace, componentName, instanceId, true, uri, clientRole, clientAuthenticationDataHttps);
+ final AuthenticationParameters authParams) {
+ changeFunctionInstanceStatus(tenant, namespace, componentName, instanceId, true, uri, authParams);
}
+ @Deprecated
public void changeFunctionInstanceStatus(final String tenant,
final String namespace,
final String componentName,
@@ -496,21 +476,27 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final URI uri,
final String clientRole,
final AuthenticationDataSource clientAuthenticationDataHttps) {
+ AuthenticationParameters authParams = AuthenticationParameters.builder()
+ .clientRole(clientRole)
+ .clientAuthenticationDataSource(clientAuthenticationDataHttps)
+ .build();
+ changeFunctionInstanceStatus(tenant, namespace, componentName, instanceId, start, uri, authParams);
+ }
+
+ public void changeFunctionInstanceStatus(final String tenant,
+ final String namespace,
+ final String componentName,
+ final String instanceId,
+ final boolean start,
+ final URI uri,
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to start/stop {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "start/stop",
+ authParams);
// validate parameters
try {
@@ -549,22 +535,13 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final String componentName,
final String instanceId,
final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to restart {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "restart",
+ authParams);
// validate parameters
try {
@@ -602,41 +579,41 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
public void stopFunctionInstances(final String tenant,
final String namespace,
final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
- changeFunctionStatusAllInstances(tenant, namespace, componentName, false, clientRole, clientAuthenticationDataHttps);
+ final AuthenticationParameters authParams) {
+ changeFunctionStatusAllInstances(tenant, namespace, componentName, false, authParams);
}
@Override
public void startFunctionInstances(final String tenant,
final String namespace,
final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
- changeFunctionStatusAllInstances(tenant, namespace, componentName, true, clientRole, clientAuthenticationDataHttps);
+ final AuthenticationParameters authParams) {
+ changeFunctionStatusAllInstances(tenant, namespace, componentName, true, authParams);
}
+ @Deprecated
public void changeFunctionStatusAllInstances(final String tenant,
final String namespace,
final String componentName,
final boolean start,
final String clientRole,
final AuthenticationDataSource clientAuthenticationDataHttps) {
+ AuthenticationParameters authParams = AuthenticationParameters.builder().clientRole(clientRole)
+ .clientAuthenticationDataSource(clientAuthenticationDataHttps).build();
+ changeFunctionStatusAllInstances(tenant, namespace, componentName, start, authParams);
+ }
+ public void changeFunctionStatusAllInstances(final String tenant,
+ final String namespace,
+ final String componentName,
+ final boolean start,
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to start/stop {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "start/stop",
+ authParams);
// validate parameters
try {
@@ -668,25 +645,17 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
String.format("Failed to start/stop %s: %s/%s/%s", ComponentTypeUtils.toString(componentType), tenant, namespace, componentName));
}
+ @Override
public void restartFunctionInstances(final String tenant,
final String namespace,
final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to restart {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "restart",
+ authParams);
// validate parameters
try {
@@ -719,26 +688,18 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
}
+ @Override
public FunctionStatsImpl getFunctionStats(final String tenant,
final String namespace,
final String componentName,
final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to get stats for {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "get stats for",
+ authParams);
// validate parameters
try {
@@ -775,27 +736,19 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
@Override
- public FunctionInstanceStatsDataImpl getFunctionsInstanceStats(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ public FunctionInstanceStatsDataImpl
+ getFunctionsInstanceStats(final String tenant,
+ final String namespace,
+ final String componentName,
+ final String instanceId,
+ final URI uri,
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to get stats for {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "get stats for",
+ authParams);
// validate parameters
try {
@@ -841,22 +794,13 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
@Override
public List<String> listFunctions(final String tenant,
final String namespace,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{} Client [{}] is not authorized to list {}", tenant, namespace, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{} Failed to authorize [{}]", tenant, namespace, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, null, "list", authParams);
// validate parameters
try {
@@ -896,13 +840,13 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
@Override
- public void reloadConnectors(String clientRole, AuthenticationDataSource authenticationData) {
+ public void reloadConnectors(AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
if (worker().getWorkerConfig().isAuthorizationEnabled()) {
// Only superuser has permission to do this operation.
- if (!isSuperUser(clientRole, authenticationData)) {
+ if (!isSuperUser(authParams)) {
throw new RestException(Status.UNAUTHORIZED, "This operation requires super-user access");
}
}
@@ -920,23 +864,13 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final String input,
final InputStream uploadedInputStream,
final String topic,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to trigger {}", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, functionName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, functionName, "trigger", authParams);
// validate parameters
try {
@@ -1043,23 +977,14 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final String namespace,
final String functionName,
final String key,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to get state for {}", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, functionName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, functionName, "get state for",
+ authParams);
if (null == worker().getStateStoreAdminClient()) {
throwStateStoreUnvailableResponse();
@@ -1129,8 +1054,7 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
final String functionName,
final String key,
final FunctionState state,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
@@ -1140,16 +1064,8 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
throwStateStoreUnvailableResponse();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to put state for {}", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, functionName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, functionName, "put state for",
+ authParams);
if (!key.equals(state.getKey())) {
log.error("{}/{}/{} Bad putFunction Request, path key doesn't match key in json", tenant, namespace, functionName);
@@ -1203,14 +1119,14 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
@Override
- public void uploadFunction(final InputStream uploadedInputStream, final String path, String clientRole,
- AuthenticationDataSource authenticationData) {
+ public void uploadFunction(final InputStream uploadedInputStream, final String path,
+ AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole, authenticationData)) {
+ if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(authParams)) {
throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
}
@@ -1236,21 +1152,13 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
@Override
public StreamingOutput downloadFunction(String tenant, String namespace, String componentName,
- String clientRole, AuthenticationDataHttps clientAuthenticationDataHttps) {
+ AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not admin and authorized to download package for {} ", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "download package for",
+ authParams);
FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
if (!functionMetaDataManager.containsFunction(tenant, namespace, componentName)) {
@@ -1283,7 +1191,7 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
@Override
- public StreamingOutput downloadFunction(final String path, String clientRole, AuthenticationDataHttps clientAuthenticationDataHttps) {
+ public StreamingOutput downloadFunction(final String path, final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
@@ -1297,18 +1205,10 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
String namespace = tokens[1];
String componentName = tokens[2];
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not admin and authorized to download package for {} ", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
- throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "download package for",
+ authParams);
} else {
- if (!isSuperUser(clientRole, clientAuthenticationDataHttps)) {
+ if (!isSuperUser(authParams)) {
throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
}
}
@@ -1436,53 +1336,61 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
getUniquePackageName(Codec.encode(fileName)));
}
+ /**
+ * @deprecated use {@link #isAuthorizedRole(String, String, AuthenticationParameters)} instead.
+ */
+ @Deprecated
public boolean isAuthorizedRole(String tenant, String namespace, String clientRole,
AuthenticationDataSource authenticationData) throws PulsarAdminException {
- if (worker().getWorkerConfig().isAuthorizationEnabled()) {
- // skip authorization if client role is super-user
- if (isSuperUser(clientRole, authenticationData)) {
- return true;
- }
-
- if (clientRole != null) {
- try {
- TenantInfoImpl tenantInfo = (TenantInfoImpl) worker().getBrokerAdmin().tenants().getTenantInfo(tenant);
- if (tenantInfo != null && worker().getAuthorizationService().isTenantAdmin(tenant, clientRole, tenantInfo, authenticationData).get()) {
- return true;
- }
- } catch (PulsarAdminException.NotFoundException | InterruptedException | ExecutionException e) {
-
- }
- }
-
- // check if role has permissions granted
- if (clientRole != null && authenticationData != null) {
- return allowFunctionOps(NamespaceName.get(tenant, namespace), clientRole, authenticationData);
- } else {
- return false;
- }
- }
- return true;
+ AuthenticationParameters authParams = AuthenticationParameters.builder().clientRole(clientRole)
+ .clientAuthenticationDataSource(authenticationData).build();
+ return isAuthorizedRole(tenant, namespace, authParams);
}
-
- protected void componentStatusRequestValidate (final String tenant, final String namespace, final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
- if (!isWorkerServiceAvailable()) {
- throw new RestException(Status.SERVICE_UNAVAILABLE, "Function worker service is not done initializing. Please try again in a little while.");
+ public boolean isAuthorizedRole(String tenant, String namespace,
+ AuthenticationParameters authParams) throws PulsarAdminException {
+ if (worker().getWorkerConfig().isAuthorizationEnabled()) {
+ return allowFunctionOps(NamespaceName.get(tenant, namespace), authParams);
+ } else {
+ return true;
}
+ }
+ public void throwRestExceptionIfUnauthorizedForNamespace(String tenant, String namespace, String componentName,
+ String action, AuthenticationParameters authParams) {
try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized get status for {}", tenant, namespace,
- componentName, clientRole, ComponentTypeUtils.toString(componentType));
+ if (!isAuthorizedRole(tenant, namespace, authParams)) {
+ log.warn("{}/{}/{} Client with role [{}] and originalPrincipal [{}] is not authorized to {} {}",
+ tenant, namespace, componentName, authParams.getClientRole(),
+ authParams.getOriginalPrincipal(), action, ComponentTypeUtils.toString(componentType));
throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
}
} catch (PulsarAdminException e) {
log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, componentName, e);
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
+ }
+
+ @Deprecated
+ protected void componentStatusRequestValidate(final String tenant, final String namespace,
+ final String componentName,
+ final String clientRole,
+ final AuthenticationDataSource clientAuthenticationDataHttps) {
+ AuthenticationParameters authParams = AuthenticationParameters.builder().clientRole(clientRole)
+ .clientAuthenticationDataSource(clientAuthenticationDataHttps).build();
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
+ }
+
+ protected void componentStatusRequestValidate(final String tenant, final String namespace,
+ final String componentName,
+ final AuthenticationParameters authParams) {
+ if (!isWorkerServiceAvailable()) {
+ throw new RestException(Status.SERVICE_UNAVAILABLE,
+ "Function worker service is not done initializing. Please try again in a little while.");
+ }
+
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, componentName, "get status for",
+ authParams);
// validate parameters
try {
@@ -1505,13 +1413,25 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
}
- protected void componentInstanceStatusRequestValidate (final String tenant,
- final String namespace,
- final String componentName,
- final int instanceId,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
- componentStatusRequestValidate(tenant, namespace, componentName, clientRole, clientAuthenticationDataHttps);
+ @Deprecated
+ protected void componentInstanceStatusRequestValidate(final String tenant,
+ final String namespace,
+ final String componentName,
+ final int instanceId,
+ final String clientRole,
+ final AuthenticationDataSource clientAuthenticationDataHttps) {
+ AuthenticationParameters authParams = AuthenticationParameters.builder().clientRole(clientRole)
+ .clientAuthenticationDataSource(clientAuthenticationDataHttps).build();
+ componentInstanceStatusRequestValidate(tenant, namespace, componentName, instanceId, authParams);
+ }
+
+ protected void componentInstanceStatusRequestValidate(final String tenant,
+ final String namespace,
+ final String componentName,
+ final int instanceId,
+ final AuthenticationParameters authParams) {
+
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
FunctionMetaData functionMetaData = functionMetaDataManager.getFunctionMetaData(tenant, namespace, componentName);
@@ -1523,49 +1443,67 @@ public abstract class ComponentImpl implements Component<PulsarWorkerService> {
}
}
- public boolean isSuperUser(String clientRole, AuthenticationDataSource authenticationData) {
- if (clientRole != null) {
+ public boolean isSuperUser(AuthenticationParameters authParams) {
+ if (authParams.getClientRole() != null) {
try {
- if ((worker().getWorkerConfig().getSuperUserRoles() != null
- && worker().getWorkerConfig().getSuperUserRoles().contains(clientRole))) {
- return true;
- }
- return worker().getAuthorizationService().isSuperUser(clientRole, authenticationData)
- .get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
+ return worker().getAuthorizationService().isSuperUser(authParams)
+ .get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
} catch (InterruptedException e) {
- log.warn("Time-out {} sec while checking the role {} is a super user role ",
- worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), clientRole);
+ log.warn("Time-out {} sec while checking the role {} originalPrincipal {} is a super user role ",
+ worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(),
+ authParams.getClientRole(), authParams.getOriginalPrincipal());
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
} catch (Exception e) {
- log.warn("Admin-client with Role - failed to check the role {} is a super user role {} ", clientRole,
- e.getMessage(), e);
+ log.warn("Failed verifying role {} originalPrincipal {} is a super user role",
+ authParams.getClientRole(), authParams.getOriginalPrincipal(), e);
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
return false;
}
+ /**
+ * @deprecated use {@link #isSuperUser(AuthenticationParameters)}
+ */
+ @Deprecated
+ public boolean isSuperUser(String clientRole, AuthenticationDataSource authenticationData) {
+ AuthenticationParameters authParams = AuthenticationParameters.builder().clientRole(clientRole)
+ .clientAuthenticationDataSource(authenticationData).build();
+ return isSuperUser(authParams);
+ }
+
+ /**
+ * @deprecated use {@link #isSuperUser(AuthenticationParameters)}
+ */
+ @Deprecated
public boolean allowFunctionOps(NamespaceName namespaceName, String role,
AuthenticationDataSource authenticationData) {
+ AuthenticationParameters authParams = AuthenticationParameters.builder().clientRole(role)
+ .clientAuthenticationDataSource(authenticationData).build();
+ return allowFunctionOps(namespaceName, authParams);
+ }
+
+ public boolean allowFunctionOps(NamespaceName namespaceName, AuthenticationParameters authParams) {
try {
switch (componentType) {
case SINK:
- return worker().getAuthorizationService().allowSinkOpsAsync(
- namespaceName, role, authenticationData).get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
+ return worker().getAuthorizationService().allowSinkOpsAsync(namespaceName, authParams)
+ .get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
case SOURCE:
- return worker().getAuthorizationService().allowSourceOpsAsync(
- namespaceName, role, authenticationData).get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
+ return worker().getAuthorizationService().allowSourceOpsAsync(namespaceName, authParams)
+ .get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
case FUNCTION:
default:
- return worker().getAuthorizationService().allowFunctionOpsAsync(
- namespaceName, role, authenticationData).get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
+ return worker().getAuthorizationService().allowFunctionOpsAsync(namespaceName, authParams)
+ .get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS);
}
} catch (InterruptedException e) {
log.warn("Time-out {} sec while checking function authorization on {} ", worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), namespaceName);
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
} catch (Exception e) {
- log.warn("Admin-client with Role - {} failed to get function permissions for namespace - {}. {}", role, namespaceName,
- e.getMessage(), e);
+ log.warn("Admin-client with Role [{}] originalPrincipal [{}] failed to get function permissions for "
+ + "namespace - {}. {}", authParams.getClientRole(),
+ authParams.getOriginalPrincipal(), namespaceName, e.getMessage(), e);
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
index 506ca452857..11fb2149f39 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
@@ -42,8 +42,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.functions.FunctionConfig;
import org.apache.pulsar.common.functions.UpdateOptionsImpl;
@@ -80,8 +79,7 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
final FormDataContentDisposition fileDetail,
final String functionPkgUrl,
final FunctionConfig functionConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
@@ -100,16 +98,7 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
throw new RestException(Response.Status.BAD_REQUEST, "Function config is not provided");
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.error("{}/{}/{} Client [{}] is not authorized to register {}", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, functionName, e);
- throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, functionName, "register", authParams);
try {
// Check tenant exists
@@ -126,8 +115,8 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
}
}
} catch (PulsarAdminException.NotAuthorizedException e) {
- log.error("{}/{}/{} Client [{}] is not authorized to operate {} on tenant", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
+ log.error("{}/{}/{} Client is not authorized to operate {} on tenant", tenant, namespace,
+ functionName, ComponentTypeUtils.toString(componentType));
throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
} catch (PulsarAdminException.NotFoundException e) {
log.error("{}/{}/{} Tenant {} does not exist", tenant, namespace, functionName, tenant);
@@ -201,11 +190,12 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
worker().getFunctionRuntimeManager()
.getRuntimeFactory()
.getAuthProvider().ifPresent(functionAuthProvider -> {
- if (clientAuthenticationDataHttps != null) {
+ if (authParams.getClientAuthenticationDataSource() != null) {
try {
Optional<FunctionAuthData> functionAuthData = functionAuthProvider
- .cacheAuthData(finalFunctionDetails, clientAuthenticationDataHttps);
+ .cacheAuthData(finalFunctionDetails,
+ authParams.getClientAuthenticationDataSource());
functionAuthData.ifPresent(authData -> functionMetaDataBuilder.setFunctionAuthSpec(
Function.FunctionAuthenticationSpec.newBuilder()
@@ -251,8 +241,7 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
final FormDataContentDisposition fileDetail,
final String functionPkgUrl,
final FunctionConfig functionConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps,
+ final AuthenticationParameters authParams,
UpdateOptionsImpl updateOptions) {
if (!isWorkerServiceAvailable()) {
@@ -272,17 +261,8 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
throw new RestException(Response.Status.BAD_REQUEST, "Function config is not provided");
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.error("{}/{}/{} Client [{}] is not authorized to update {}", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
-
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, functionName, e);
- throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, functionName, "update",
+ authParams);
FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
@@ -386,17 +366,19 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
worker().getFunctionRuntimeManager()
.getRuntimeFactory()
.getAuthProvider().ifPresent(functionAuthProvider -> {
- if (clientAuthenticationDataHttps != null && updateOptions != null && updateOptions.isUpdateAuthData()) {
- // get existing auth data if it exists
- Optional<FunctionAuthData> existingFunctionAuthData = Optional.empty();
- if (functionMetaDataBuilder.hasFunctionAuthSpec()) {
- existingFunctionAuthData = Optional.ofNullable(getFunctionAuthData(Optional.ofNullable(functionMetaDataBuilder.getFunctionAuthSpec())));
- }
+ if (authParams.getClientAuthenticationDataSource() != null && updateOptions
+ != null && updateOptions.isUpdateAuthData()) {
+ // get existing auth data if it exists
+ Optional<FunctionAuthData> existingFunctionAuthData = Optional.empty();
+ if (functionMetaDataBuilder.hasFunctionAuthSpec()) {
+ existingFunctionAuthData = Optional.ofNullable(getFunctionAuthData(Optional
+ .ofNullable(functionMetaDataBuilder.getFunctionAuthSpec())));
+ }
try {
Optional<FunctionAuthData> newFunctionAuthData = functionAuthProvider
.updateAuthData(finalFunctionDetails, existingFunctionAuthData,
- clientAuthenticationDataHttps);
+ authParams.getClientAuthenticationDataSource());
if (newFunctionAuthData.isPresent()) {
functionMetaDataBuilder.setFunctionAuthSpec(
@@ -604,16 +586,17 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
* @return the function status
*/
@Override
- public FunctionStatus.FunctionInstanceStatus.FunctionInstanceStatusData getFunctionInstanceStatus(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ public FunctionStatus.FunctionInstanceStatus.FunctionInstanceStatusData getFunctionInstanceStatus(
+ final String tenant,
+ final String namespace,
+ final String componentName,
+ final String instanceId,
+ final URI uri,
+ final AuthenticationParameters authParams) {
// validate parameters
- componentInstanceStatusRequestValidate(tenant, namespace, componentName, Integer.parseInt(instanceId), clientRole, clientAuthenticationDataHttps);
+ componentInstanceStatusRequestValidate(tenant, namespace, componentName, Integer.parseInt(instanceId),
+ authParams);
FunctionStatus.FunctionInstanceStatus.FunctionInstanceStatusData functionInstanceStatusData;
try {
@@ -642,11 +625,10 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
final String namespace,
final String componentName,
final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
// validate parameters
- componentStatusRequestValidate(tenant, namespace, componentName, clientRole, clientAuthenticationDataHttps);
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
FunctionStatus functionStatus;
try {
@@ -663,22 +645,23 @@ public class FunctionsImpl extends ComponentImpl implements Functions<PulsarWork
@Override
public void updateFunctionOnWorkerLeader(final String tenant,
- final String namespace,
- final String functionName,
- final InputStream uploadedInputStream,
- final boolean delete,
- URI uri,
- final String clientRole,
- AuthenticationDataSource authenticationData) {
+ final String namespace,
+ final String functionName,
+ final InputStream uploadedInputStream,
+ final boolean delete,
+ URI uri,
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
if (worker().getWorkerConfig().isAuthorizationEnabled()) {
- if (!isSuperUser(clientRole, authenticationData)) {
- log.error("{}/{}/{} Client [{}] is not superuser to update on worker leader {}", tenant, namespace,
- functionName, clientRole, ComponentTypeUtils.toString(componentType));
+ if (!isSuperUser(authParams)) {
+ log.error("{}/{}/{} Client with role [{}] and originalPrincipal [{}] is not superuser to update on"
+ + " worker leader {}", tenant, namespace, functionName, authParams.getClientRole(),
+ authParams.getClientAuthenticationDataSource(),
+ ComponentTypeUtils.toString(componentType));
throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplV2.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplV2.java
index 26479baea38..8d83f566e6a 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplV2.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplV2.java
@@ -20,6 +20,7 @@ package org.apache.pulsar.functions.worker.rest.api;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.common.functions.FunctionConfig;
import org.apache.pulsar.common.functions.FunctionState;
import org.apache.pulsar.common.io.ConnectorDefinition;
@@ -59,11 +60,12 @@ public class FunctionsImplV2 implements FunctionsV2<PulsarWorkerService> {
}
@Override
- public Response getFunctionInfo(final String tenant, final String namespace, final String functionName, String clientRole)
+ public Response getFunctionInfo(final String tenant, final String namespace,
+ final String functionName, AuthenticationParameters authParams)
throws IOException {
// run just for parameter checks
- delegate.getFunctionInfo(tenant, namespace, functionName, clientRole, null);
+ delegate.getFunctionInfo(tenant, namespace, functionName, authParams);
FunctionMetaDataManager functionMetaDataManager = delegate.worker().getFunctionMetaDataManager();
@@ -75,20 +77,25 @@ public class FunctionsImplV2 implements FunctionsV2<PulsarWorkerService> {
@Override
public Response getFunctionInstanceStatus(final String tenant, final String namespace, final String functionName,
- final String instanceId, URI uri, String clientRole) throws IOException {
+ final String instanceId, URI uri,
+ AuthenticationParameters authParams) throws IOException {
org.apache.pulsar.common.policies.data.FunctionStatus.FunctionInstanceStatus.FunctionInstanceStatusData
- functionInstanceStatus = delegate.getFunctionInstanceStatus(tenant, namespace, functionName, instanceId, uri, clientRole, null);
+ functionInstanceStatus = delegate.getFunctionInstanceStatus(tenant, namespace,
+ functionName, instanceId, uri, authParams);
String jsonResponse = FunctionCommon.printJson(toProto(functionInstanceStatus, instanceId));
return Response.status(Response.Status.OK).entity(jsonResponse).build();
}
@Override
- public Response getFunctionStatusV2(String tenant, String namespace, String functionName, URI requestUri, String clientRole) throws
+ public Response getFunctionStatusV2(String tenant, String namespace, String functionName,
+ URI requestUri, AuthenticationParameters authParams) throws
IOException {
- FunctionStatus functionStatus = delegate.getFunctionStatus(tenant, namespace, functionName, requestUri, clientRole, null);
- InstanceCommunication.FunctionStatusList.Builder functionStatusList = InstanceCommunication.FunctionStatusList.newBuilder();
+ FunctionStatus functionStatus = delegate.getFunctionStatus(tenant, namespace,
+ functionName, requestUri, authParams);
+ InstanceCommunication.FunctionStatusList.Builder functionStatusList =
+ InstanceCommunication.FunctionStatusList.newBuilder();
functionStatus.instances.forEach(functionInstanceStatus -> functionStatusList.addFunctionStatusList(
toProto(functionInstanceStatus.getStatus(),
String.valueOf(functionInstanceStatus.getInstanceId()))));
@@ -99,7 +106,7 @@ public class FunctionsImplV2 implements FunctionsV2<PulsarWorkerService> {
@Override
public Response registerFunction(String tenant, String namespace, String functionName, InputStream
uploadedInputStream, FormDataContentDisposition fileDetail, String functionPkgUrl, String
- functionDetailsJson, String clientRole) {
+ functionDetailsJson, AuthenticationParameters authParams) {
Function.FunctionDetails.Builder functionDetailsBuilder = Function.FunctionDetails.newBuilder();
try {
@@ -110,14 +117,15 @@ public class FunctionsImplV2 implements FunctionsV2<PulsarWorkerService> {
FunctionConfig functionConfig = FunctionConfigUtils.convertFromDetails(functionDetailsBuilder.build());
delegate.registerFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionConfig, clientRole, null);
+ functionPkgUrl, functionConfig, authParams);
return Response.ok().build();
}
@Override
- public Response updateFunction(String tenant, String namespace, String functionName, InputStream uploadedInputStream,
- FormDataContentDisposition fileDetail, String functionPkgUrl, String
- functionDetailsJson, String clientRole) {
+ public Response updateFunction(String tenant, String namespace, String functionName,
+ InputStream uploadedInputStream, FormDataContentDisposition fileDetail,
+ String functionPkgUrl, String functionDetailsJson,
+ AuthenticationParameters authParams) {
Function.FunctionDetails.Builder functionDetailsBuilder = Function.FunctionDetails.newBuilder();
try {
@@ -128,33 +136,36 @@ public class FunctionsImplV2 implements FunctionsV2<PulsarWorkerService> {
FunctionConfig functionConfig = FunctionConfigUtils.convertFromDetails(functionDetailsBuilder.build());
delegate.updateFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionConfig, clientRole, null, null);
+ functionPkgUrl, functionConfig, authParams, null);
return Response.ok().build();
}
@Override
- public Response deregisterFunction(String tenant, String namespace, String functionName, String clientAppId) {
- delegate.deregisterFunction(tenant, namespace, functionName, clientAppId, null);
+ public Response deregisterFunction(String tenant, String namespace, String functionName,
+ AuthenticationParameters authParams) {
+ delegate.deregisterFunction(tenant, namespace, functionName, authParams);
return Response.ok().build();
}
@Override
- public Response listFunctions(String tenant, String namespace, String clientRole) {
- Collection<String> functionStateList = delegate.listFunctions( tenant, namespace, clientRole, null);
+ public Response listFunctions(String tenant, String namespace, AuthenticationParameters authParams) {
+ Collection<String> functionStateList = delegate.listFunctions(tenant, namespace, authParams);
return Response.status(Response.Status.OK).entity(new Gson().toJson(functionStateList.toArray())).build();
}
@Override
public Response triggerFunction(String tenant, String namespace, String functionName, String triggerValue,
- InputStream triggerStream, String topic, String clientRole) {
- String result = delegate.triggerFunction(tenant, namespace, functionName, triggerValue, triggerStream, topic, clientRole, null);
+ InputStream triggerStream, String topic, AuthenticationParameters authParams) {
+ String result = delegate.triggerFunction(tenant, namespace, functionName,
+ triggerValue, triggerStream, topic, authParams);
return Response.status(Response.Status.OK).entity(result).build();
}
@Override
- public Response getFunctionState(String tenant, String namespace, String functionName, String key, String clientRole) {
+ public Response getFunctionState(String tenant, String namespace, String functionName,
+ String key, AuthenticationParameters authParams) {
FunctionState functionState = delegate.getFunctionState(
- tenant, namespace, functionName, key, clientRole, null);
+ tenant, namespace, functionName, key, authParams);
String value;
if (functionState.getNumberValue() != null) {
@@ -169,39 +180,41 @@ public class FunctionsImplV2 implements FunctionsV2<PulsarWorkerService> {
@Override
public Response restartFunctionInstance(String tenant, String namespace, String functionName, String instanceId, URI
- uri, String clientRole) {
- delegate.restartFunctionInstance(tenant, namespace, functionName, instanceId, uri, clientRole, null);
+ uri, AuthenticationParameters authParams) {
+ delegate.restartFunctionInstance(tenant, namespace, functionName, instanceId, uri, authParams);
return Response.ok().build();
}
@Override
- public Response restartFunctionInstances(String tenant, String namespace, String functionName, String clientRole) {
- delegate.restartFunctionInstances(tenant, namespace, functionName, clientRole, null);
+ public Response restartFunctionInstances(String tenant, String namespace, String functionName,
+ AuthenticationParameters authParams) {
+ delegate.restartFunctionInstances(tenant, namespace, functionName, authParams);
return Response.ok().build();
}
@Override
public Response stopFunctionInstance(String tenant, String namespace, String functionName, String instanceId, URI
- uri, String clientRole) {
- delegate.stopFunctionInstance(tenant, namespace, functionName, instanceId, uri, clientRole ,null);
+ uri, AuthenticationParameters authParams) {
+ delegate.stopFunctionInstance(tenant, namespace, functionName, instanceId, uri, authParams);
return Response.ok().build();
}
@Override
- public Response stopFunctionInstances(String tenant, String namespace, String functionName, String clientRole) {
- delegate.stopFunctionInstances(tenant, namespace, functionName, clientRole, null);
+ public Response stopFunctionInstances(String tenant, String namespace, String functionName,
+ AuthenticationParameters authParams) {
+ delegate.stopFunctionInstances(tenant, namespace, functionName, authParams);
return Response.ok().build();
}
@Override
- public Response uploadFunction(InputStream uploadedInputStream, String path, String clientRole) {
- delegate.uploadFunction(uploadedInputStream, path, clientRole, null);
+ public Response uploadFunction(InputStream uploadedInputStream, String path, AuthenticationParameters authParams) {
+ delegate.uploadFunction(uploadedInputStream, path, authParams);
return Response.ok().build();
}
@Override
- public Response downloadFunction(String path, String clientRole) {
- return Response.status(Response.Status.OK).entity(delegate.downloadFunction(path, clientRole, null)).build();
+ public Response downloadFunction(String path, AuthenticationParameters authParams) {
+ return Response.status(Response.Status.OK).entity(delegate.downloadFunction(path, authParams)).build();
}
@Override
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java
index ab69ab9182c..86711d5b5c6 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java
@@ -39,8 +39,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.functions.UpdateOptionsImpl;
import org.apache.pulsar.common.functions.Utils;
@@ -80,8 +79,7 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
final FormDataContentDisposition fileDetail,
final String sinkPkgUrl,
final SinkConfig sinkConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
@@ -100,16 +98,7 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
throw new RestException(Response.Status.BAD_REQUEST, "Sink config is not provided");
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to register {}", tenant, namespace,
- sinkName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, sinkName, e);
- throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, sinkName, "register", authParams);
try {
// Check tenant exists
@@ -126,8 +115,8 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
}
}
} catch (PulsarAdminException.NotAuthorizedException e) {
- log.error("{}/{}/{} Client [{}] is not authorized to operate {} on tenant", tenant, namespace,
- sinkName, clientRole, ComponentTypeUtils.toString(componentType));
+ log.error("{}/{}/{} Client is not authorized to operate {} on tenant", tenant, namespace,
+ sinkName, ComponentTypeUtils.toString(componentType));
throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
} catch (PulsarAdminException.NotFoundException e) {
log.error("{}/{}/{} Tenant {} does not exist", tenant, namespace, sinkName, tenant);
@@ -200,11 +189,12 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
worker().getFunctionRuntimeManager()
.getRuntimeFactory()
.getAuthProvider().ifPresent(functionAuthProvider -> {
- if (clientAuthenticationDataHttps != null) {
+ if (authParams.getClientAuthenticationDataSource() != null) {
try {
Optional<FunctionAuthData> functionAuthData = functionAuthProvider
- .cacheAuthData(finalFunctionDetails, clientAuthenticationDataHttps);
+ .cacheAuthData(finalFunctionDetails,
+ authParams.getClientAuthenticationDataSource());
functionAuthData.ifPresent(authData -> functionMetaDataBuilder.setFunctionAuthSpec(
Function.FunctionAuthenticationSpec.newBuilder()
@@ -250,8 +240,7 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
final FormDataContentDisposition fileDetail,
final String sinkPkgUrl,
final SinkConfig sinkConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps,
+ final AuthenticationParameters authParams,
UpdateOptionsImpl updateOptions) {
if (!isWorkerServiceAvailable()) {
@@ -271,17 +260,7 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
throw new RestException(Response.Status.BAD_REQUEST, "Sink config is not provided");
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to update {}", tenant, namespace,
- sinkName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
-
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, sinkName, e);
- throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, sinkName, "update", authParams);
FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
@@ -387,7 +366,8 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
worker().getFunctionRuntimeManager()
.getRuntimeFactory()
.getAuthProvider().ifPresent(functionAuthProvider -> {
- if (clientAuthenticationDataHttps != null && updateOptions != null && updateOptions.isUpdateAuthData()) {
+ if (authParams.getClientAuthenticationDataSource() != null && updateOptions != null
+ && updateOptions.isUpdateAuthData()) {
// get existing auth data if it exists
Optional<FunctionAuthData> existingFunctionAuthData = Optional.empty();
if (functionMetaDataBuilder.hasFunctionAuthSpec()) {
@@ -397,7 +377,7 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
try {
Optional<FunctionAuthData> newFunctionAuthData = functionAuthProvider
.updateAuthData(finalFunctionDetails, existingFunctionAuthData,
- clientAuthenticationDataHttps);
+ authParams.getClientAuthenticationDataSource());
if (newFunctionAuthData.isPresent()) {
functionMetaDataBuilder.setFunctionAuthSpec(
@@ -601,16 +581,17 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
}
@Override
- public SinkStatus.SinkInstanceStatus.SinkInstanceStatusData getSinkInstanceStatus(final String tenant,
- final String namespace,
- final String sinkName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ public SinkStatus.SinkInstanceStatus.SinkInstanceStatusData
+ getSinkInstanceStatus(final String tenant,
+ final String namespace,
+ final String sinkName,
+ final String instanceId,
+ final URI uri,
+ final AuthenticationParameters authParams) {
// validate parameters
- componentInstanceStatusRequestValidate(tenant, namespace, sinkName, Integer.parseInt(instanceId), clientRole, clientAuthenticationDataHttps);
+ componentInstanceStatusRequestValidate(tenant, namespace, sinkName, Integer.parseInt(instanceId),
+ authParams);
SinkStatus.SinkInstanceStatus.SinkInstanceStatusData sinkInstanceStatusData;
@@ -631,11 +612,10 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
final String namespace,
final String componentName,
final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
// validate parameters
- componentStatusRequestValidate(tenant, namespace, componentName, clientRole, clientAuthenticationDataHttps);
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
SinkStatus sinkStatus;
try {
@@ -653,32 +633,12 @@ public class SinksImpl extends ComponentImpl implements Sinks<PulsarWorkerServic
@Override
public SinkConfig getSinkInfo(final String tenant,
final String namespace,
- final String componentName) {
-
- if (!isWorkerServiceAvailable()) {
- throwUnavailableException();
- }
-
- // validate parameters
- try {
- validateGetFunctionRequestParams(tenant, namespace, componentName, componentType);
- } catch (IllegalArgumentException e) {
- log.error("Invalid get {} request @ /{}/{}/{}", ComponentTypeUtils.toString(componentType), tenant, namespace, componentName, e);
- throw new RestException(Response.Status.BAD_REQUEST, e.getMessage());
- }
-
- FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
- if (!functionMetaDataManager.containsFunction(tenant, namespace, componentName)) {
- log.error("{} does not exist @ /{}/{}/{}", ComponentTypeUtils.toString(componentType), tenant, namespace, componentName);
- throw new RestException(Response.Status.NOT_FOUND, String.format(ComponentTypeUtils.toString(componentType) + " %s doesn't exist", componentName));
- }
- Function.FunctionMetaData functionMetaData = functionMetaDataManager.getFunctionMetaData(tenant, namespace, componentName);
- if (!InstanceUtils.calculateSubjectType(functionMetaData.getFunctionDetails()).equals(componentType)) {
- log.error("{}/{}/{} is not a {}", tenant, namespace, componentName, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.NOT_FOUND, String.format(ComponentTypeUtils.toString(componentType) + " %s doesn't exist", componentName));
- }
- SinkConfig config = SinkConfigUtils.convertFromDetails(functionMetaData.getFunctionDetails());
- return config;
+ final String componentName,
+ final AuthenticationParameters authParams) {
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
+ Function.FunctionMetaData functionMetaData =
+ worker().getFunctionMetaDataManager().getFunctionMetaData(tenant, namespace, componentName);
+ return SinkConfigUtils.convertFromDetails(functionMetaData.getFunctionDetails());
}
@Override
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java
index df2dca813e7..2d604e073ae 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java
@@ -39,8 +39,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.functions.UpdateOptionsImpl;
import org.apache.pulsar.common.functions.Utils;
@@ -80,8 +79,7 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
final FormDataContentDisposition fileDetail,
final String sourcePkgUrl,
final SourceConfig sourceConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps) {
+ final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
@@ -100,16 +98,7 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
throw new RestException(Response.Status.BAD_REQUEST, "Source config is not provided");
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to register {}", tenant, namespace,
- sourceName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, sourceName, e);
- throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, sourceName, "register", authParams);
try {
// Check tenant exists
@@ -126,8 +115,8 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
}
}
} catch (PulsarAdminException.NotAuthorizedException e) {
- log.error("{}/{}/{} Client [{}] is not authorized to operate {} on tenant", tenant, namespace,
- sourceName, clientRole, ComponentTypeUtils.toString(componentType));
+ log.error("{}/{}/{} Client is not authorized to operate {} on tenant", tenant, namespace,
+ sourceName, ComponentTypeUtils.toString(componentType));
throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
} catch (PulsarAdminException.NotFoundException e) {
log.error("{}/{}/{} Tenant {} does not exist", tenant, namespace, sourceName, tenant);
@@ -200,11 +189,12 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
worker().getFunctionRuntimeManager()
.getRuntimeFactory()
.getAuthProvider().ifPresent(functionAuthProvider -> {
- if (clientAuthenticationDataHttps != null) {
+ if (authParams.getClientAuthenticationDataSource() != null) {
try {
Optional<FunctionAuthData> functionAuthData = functionAuthProvider
- .cacheAuthData(finalFunctionDetails, clientAuthenticationDataHttps);
+ .cacheAuthData(finalFunctionDetails,
+ authParams.getClientAuthenticationDataSource());
functionAuthData.ifPresent(authData -> functionMetaDataBuilder.setFunctionAuthSpec(
Function.FunctionAuthenticationSpec.newBuilder()
@@ -250,8 +240,7 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
final FormDataContentDisposition fileDetail,
final String sourcePkgUrl,
final SourceConfig sourceConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps,
+ final AuthenticationParameters authParams,
UpdateOptionsImpl updateOptions) {
if (!isWorkerServiceAvailable()) {
@@ -271,17 +260,7 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
throw new RestException(Response.Status.BAD_REQUEST, "Source config is not provided");
}
- try {
- if (!isAuthorizedRole(tenant, namespace, clientRole, clientAuthenticationDataHttps)) {
- log.warn("{}/{}/{} Client [{}] is not authorized to update {}", tenant, namespace,
- sourceName, clientRole, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
-
- }
- } catch (PulsarAdminException e) {
- log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace, sourceName, e);
- throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
- }
+ throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, sourceName, "update", authParams);
FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
@@ -385,7 +364,8 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
worker().getFunctionRuntimeManager()
.getRuntimeFactory()
.getAuthProvider().ifPresent(functionAuthProvider -> {
- if (clientAuthenticationDataHttps != null && updateOptions != null && updateOptions.isUpdateAuthData()) {
+ if (authParams.getClientAuthenticationDataSource() != null && updateOptions != null
+ && updateOptions.isUpdateAuthData()) {
// get existing auth data if it exists
Optional<FunctionAuthData> existingFunctionAuthData = Optional.empty();
if (functionMetaDataBuilder.hasFunctionAuthSpec()) {
@@ -395,7 +375,7 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
try {
Optional<FunctionAuthData> newFunctionAuthData = functionAuthProvider
.updateAuthData(finalFunctionDetails, existingFunctionAuthData,
- clientAuthenticationDataHttps);
+ authParams.getClientAuthenticationDataSource());
if (newFunctionAuthData.isPresent()) {
functionMetaDataBuilder.setFunctionAuthSpec(
@@ -605,10 +585,10 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
public SourceStatus getSourceStatus(final String tenant,
final String namespace,
final String componentName,
- final URI uri, final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ final URI uri,
+ final AuthenticationParameters authParams) {
// validate parameters
- componentStatusRequestValidate(tenant, namespace, componentName, clientRole, clientAuthenticationDataHttps);
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
SourceStatus sourceStatus;
try {
@@ -624,15 +604,15 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
}
@Override
- public SourceStatus.SourceInstanceStatus.SourceInstanceStatusData getSourceInstanceStatus(final String tenant,
- final String namespace,
- final String sourceName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps) {
+ public SourceStatus.SourceInstanceStatus.SourceInstanceStatusData
+ getSourceInstanceStatus(final String tenant,
+ final String namespace,
+ final String sourceName,
+ final String instanceId,
+ final URI uri,
+ final AuthenticationParameters authParams) {
// validate parameters
- componentInstanceStatusRequestValidate(tenant, namespace, sourceName, Integer.parseInt(instanceId), clientRole, clientAuthenticationDataHttps);
+ componentInstanceStatusRequestValidate(tenant, namespace, sourceName, Integer.parseInt(instanceId), authParams);
SourceStatus.SourceInstanceStatus.SourceInstanceStatusData sourceInstanceStatusData;
try {
@@ -650,32 +630,12 @@ public class SourcesImpl extends ComponentImpl implements Sources<PulsarWorkerSe
@Override
public SourceConfig getSourceInfo(final String tenant,
final String namespace,
- final String componentName) {
-
- if (!isWorkerServiceAvailable()) {
- throwUnavailableException();
- }
-
- // validate parameters
- try {
- validateGetFunctionRequestParams(tenant, namespace, componentName, componentType);
- } catch (IllegalArgumentException e) {
- log.error("Invalid get {} request @ /{}/{}/{}", ComponentTypeUtils.toString(componentType), tenant, namespace, componentName, e);
- throw new RestException(Response.Status.BAD_REQUEST, e.getMessage());
- }
-
- FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
- if (!functionMetaDataManager.containsFunction(tenant, namespace, componentName)) {
- log.error("{} does not exist @ /{}/{}/{}", ComponentTypeUtils.toString(componentType), tenant, namespace, componentName);
- throw new RestException(Response.Status.NOT_FOUND, String.format(ComponentTypeUtils.toString(componentType) + " %s doesn't exist", componentName));
- }
- Function.FunctionMetaData functionMetaData = functionMetaDataManager.getFunctionMetaData(tenant, namespace, componentName);
- if (!InstanceUtils.calculateSubjectType(functionMetaData.getFunctionDetails()).equals(componentType)) {
- log.error("{}/{}/{} is not a {}", tenant, namespace, componentName, ComponentTypeUtils.toString(componentType));
- throw new RestException(Response.Status.NOT_FOUND, String.format(ComponentTypeUtils.toString(componentType) + " %s doesn't exist", componentName));
- }
- SourceConfig config = SourceConfigUtils.convertFromDetails(functionMetaData.getFunctionDetails());
- return config;
+ final String componentName,
+ final AuthenticationParameters authParams) {
+ componentStatusRequestValidate(tenant, namespace, componentName, authParams);
+ Function.FunctionMetaData functionMetaData =
+ worker().getFunctionMetaDataManager().getFunctionMetaData(tenant, namespace, componentName);
+ return SourceConfigUtils.convertFromDetails(functionMetaData.getFunctionDetails());
}
@Override
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java
index 8255061d2b4..b265b601d0c 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java
@@ -18,7 +18,25 @@
*/
package org.apache.pulsar.functions.worker.rest.api;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.pulsar.functions.worker.rest.RestUtils.throwUnavailableException;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Supplier;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriBuilder;
import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.LongRunningProcessStatus;
import org.apache.pulsar.common.functions.WorkerInfo;
import org.apache.pulsar.common.io.ConnectorDefinition;
@@ -35,23 +53,8 @@ import org.apache.pulsar.functions.worker.SchedulerManager;
import org.apache.pulsar.functions.worker.WorkerService;
import org.apache.pulsar.functions.worker.WorkerUtils;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriBuilder;
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Supplier;
import org.apache.pulsar.functions.worker.service.api.Workers;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.pulsar.functions.worker.rest.RestUtils.throwUnavailableException;
-
@Slf4j
public class WorkerImpl implements Workers<PulsarWorkerService> {
@@ -79,29 +82,24 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
}
@Override
- public List<WorkerInfo> getCluster(String clientRole) {
+ public List<WorkerInfo> getCluster(AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
+ throwIfNotSuperUser(authParams, "get cluster");
List<WorkerInfo> workers = worker().getMembershipManager().getCurrentMembership();
return workers;
}
@Override
- public WorkerInfo getClusterLeader(String clientRole) {
+ public WorkerInfo getClusterLeader(AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to get cluster leader", clientRole);
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
+ throwIfNotSuperUser(authParams, "get cluster leader");
MembershipManager membershipManager = worker().getMembershipManager();
WorkerInfo leader = membershipManager.getLeader();
@@ -114,15 +112,12 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
}
@Override
- public Map<String, Collection<String>> getAssignments(String clientRole) {
+ public Map<String, Collection<String>> getAssignments(AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to get cluster assignments", clientRole);
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
+ throwIfNotSuperUser(authParams, "get cluster assignments");
FunctionRuntimeManager functionRuntimeManager = worker().getFunctionRuntimeManager();
Map<String, Map<String, Function.Assignment>> assignments = functionRuntimeManager.getCurrentAssignments();
@@ -133,33 +128,41 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
return ret;
}
- private boolean isSuperUser(final String clientRole) {
- return clientRole != null && worker().getWorkerConfig().getSuperUserRoles().contains(clientRole);
+ private void throwIfNotSuperUser(AuthenticationParameters authParams, String action) {
+ if (worker().getWorkerConfig().isAuthorizationEnabled()) {
+ try {
+ if (authParams.getClientRole() == null || !worker().getAuthorizationService().isSuperUser(authParams)
+ .get(worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(), SECONDS)) {
+ log.error("Client with role [{}] and originalPrincipal [{}] is not authorized to {}",
+ authParams.getClientRole(), authParams.getOriginalPrincipal(), action);
+ throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
+ }
+ } catch (ExecutionException | TimeoutException | InterruptedException e) {
+ log.warn("Time-out {} sec while checking the role {} originalPrincipal {} is a super user role ",
+ worker().getWorkerConfig().getZooKeeperOperationTimeoutSeconds(),
+ authParams.getClientRole(), authParams.getOriginalPrincipal());
+ throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
+ }
+ }
}
@Override
- public List<org.apache.pulsar.common.stats.Metrics> getWorkerMetrics(final String clientRole) {
+ public List<org.apache.pulsar.common.stats.Metrics> getWorkerMetrics(final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable() || worker().getMetricsGenerator() == null) {
throwUnavailableException();
}
-
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to get worker stats", clientRole);
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
+ throwIfNotSuperUser(authParams, "get worker stats");
return worker().getMetricsGenerator().generate();
}
@Override
- public List<WorkerFunctionInstanceStats> getFunctionsMetrics(String clientRole) throws IOException {
+ public List<WorkerFunctionInstanceStats> getFunctionsMetrics(AuthenticationParameters authParams)
+ throws IOException {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to get function stats", clientRole);
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
+ throwIfNotSuperUser(authParams, "get function stats");
Map<String, FunctionRuntimeInfo> functionRuntimes = worker().getFunctionRuntimeManager()
.getFunctionRuntimeInfos();
@@ -197,28 +200,20 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
}
@Override
- public List<ConnectorDefinition> getListOfConnectors(String clientRole) {
+ public List<ConnectorDefinition> getListOfConnectors(AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
-
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
-
+ throwIfNotSuperUser(authParams, "get list of connectors");
return this.worker().getConnectorsManager().getConnectorDefinitions();
}
@Override
- public void rebalance(final URI uri, final String clientRole) {
+ public void rebalance(final URI uri, final AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
-
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to rebalance cluster", clientRole);
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
- }
+ throwIfNotSuperUser(authParams, "rebalance cluster");
if (worker().getLeaderService().isLeader()) {
try {
@@ -240,7 +235,8 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
}
@Override
- public void drain(final URI uri, final String inWorkerId, final String clientRole, boolean calledOnLeaderUri) {
+ public void drain(final URI uri, final String inWorkerId, final AuthenticationParameters authParams,
+ boolean calledOnLeaderUri) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
@@ -249,15 +245,13 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
final String workerId = (inWorkerId == null || inWorkerId.isEmpty()) ? actualWorkerId : inWorkerId;
if (log.isDebugEnabled()) {
- log.debug("drain called with URI={}, inWorkerId={}, workerId={}, clientRole={}, calledOnLeaderUri={}, "
- + "on actual worker-id={}",
- uri, inWorkerId, workerId, clientRole, calledOnLeaderUri, actualWorkerId);
+ log.debug("drain called with URI={}, inWorkerId={}, workerId={}, clientRole={}, originalPrincipal={}, "
+ + "calledOnLeaderUri={}, on actual worker-id={}",
+ uri, inWorkerId, workerId, authParams.getClientRole(), authParams.getOriginalPrincipal(),
+ calledOnLeaderUri, actualWorkerId);
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to drain worker {}", clientRole, workerId);
- throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform drain operation");
- }
+ throwIfNotSuperUser(authParams, "drain worker");
// Depending on which operations we decide to allow, we may add checks here to error/exception if
// calledOnLeaderUri is true on a non-leader
@@ -286,8 +280,9 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
}
@Override
- public LongRunningProcessStatus getDrainStatus(final URI uri, final String inWorkerId, final String clientRole,
- boolean calledOnLeaderUri) {
+ public LongRunningProcessStatus getDrainStatus(final URI uri, final String inWorkerId,
+ final AuthenticationParameters authParams,
+ boolean calledOnLeaderUri) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
@@ -297,15 +292,12 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
if (log.isDebugEnabled()) {
log.debug("getDrainStatus called with uri={}, inWorkerId={}, workerId={}, clientRole={}, "
- + " calledOnLeaderUri={}, on actual workerId={}",
- uri, inWorkerId, workerId, clientRole, calledOnLeaderUri, actualWorkerId);
+ + "originalPrincipal={}, calledOnLeaderUri={}, on actual workerId={}",
+ uri, inWorkerId, workerId, authParams.getClientRole(), authParams.getOriginalPrincipal(),
+ calledOnLeaderUri, actualWorkerId);
}
- if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
- log.error("Client [{}] is not authorized to get drain status of worker {}", clientRole, workerId);
- throw new RestException(Status.UNAUTHORIZED,
- "Client is not authorized to get the status of a drain operation");
- }
+ throwIfNotSuperUser(authParams, "get drain status of worker");
// Depending on which operations we decide to allow, we may add checks here to error/exception if
// calledOnLeaderUri is true on a non-leader
@@ -322,7 +314,7 @@ public class WorkerImpl implements Workers<PulsarWorkerService> {
}
@Override
- public Boolean isLeaderReady(final String clientRole) {
+ public boolean isLeaderReady(AuthenticationParameters authParams) {
if (!isWorkerServiceAvailable()) {
throwUnavailableException();
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionsApiV2Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionsApiV2Resource.java
index a53c2ac16d9..e4de1019d58 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionsApiV2Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionsApiV2Resource.java
@@ -73,7 +73,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @FormDataParam("functionDetails") String functionDetailsJson) {
return functions().registerFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionDetailsJson, clientAppId());
+ functionPkgUrl, functionDetailsJson, authParams());
}
@PUT
@@ -94,7 +94,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @FormDataParam("functionDetails") String functionDetailsJson) {
return functions().updateFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionDetailsJson, clientAppId());
+ functionPkgUrl, functionDetailsJson, authParams());
}
@@ -111,7 +111,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
public Response deregisterFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- return functions().deregisterFunction(tenant, namespace, functionName, clientAppId());
+ return functions().deregisterFunction(tenant, namespace, functionName, authParams());
}
@GET
@@ -130,8 +130,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) throws IOException {
- return functions().getFunctionInfo(
- tenant, namespace, functionName, clientAppId());
+ return functions().getFunctionInfo(tenant, namespace, functionName, authParams());
}
@GET
@@ -152,7 +151,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @PathParam("instanceId") String instanceId) throws IOException {
return functions().getFunctionInstanceStatus(tenant, namespace, functionName, instanceId, uri.getRequestUri(),
- clientAppId());
+ authParams());
}
@GET
@@ -169,7 +168,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
public Response getFunctionStatus(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) throws IOException {
- return functions().getFunctionStatusV2(tenant, namespace, functionName, uri.getRequestUri(), clientAppId());
+ return functions().getFunctionStatusV2(tenant, namespace, functionName, uri.getRequestUri(), authParams());
}
@GET
@@ -185,7 +184,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
@Path("/{tenant}/{namespace}")
public Response listFunctions(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace) {
- return functions().listFunctions(tenant, namespace, clientAppId());
+ return functions().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -208,7 +207,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @FormDataParam("dataStream") InputStream triggerStream,
final @FormDataParam("topic") String topic) {
return functions().triggerFunction(tenant, namespace, functionName, triggerValue, triggerStream, topic,
- clientAppId());
+ authParams());
}
@GET
@@ -227,7 +226,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName,
final @PathParam("key") String key) {
- return functions().getFunctionState(tenant, namespace, functionName, key, clientAppId());
+ return functions().getFunctionState(tenant, namespace, functionName, key, authParams());
}
@POST
@@ -243,7 +242,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace, final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
return functions().restartFunctionInstance(tenant, namespace, functionName, instanceId, uri.getRequestUri(),
- clientAppId());
+ authParams());
}
@POST
@@ -254,8 +253,9 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
@Path("/{tenant}/{namespace}/{functionName}/restart")
@Consumes(MediaType.APPLICATION_JSON)
public Response restartFunction(final @PathParam("tenant") String tenant,
- final @PathParam("namespace") String namespace, final @PathParam("functionName") String functionName) {
- return functions().restartFunctionInstances(tenant, namespace, functionName, clientAppId());
+ final @PathParam("namespace") String namespace,
+ final @PathParam("functionName") String functionName) {
+ return functions().restartFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -269,7 +269,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace, final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
return functions().stopFunctionInstance(tenant, namespace, functionName, instanceId, uri.getRequestUri(),
- clientAppId());
+ authParams());
}
@POST
@@ -280,8 +280,9 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
@Path("/{tenant}/{namespace}/{functionName}/stop")
@Consumes(MediaType.APPLICATION_JSON)
public Response stopFunction(final @PathParam("tenant") String tenant,
- final @PathParam("namespace") String namespace, final @PathParam("functionName") String functionName) {
- return functions().stopFunctionInstances(tenant, namespace, functionName, clientAppId());
+ final @PathParam("namespace") String namespace,
+ final @PathParam("functionName") String functionName) {
+ return functions().stopFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -293,7 +294,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFunction(final @FormDataParam("data") InputStream uploadedInputStream,
final @FormDataParam("path") String path) {
- return functions().uploadFunction(uploadedInputStream, path, clientAppId());
+ return functions().uploadFunction(uploadedInputStream, path, authParams());
}
@GET
@@ -303,7 +304,7 @@ public class FunctionsApiV2Resource extends FunctionApiResource {
)
@Path("/download")
public Response downloadFunction(final @QueryParam("path") String path) {
- return functions().downloadFunction(path, clientAppId());
+ return functions().downloadFunction(path, authParams());
}
@GET
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerApiV2Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerApiV2Resource.java
index 7bf999b629c..a75ee8fc29c 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerApiV2Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerApiV2Resource.java
@@ -46,6 +46,9 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
+import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
+import org.apache.pulsar.functions.worker.rest.FunctionApiResource;
import org.apache.pulsar.functions.worker.service.api.Workers;
@Slf4j
@@ -77,12 +80,25 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
return get().getWorkers();
}
+ /**
+ * @deprecated use {@link #authParams()} instead
+ */
+ @Deprecated
public String clientAppId() {
return httpRequest != null
? (String) httpRequest.getAttribute(AuthenticationFilter.AuthenticatedRoleAttributeName)
: null;
}
+ public AuthenticationParameters authParams() {
+ return AuthenticationParameters.builder()
+ .clientRole(clientAppId())
+ .originalPrincipal(httpRequest.getHeader(FunctionApiResource.ORIGINAL_PRINCIPAL_HEADER))
+ .clientAuthenticationDataSource((AuthenticationDataSource)
+ httpRequest.getAttribute(AuthenticationFilter.AuthenticatedDataAttributeName))
+ .build();
+ }
+
@GET
@ApiOperation(
value = "Fetches information about the Pulsar cluster running Pulsar Functions",
@@ -96,7 +112,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
@Path("/cluster")
@Produces(MediaType.APPLICATION_JSON)
public List<WorkerInfo> getCluster() {
- return workers().getCluster(clientAppId());
+ return workers().getCluster(authParams());
}
@GET
@@ -111,7 +127,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
@Path("/cluster/leader")
@Produces(MediaType.APPLICATION_JSON)
public WorkerInfo getClusterLeader() {
- return workers().getClusterLeader(clientAppId());
+ return workers().getClusterLeader(authParams());
}
@GET
@@ -126,7 +142,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
@Path("/assignments")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Collection<String>> getAssignments() {
- return workers().getAssignments(clientAppId());
+ return workers().getAssignments(authParams());
}
@GET
@@ -141,7 +157,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/connectors")
public List<ConnectorDefinition> getConnectorsList() throws IOException {
- return workers().getListOfConnectors(clientAppId());
+ return workers().getListOfConnectors(authParams());
}
@PUT
@@ -155,7 +171,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/rebalance")
public void rebalance() {
- workers().rebalance(uri.getRequestUri(), clientAppId());
+ workers().rebalance(uri.getRequestUri(), authParams());
}
@PUT
@@ -171,7 +187,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/leader/drain")
public void drainAtLeader(@QueryParam("workerId") String workerId) {
- workers().drain(uri.getRequestUri(), workerId, clientAppId(), true);
+ workers().drain(uri.getRequestUri(), workerId, authParams(), true);
}
@PUT
@@ -187,7 +203,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/drain")
public void drain() {
- workers().drain(uri.getRequestUri(), null, clientAppId(), false);
+ workers().drain(uri.getRequestUri(), null, authParams(), false);
}
@GET
@@ -201,7 +217,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/leader/drain")
public LongRunningProcessStatus getDrainStatus(@QueryParam("workerId") String workerId) {
- return workers().getDrainStatus(uri.getRequestUri(), workerId, clientAppId(), true);
+ return workers().getDrainStatus(uri.getRequestUri(), workerId, authParams(), true);
}
@GET
@@ -215,7 +231,7 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/drain")
public LongRunningProcessStatus getDrainStatus() {
- return workers().getDrainStatus(uri.getRequestUri(), null, clientAppId(), false);
+ return workers().getDrainStatus(uri.getRequestUri(), null, authParams(), false);
}
@GET
@@ -228,6 +244,6 @@ public class WorkerApiV2Resource implements Supplier<WorkerService> {
})
@Path("/cluster/leader/ready")
public Boolean isLeaderReady() {
- return workers().isLeaderReady(clientAppId());
+ return workers().isLeaderReady(authParams());
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerStatsApiV2Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerStatsApiV2Resource.java
index 19c5d8ef3ec..1bb36537fe2 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerStatsApiV2Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v2/WorkerStatsApiV2Resource.java
@@ -38,6 +38,9 @@ import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.List;
import java.util.function.Supplier;
+import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
+import org.apache.pulsar.functions.worker.rest.FunctionApiResource;
import org.apache.pulsar.functions.worker.service.api.Workers;
@Slf4j
@@ -67,6 +70,19 @@ public class WorkerStatsApiV2Resource implements Supplier<WorkerService> {
return get().getWorkers();
}
+ AuthenticationParameters authParams() {
+ return AuthenticationParameters.builder()
+ .clientRole(clientAppId())
+ .originalPrincipal(httpRequest.getHeader(FunctionApiResource.ORIGINAL_PRINCIPAL_HEADER))
+ .clientAuthenticationDataSource((AuthenticationDataSource)
+ httpRequest.getAttribute(AuthenticationFilter.AuthenticatedDataAttributeName))
+ .build();
+ }
+
+ /**
+ * @deprecated use {@link AuthenticationParameters} instead
+ */
+ @Deprecated
public String clientAppId() {
return httpRequest != null
? (String) httpRequest.getAttribute(AuthenticationFilter.AuthenticatedRoleAttributeName)
@@ -86,7 +102,7 @@ public class WorkerStatsApiV2Resource implements Supplier<WorkerService> {
})
@Produces(MediaType.APPLICATION_JSON)
public List<org.apache.pulsar.common.stats.Metrics> getMetrics() throws Exception {
- return workers().getWorkerMetrics(clientAppId());
+ return workers().getWorkerMetrics(authParams());
}
@GET
@@ -102,6 +118,6 @@ public class WorkerStatsApiV2Resource implements Supplier<WorkerService> {
})
@Produces(MediaType.APPLICATION_JSON)
public List<WorkerFunctionInstanceStats> getStats() throws IOException {
- return workers().getFunctionsMetrics(clientAppId());
+ return workers().getFunctionsMetrics(authParams());
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionsApiV3Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionsApiV3Resource.java
index 5044eb6a893..1c4839b17a2 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionsApiV3Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionsApiV3Resource.java
@@ -73,7 +73,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @FormDataParam("functionConfig") FunctionConfig functionConfig) {
functions().registerFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionConfig, clientAppId(), clientAuthData());
+ functionPkgUrl, functionConfig, authParams());
}
@@ -90,7 +90,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @FormDataParam("updateOptions") UpdateOptionsImpl updateOptions) {
functions().updateFunction(tenant, namespace, functionName, uploadedInputStream, fileDetail,
- functionPkgUrl, functionConfig, clientAppId(), clientAuthData(), updateOptions);
+ functionPkgUrl, functionConfig, authParams(), updateOptions);
}
@@ -99,7 +99,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
public void deregisterFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- functions().deregisterFunction(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().deregisterFunction(tenant, namespace, functionName, authParams());
}
@GET
@@ -107,7 +107,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
public FunctionConfig getFunctionInfo(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- return functions().getFunctionInfo(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ return functions().getFunctionInfo(tenant, namespace, functionName, authParams());
}
@GET
@@ -115,7 +115,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
@Path("/{tenant}/{namespace}")
public List<String> listFunctions(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace) {
- return functions().listFunctions(tenant, namespace, clientAppId(), clientAuthData());
+ return functions().listFunctions(tenant, namespace, authParams());
}
@GET
@@ -137,7 +137,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) throws IOException {
return functions().getFunctionInstanceStatus(
- tenant, namespace, functionName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ tenant, namespace, functionName, instanceId, uri.getRequestUri(), authParams());
}
@GET
@@ -158,7 +158,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) throws IOException {
return functions().getFunctionStatus(
- tenant, namespace, functionName, uri.getRequestUri(), clientAppId(), clientAuthData());
+ tenant, namespace, functionName, uri.getRequestUri(), authParams());
}
@GET
@@ -177,7 +177,8 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
public FunctionStatsImpl getFunctionStats(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) throws IOException {
- return functions().getFunctionStats(tenant, namespace, functionName, uri.getRequestUri(), clientAppId(), clientAuthData());
+ return functions().getFunctionStats(tenant, namespace, functionName,
+ uri.getRequestUri(), authParams());
}
@GET
@@ -199,7 +200,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) throws IOException {
return functions().getFunctionsInstanceStats(
- tenant, namespace, functionName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ tenant, namespace, functionName, instanceId, uri.getRequestUri(), authParams());
}
@POST
@@ -211,7 +212,8 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @FormDataParam("data") String input,
final @FormDataParam("dataStream") InputStream uploadedInputStream,
final @FormDataParam("topic") String topic) {
- return functions().triggerFunction(tenant, namespace, functionName, input, uploadedInputStream, topic, clientAppId(), clientAuthData());
+ return functions().triggerFunction(tenant, namespace, functionName, input,
+ uploadedInputStream, topic, authParams());
}
@POST
@@ -228,7 +230,8 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
- functions().restartFunctionInstance(tenant, namespace, functionName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ functions().restartFunctionInstance(tenant, namespace, functionName, instanceId,
+ this.uri.getRequestUri(), authParams());
}
@POST
@@ -243,7 +246,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
public void restartFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- functions().restartFunctionInstances(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().restartFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -259,7 +262,8 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
- functions().stopFunctionInstance(tenant, namespace, functionName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ functions().stopFunctionInstance(tenant, namespace, functionName, instanceId,
+ this.uri.getRequestUri(), authParams());
}
@POST
@@ -274,7 +278,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
public void stopFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- functions().stopFunctionInstances(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().stopFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -290,7 +294,8 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName,
final @PathParam("instanceId") String instanceId) {
- functions().startFunctionInstance(tenant, namespace, functionName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ functions().startFunctionInstance(tenant, namespace, functionName, instanceId,
+ this.uri.getRequestUri(), authParams());
}
@POST
@@ -305,7 +310,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
public void startFunction(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName) {
- functions().startFunctionInstances(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ functions().startFunctionInstances(tenant, namespace, functionName, authParams());
}
@POST
@@ -313,13 +318,13 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadFunction(final @FormDataParam("data") InputStream uploadedInputStream,
final @FormDataParam("path") String path) {
- functions().uploadFunction(uploadedInputStream, path, clientAppId(), clientAuthData());
+ functions().uploadFunction(uploadedInputStream, path, authParams());
}
@GET
@Path("/download")
public StreamingOutput downloadFunction(final @QueryParam("path") String path) {
- return functions().downloadFunction(path, clientAppId(), clientAuthData());
+ return functions().downloadFunction(path, authParams());
}
@GET
@@ -336,7 +341,8 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
@ApiParam(value = "The name of functions")
final @PathParam("functionName") String functionName) {
- return functions().downloadFunction(tenant, namespace, functionName, clientAppId(), clientAuthData());
+ return functions()
+ .downloadFunction(tenant, namespace, functionName, authParams());
}
@GET
@@ -355,7 +361,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("functionName") String functionName,
final @PathParam("key") String key) throws IOException {
- return functions().getFunctionState(tenant, namespace, functionName, key, clientAppId(), clientAuthData());
+ return functions().getFunctionState(tenant, namespace, functionName, key, authParams());
}
@POST
@@ -366,7 +372,7 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @PathParam("functionName") String functionName,
final @PathParam("key") String key,
final @FormDataParam("state") FunctionState stateJson) throws IOException {
- functions().putFunctionState(tenant, namespace, functionName, key, stateJson, clientAppId(), clientAuthData());
+ functions().putFunctionState(tenant, namespace, functionName, key, stateJson, authParams());
}
@PUT
@@ -387,6 +393,6 @@ public class FunctionsApiV3Resource extends FunctionApiResource {
final @FormDataParam("delete") boolean delete) {
functions().updateFunctionOnWorkerLeader(tenant, namespace, functionName, uploadedInputStream,
- delete, uri.getRequestUri(), clientAppId(), clientAuthData());
+ delete, uri.getRequestUri(), authParams());
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SinksApiV3Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SinksApiV3Resource.java
index 4bff94476c5..53523cfe976 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SinksApiV3Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SinksApiV3Resource.java
@@ -71,7 +71,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @FormDataParam("sinkConfig") SinkConfig sinkConfig) {
sinks().registerSink(tenant, namespace, sinkName, uploadedInputStream, fileDetail,
- functionPkgUrl, sinkConfig, clientAppId(), clientAuthData());
+ functionPkgUrl, sinkConfig, authParams());
}
@PUT
@@ -87,7 +87,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @FormDataParam("updateOptions") UpdateOptionsImpl updateOptions) {
sinks().updateSink(tenant, namespace, sinkName, uploadedInputStream, fileDetail,
- functionPkgUrl, sinkConfig, clientAppId(), clientAuthData(), updateOptions);
+ functionPkgUrl, sinkConfig, authParams(), updateOptions);
}
@DELETE
@@ -95,7 +95,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
public void deregisterSink(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName) {
- sinks().deregisterFunction(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().deregisterFunction(tenant, namespace, sinkName, authParams());
}
@GET
@@ -104,7 +104,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName)
throws IOException {
- return sinks().getSinkInfo(tenant, namespace, sinkName);
+ return sinks().getSinkInfo(tenant, namespace, sinkName, authParams());
}
@GET
@@ -125,7 +125,8 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName,
final @PathParam("instanceId") String instanceId) throws IOException {
- return sinks().getSinkInstanceStatus(tenant, namespace, sinkName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ return sinks().getSinkInstanceStatus(tenant, namespace, sinkName, instanceId, uri.getRequestUri(),
+ authParams());
}
@GET
@@ -144,14 +145,14 @@ public class SinksApiV3Resource extends FunctionApiResource {
public SinkStatus getSinkStatus(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName) throws IOException {
- return sinks().getSinkStatus(tenant, namespace, sinkName, uri.getRequestUri(), clientAppId(), clientAuthData());
+ return sinks().getSinkStatus(tenant, namespace, sinkName, uri.getRequestUri(), authParams());
}
@GET
@Path("/{tenant}/{namespace}")
public List<String> listSink(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace) {
- return sinks().listFunctions(tenant, namespace, clientAppId(), clientAuthData());
+ return sinks().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -167,7 +168,8 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName,
final @PathParam("instanceId") String instanceId) {
- sinks().restartFunctionInstance(tenant, namespace, sinkName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ sinks().restartFunctionInstance(tenant, namespace, sinkName, instanceId, this.uri.getRequestUri(),
+ authParams());
}
@POST
@@ -179,7 +181,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
public void restartSink(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName) {
- sinks().restartFunctionInstances(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().restartFunctionInstances(tenant, namespace, sinkName, authParams());
}
@POST
@@ -193,7 +195,8 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName,
final @PathParam("instanceId") String instanceId) {
- sinks().stopFunctionInstance(tenant, namespace, sinkName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ sinks().stopFunctionInstance(tenant, namespace, sinkName, instanceId, this.uri.getRequestUri(),
+ authParams());
}
@POST
@@ -206,7 +209,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
public void stopSink(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName) {
- sinks().stopFunctionInstances(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().stopFunctionInstances(tenant, namespace, sinkName, authParams());
}
@POST
@@ -220,7 +223,8 @@ public class SinksApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName,
final @PathParam("instanceId") String instanceId) {
- sinks().startFunctionInstance(tenant, namespace, sinkName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ sinks().startFunctionInstance(tenant, namespace, sinkName, instanceId, this.uri.getRequestUri(),
+ authParams());
}
@POST
@@ -233,7 +237,7 @@ public class SinksApiV3Resource extends FunctionApiResource {
public void startSink(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sinkName") String sinkName) {
- sinks().startFunctionInstances(tenant, namespace, sinkName, clientAppId(), clientAuthData());
+ sinks().startFunctionInstances(tenant, namespace, sinkName, authParams());
}
@GET
@@ -274,6 +278,6 @@ public class SinksApiV3Resource extends FunctionApiResource {
})
@Path("/reloadBuiltInSinks")
public void reloadSinks() {
- sinks().reloadConnectors(clientAppId(), clientAuthData());
+ sinks().reloadConnectors(authParams());
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SourcesApiV3Resource.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SourcesApiV3Resource.java
index 16901ee7705..a05fbe75cd3 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SourcesApiV3Resource.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/v3/SourcesApiV3Resource.java
@@ -71,7 +71,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @FormDataParam("sourceConfig") SourceConfig sourceConfig) {
sources().registerSource(tenant, namespace, sourceName, uploadedInputStream, fileDetail,
- functionPkgUrl, sourceConfig, clientAppId(), clientAuthData());
+ functionPkgUrl, sourceConfig, authParams());
}
@@ -88,7 +88,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @FormDataParam("updateOptions") UpdateOptionsImpl updateOptions) {
sources().updateSource(tenant, namespace, sourceName, uploadedInputStream, fileDetail,
- functionPkgUrl, sourceConfig, clientAppId(), clientAuthData(), updateOptions);
+ functionPkgUrl, sourceConfig, authParams(), updateOptions);
}
@@ -97,7 +97,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
public void deregisterSource(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName) {
- sources().deregisterFunction(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().deregisterFunction(tenant, namespace, sourceName, authParams());
}
@GET
@@ -107,7 +107,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName)
throws IOException {
- return sources().getSourceInfo(tenant, namespace, sourceName);
+ return sources().getSourceInfo(tenant, namespace, sourceName, authParams());
}
@GET
@@ -128,8 +128,8 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName,
final @PathParam("instanceId") String instanceId) throws IOException {
- return sources().getSourceInstanceStatus(
- tenant, namespace, sourceName, instanceId, uri.getRequestUri(), clientAppId(), clientAuthData());
+ return sources().getSourceInstanceStatus(tenant, namespace, sourceName, instanceId, uri.getRequestUri(),
+ authParams());
}
@GET
@@ -148,7 +148,8 @@ public class SourcesApiV3Resource extends FunctionApiResource {
public SourceStatus getSourceStatus(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName) throws IOException {
- return sources().getSourceStatus(tenant, namespace, sourceName, uri.getRequestUri(), clientAppId(), clientAuthData());
+ return sources()
+ .getSourceStatus(tenant, namespace, sourceName, uri.getRequestUri(), authParams());
}
@GET
@@ -156,7 +157,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
@Path("/{tenant}/{namespace}")
public List<String> listSources(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace) {
- return sources().listFunctions(tenant, namespace, clientAppId(), clientAuthData());
+ return sources().listFunctions(tenant, namespace, authParams());
}
@POST
@@ -172,7 +173,8 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName,
final @PathParam("instanceId") String instanceId) {
- sources().restartFunctionInstance(tenant, namespace, sourceName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ sources().restartFunctionInstance(tenant, namespace, sourceName, instanceId, this.uri.getRequestUri(),
+ authParams());
}
@POST
@@ -185,7 +187,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
public void restartSource(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName) {
- sources().restartFunctionInstances(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().restartFunctionInstances(tenant, namespace, sourceName, authParams());
}
@POST
@@ -199,7 +201,8 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName,
final @PathParam("instanceId") String instanceId) {
- sources().stopFunctionInstance(tenant, namespace, sourceName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ sources().stopFunctionInstance(tenant, namespace, sourceName, instanceId, this.uri.getRequestUri(),
+ authParams());
}
@POST
@@ -212,7 +215,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
public void stopSource(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName) {
- sources().stopFunctionInstances(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().stopFunctionInstances(tenant, namespace, sourceName, authParams());
}
@POST
@@ -226,7 +229,8 @@ public class SourcesApiV3Resource extends FunctionApiResource {
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName,
final @PathParam("instanceId") String instanceId) {
- sources().startFunctionInstance(tenant, namespace, sourceName, instanceId, this.uri.getRequestUri(), clientAppId(), clientAuthData());
+ sources().startFunctionInstance(tenant, namespace, sourceName, instanceId, this.uri.getRequestUri(),
+ authParams());
}
@POST
@@ -239,7 +243,7 @@ public class SourcesApiV3Resource extends FunctionApiResource {
public void startSource(final @PathParam("tenant") String tenant,
final @PathParam("namespace") String namespace,
final @PathParam("sourceName") String sourceName) {
- sources().startFunctionInstances(tenant, namespace, sourceName, clientAppId(), clientAuthData());
+ sources().startFunctionInstances(tenant, namespace, sourceName, authParams());
}
@GET
@@ -290,6 +294,6 @@ public class SourcesApiV3Resource extends FunctionApiResource {
})
@Path("/reloadBuiltInSources")
public void reloadSources() {
- sources().reloadConnectors(clientAppId(), clientAuthData());
+ sources().reloadConnectors(authParams());
}
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Component.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Component.java
index 5f0c1a96703..7110b07d29e 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Component.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Component.java
@@ -22,8 +22,7 @@ import java.io.InputStream;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.StreamingOutput;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.common.functions.FunctionConfig;
import org.apache.pulsar.common.functions.FunctionState;
import org.apache.pulsar.common.io.ConnectorDefinition;
@@ -39,121 +38,55 @@ public interface Component<W extends WorkerService> {
W worker();
- void deregisterFunction(final String tenant,
- final String namespace,
- final String componentName,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps);
-
- FunctionConfig getFunctionInfo(final String tenant,
- final String namespace,
- final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void stopFunctionInstance(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void startFunctionInstance(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void restartFunctionInstance(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void startFunctionInstances(final String tenant,
- final String namespace,
- final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void stopFunctionInstances(final String tenant,
- final String namespace,
- final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void restartFunctionInstances(final String tenant,
- final String namespace,
- final String componentName,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- FunctionStatsImpl getFunctionStats(final String tenant,
- final String namespace,
- final String componentName,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- FunctionInstanceStatsDataImpl getFunctionsInstanceStats(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- String triggerFunction(final String tenant,
- final String namespace,
- final String functionName,
- final String input,
- final InputStream uploadedInputStream,
- final String topic,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- List<String> listFunctions(final String tenant,
- final String namespace,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- FunctionState getFunctionState(final String tenant,
- final String namespace,
- final String functionName,
- final String key,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void putFunctionState(final String tenant,
- final String namespace,
- final String functionName,
- final String key,
- final FunctionState state,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- void uploadFunction(final InputStream uploadedInputStream,
- final String path,
- String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- StreamingOutput downloadFunction(String path,
- String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps);
-
- StreamingOutput downloadFunction(String tenant,
- String namespace,
- String componentName,
- String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps);
+ void deregisterFunction(String tenant, String namespace, String componentName, AuthenticationParameters authParams);
- List<ConnectorDefinition> getListOfConnectors();
+ FunctionConfig getFunctionInfo(String tenant, String namespace, String componentName,
+ AuthenticationParameters authParams);
+
+ void stopFunctionInstance(String tenant, String namespace, String componentName, String instanceId, URI uri,
+ AuthenticationParameters authParams);
+
+ void startFunctionInstance(String tenant, String namespace, String componentName, String instanceId, URI uri,
+ AuthenticationParameters authParams);
+
+ void restartFunctionInstance(String tenant, String namespace, String componentName, String instanceId, URI uri,
+ AuthenticationParameters authParams);
+
+ void startFunctionInstances(String tenant, String namespace, String componentName,
+ AuthenticationParameters authParams);
+
+ void stopFunctionInstances(String tenant, String namespace, String componentName,
+ AuthenticationParameters authParams);
+
+ void restartFunctionInstances(String tenant, String namespace, String componentName,
+ AuthenticationParameters authParams);
+
+ FunctionStatsImpl getFunctionStats(String tenant, String namespace, String componentName, URI uri,
+ AuthenticationParameters authParams);
+
+ FunctionInstanceStatsDataImpl getFunctionsInstanceStats(String tenant, String namespace, String componentName,
+ String instanceId, URI uri,
+ AuthenticationParameters authParams);
+ String triggerFunction(String tenant, String namespace, String functionName, String input,
+ InputStream uploadedInputStream, String topic, AuthenticationParameters authParams);
+
+ List<String> listFunctions(String tenant, String namespace, AuthenticationParameters authParams);
+
+ FunctionState getFunctionState(String tenant, String namespace, String functionName, String key,
+ AuthenticationParameters authParams);
+
+ void putFunctionState(String tenant, String namespace, String functionName, String key, FunctionState state,
+ AuthenticationParameters authParams);
+
+ void uploadFunction(InputStream uploadedInputStream, String path, AuthenticationParameters authParams);
+
+ StreamingOutput downloadFunction(String path, AuthenticationParameters authParams);
+
+ StreamingOutput downloadFunction(String tenant, String namespace, String componentName,
+ AuthenticationParameters authParams);
+
+ List<ConnectorDefinition> getListOfConnectors();
- void reloadConnectors(String clientRole, AuthenticationDataSource clientAuthenticationDataHttps);
+ void reloadConnectors(AuthenticationParameters authParams);
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Functions.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Functions.java
index 7a155d51fe2..9de96a1a5b0 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Functions.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Functions.java
@@ -20,8 +20,7 @@ package org.apache.pulsar.functions.worker.service.api;
import java.io.InputStream;
import java.net.URI;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.common.functions.FunctionConfig;
import org.apache.pulsar.common.functions.UpdateOptionsImpl;
import org.apache.pulsar.common.policies.data.FunctionStatus;
@@ -34,49 +33,67 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
*/
public interface Functions<W extends WorkerService> extends Component<W> {
- void registerFunction(final String tenant,
- final String namespace,
- final String functionName,
- final InputStream uploadedInputStream,
- final FormDataContentDisposition fileDetail,
- final String functionPkgUrl,
- final FunctionConfig functionConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps);
+ /**
+ * Register a new function.
+ * @param tenant The tenant of a Pulsar Function
+ * @param namespace The namespace of a Pulsar Function
+ * @param functionName The name of a Pulsar Function
+ * @param uploadedInputStream Input stream of bytes
+ * @param fileDetail A form-data content disposition header
+ * @param functionPkgUrl URL path of the Pulsar Function package
+ * @param functionConfig Configuration of Pulsar Function
+ * @param authParams the authentication parameters associated with the request
+ */
+ void registerFunction(String tenant,
+ String namespace,
+ String functionName,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String functionPkgUrl,
+ FunctionConfig functionConfig,
+ AuthenticationParameters authParams);
- void updateFunction(final String tenant,
- final String namespace,
- final String functionName,
- final InputStream uploadedInputStream,
- final FormDataContentDisposition fileDetail,
- final String functionPkgUrl,
- final FunctionConfig functionConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps,
+ /**
+ * Update a function.
+ * @param tenant The tenant of a Pulsar Function
+ * @param namespace The namespace of a Pulsar Function
+ * @param functionName The name of a Pulsar Function
+ * @param uploadedInputStream Input stream of bytes
+ * @param fileDetail A form-data content disposition header
+ * @param functionPkgUrl URL path of the Pulsar Function package
+ * @param functionConfig Configuration of Pulsar Function
+ * @param authParams the authentication parameters associated with the request
+ * @param updateOptions Options while updating the function
+ */
+ void updateFunction(String tenant,
+ String namespace,
+ String functionName,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String functionPkgUrl,
+ FunctionConfig functionConfig,
+ AuthenticationParameters authParams,
UpdateOptionsImpl updateOptions);
- void updateFunctionOnWorkerLeader(final String tenant,
- final String namespace,
- final String functionName,
- final InputStream uploadedInputStream,
- final boolean delete,
+ void updateFunctionOnWorkerLeader(String tenant,
+ String namespace,
+ String functionName,
+ InputStream uploadedInputStream,
+ boolean delete,
URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
+ AuthenticationParameters authParams);
- FunctionStatus getFunctionStatus(final String tenant,
- final String namespace,
- final String componentName,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
+ FunctionStatus getFunctionStatus(String tenant,
+ String namespace,
+ String componentName,
+ URI uri,
+ AuthenticationParameters authParams);
- FunctionInstanceStatusData getFunctionInstanceStatus(final String tenant,
- final String namespace,
- final String componentName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
+ FunctionInstanceStatusData getFunctionInstanceStatus(String tenant,
+ String namespace,
+ String componentName,
+ String instanceId,
+ URI uri,
+ AuthenticationParameters authParams);
}
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/FunctionsV2.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/FunctionsV2.java
index 6b21657586a..4e1b0df6c0c 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/FunctionsV2.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/FunctionsV2.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.Response;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.common.io.ConnectorDefinition;
import org.apache.pulsar.functions.worker.WorkerService;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
@@ -32,23 +33,23 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
*/
public interface FunctionsV2<W extends WorkerService> {
- Response getFunctionInfo(final String tenant,
- final String namespace,
- final String functionName,
- String clientRole) throws IOException;
+ Response getFunctionInfo(String tenant,
+ String namespace,
+ String functionName,
+ AuthenticationParameters authParams) throws IOException;
- Response getFunctionInstanceStatus(final String tenant,
- final String namespace,
- final String functionName,
- final String instanceId,
- URI uri,
- String clientRole) throws IOException;
+ Response getFunctionInstanceStatus(String tenant,
+ String namespace,
+ String functionName,
+ String instanceId,
+ URI uri,
+ AuthenticationParameters authParams) throws IOException;
Response getFunctionStatusV2(String tenant,
String namespace,
String functionName,
URI requestUri,
- String clientRole) throws IOException;
+ AuthenticationParameters authParams) throws IOException;
Response registerFunction(String tenant,
String namespace,
@@ -57,7 +58,8 @@ public interface FunctionsV2<W extends WorkerService> {
FormDataContentDisposition fileDetail,
String functionPkgUrl,
String functionDetailsJson,
- String clientRole);
+ AuthenticationParameters authParams);
+
Response updateFunction(String tenant,
String namespace,
@@ -66,14 +68,12 @@ public interface FunctionsV2<W extends WorkerService> {
FormDataContentDisposition fileDetail,
String functionPkgUrl,
String functionDetailsJson,
- String clientRole);
+ AuthenticationParameters authParams);
- Response deregisterFunction(String tenant,
- String namespace,
- String functionName,
- String clientAppId);
+ Response deregisterFunction(String tenant, String namespace, String functionName,
+ AuthenticationParameters authParams);
- Response listFunctions(String tenant, String namespace, String clientRole);
+ Response listFunctions(String tenant, String namespace, AuthenticationParameters authParams);
Response triggerFunction(String tenant,
String namespace,
@@ -81,45 +81,44 @@ public interface FunctionsV2<W extends WorkerService> {
String triggerValue,
InputStream triggerStream,
String topic,
- String clientRole);
+ AuthenticationParameters authParams);
Response getFunctionState(String tenant,
String namespace,
String functionName,
String key,
- String clientRole);
-
+ AuthenticationParameters authParams);
Response restartFunctionInstance(String tenant,
String namespace,
String functionName,
String instanceId,
URI uri,
- String clientRole);
+ AuthenticationParameters authParams);
+
Response restartFunctionInstances(String tenant,
String namespace,
String functionName,
- String clientRole);
+ AuthenticationParameters authParams);
Response stopFunctionInstance(String tenant,
String namespace,
String functionName,
String instanceId,
URI uri,
- String clientRole);
+ AuthenticationParameters authParams);
Response stopFunctionInstances(String tenant,
String namespace,
String functionName,
- String clientRole);
+ AuthenticationParameters authParams);
Response uploadFunction(InputStream uploadedInputStream,
String path,
- String clientRole);
-
- Response downloadFunction(String path, String clientRole);
+ AuthenticationParameters authParams);
+ Response downloadFunction(String path, AuthenticationParameters authParams);
List<ConnectorDefinition> getListOfConnectors();
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sinks.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sinks.java
index fc6bdf7bf6d..340da1e99df 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sinks.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sinks.java
@@ -21,8 +21,7 @@ package org.apache.pulsar.functions.worker.service.api;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.common.functions.UpdateOptionsImpl;
import org.apache.pulsar.common.io.ConfigFieldDefinition;
import org.apache.pulsar.common.io.ConnectorDefinition;
@@ -37,45 +36,65 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
*/
public interface Sinks<W extends WorkerService> extends Component<W> {
- void registerSink(final String tenant,
- final String namespace,
- final String sinkName,
- final InputStream uploadedInputStream,
- final FormDataContentDisposition fileDetail,
- final String sinkPkgUrl,
- final SinkConfig sinkConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps);
+ /**
+ * Update a function.
+ * @param tenant The tenant of a Pulsar Sink
+ * @param namespace The namespace of a Pulsar Sink
+ * @param sinkName The name of a Pulsar Sink
+ * @param uploadedInputStream Input stream of bytes
+ * @param fileDetail A form-data content disposition header
+ * @param sinkPkgUrl URL path of the Pulsar Sink package
+ * @param sinkConfig Configuration of Pulsar Sink
+ * @param authParams the authentication parameters associated with the request
+ */
+ void registerSink(String tenant,
+ String namespace,
+ String sinkName,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String sinkPkgUrl,
+ SinkConfig sinkConfig,
+ AuthenticationParameters authParams);
- void updateSink(final String tenant,
- final String namespace,
- final String sinkName,
- final InputStream uploadedInputStream,
- final FormDataContentDisposition fileDetail,
- final String sinkPkgUrl,
- final SinkConfig sinkConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps,
+ /**
+ * Update a function.
+ * @param tenant The tenant of a Pulsar Sink
+ * @param namespace The namespace of a Pulsar Sink
+ * @param sinkName The name of a Pulsar Sink
+ * @param uploadedInputStream Input stream of bytes
+ * @param fileDetail A form-data content disposition header
+ * @param sinkPkgUrl URL path of the Pulsar Sink package
+ * @param sinkConfig Configuration of Pulsar Sink
+ * @param authParams the authentication parameters associated with the request
+ * @param updateOptions Options while updating the sink
+ */
+ void updateSink(String tenant,
+ String namespace,
+ String sinkName,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String sinkPkgUrl,
+ SinkConfig sinkConfig,
+ AuthenticationParameters authParams,
UpdateOptionsImpl updateOptions);
- SinkInstanceStatusData getSinkInstanceStatus(final String tenant,
- final String namespace,
- final String sinkName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
+ SinkInstanceStatusData getSinkInstanceStatus(String tenant,
+ String namespace,
+ String sinkName,
+ String instanceId,
+ URI uri,
+ AuthenticationParameters authParams);
- SinkStatus getSinkStatus(final String tenant,
- final String namespace,
- final String componentName,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
+ SinkStatus getSinkStatus(String tenant,
+ String namespace,
+ String componentName,
+ URI uri,
+ AuthenticationParameters authParams);
- SinkConfig getSinkInfo(final String tenant,
- final String namespace,
- final String componentName);
+ SinkConfig getSinkInfo(String tenant,
+ String namespace,
+ String componentName,
+ AuthenticationParameters authParams);
List<ConnectorDefinition> getSinkList();
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sources.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sources.java
index cc372490f4b..041af713031 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sources.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Sources.java
@@ -21,8 +21,7 @@ package org.apache.pulsar.functions.worker.service.api;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
-import org.apache.pulsar.broker.authentication.AuthenticationDataHttps;
-import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.common.functions.UpdateOptionsImpl;
import org.apache.pulsar.common.io.ConfigFieldDefinition;
import org.apache.pulsar.common.io.ConnectorDefinition;
@@ -37,47 +36,65 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
*/
public interface Sources<W extends WorkerService> extends Component<W> {
- void registerSource(final String tenant,
- final String namespace,
- final String sourceName,
- final InputStream uploadedInputStream,
- final FormDataContentDisposition fileDetail,
- final String sourcePkgUrl,
- final SourceConfig sourceConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps);
+ /**
+ * Update a function.
+ * @param tenant The tenant of a Pulsar Source
+ * @param namespace The namespace of a Pulsar Source
+ * @param sourceName The name of a Pulsar Source
+ * @param uploadedInputStream Input stream of bytes
+ * @param fileDetail A form-data content disposition header
+ * @param sourcePkgUrl URL path of the Pulsar Source package
+ * @param sourceConfig Configuration of Pulsar Source
+ * @param authParams the authentication parameters associated with the request
+ */
+ void registerSource(String tenant,
+ String namespace,
+ String sourceName,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String sourcePkgUrl,
+ SourceConfig sourceConfig,
+ AuthenticationParameters authParams);
- void updateSource(final String tenant,
- final String namespace,
- final String sourceName,
- final InputStream uploadedInputStream,
- final FormDataContentDisposition fileDetail,
- final String sourcePkgUrl,
- final SourceConfig sourceConfig,
- final String clientRole,
- AuthenticationDataHttps clientAuthenticationDataHttps,
+ /**
+ * Update a function.
+ * @param tenant The tenant of a Pulsar Source
+ * @param namespace The namespace of a Pulsar Source
+ * @param sourceName The name of a Pulsar Source
+ * @param uploadedInputStream Input stream of bytes
+ * @param fileDetail A form-data content disposition header
+ * @param sourcePkgUrl URL path of the Pulsar Source package
+ * @param sourceConfig Configuration of Pulsar Source
+ * @param authParams the authentication parameters associated with the request
+ * @param updateOptions Options while updating the source
+ */
+ void updateSource(String tenant,
+ String namespace,
+ String sourceName,
+ InputStream uploadedInputStream,
+ FormDataContentDisposition fileDetail,
+ String sourcePkgUrl,
+ SourceConfig sourceConfig,
+ AuthenticationParameters authParams,
UpdateOptionsImpl updateOptions);
+ SourceStatus getSourceStatus(String tenant,
+ String namespace,
+ String componentName,
+ URI uri,
+ AuthenticationParameters authParams);
- SourceStatus getSourceStatus(final String tenant,
- final String namespace,
- final String componentName,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
+ SourceInstanceStatusData getSourceInstanceStatus(String tenant,
+ String namespace,
+ String sourceName,
+ String instanceId,
+ URI uri,
+ AuthenticationParameters authParams);
-
- SourceInstanceStatusData getSourceInstanceStatus(final String tenant,
- final String namespace,
- final String sourceName,
- final String instanceId,
- final URI uri,
- final String clientRole,
- final AuthenticationDataSource clientAuthenticationDataHttps);
-
- SourceConfig getSourceInfo(final String tenant,
- final String namespace,
- final String componentName);
+ SourceConfig getSourceInfo(String tenant,
+ String namespace,
+ String componentName,
+ AuthenticationParameters authParams);
List<ConnectorDefinition> getSourceList();
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Workers.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Workers.java
index 1ce99025363..bed4404479c 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Workers.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/service/api/Workers.java
@@ -23,7 +23,7 @@ import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.LongRunningProcessStatus;
import org.apache.pulsar.common.functions.WorkerInfo;
import org.apache.pulsar.common.io.ConnectorDefinition;
@@ -36,25 +36,25 @@ import org.apache.pulsar.functions.worker.WorkerService;
*/
public interface Workers<W extends WorkerService> {
- List<WorkerInfo> getCluster(String clientRole);
+ List<WorkerInfo> getCluster(AuthenticationParameters authParams);
- WorkerInfo getClusterLeader(String clientRole);
+ WorkerInfo getClusterLeader(AuthenticationParameters authParams);
- Map<String, Collection<String>> getAssignments(String clientRole);
+ Map<String, Collection<String>> getAssignments(AuthenticationParameters authParams);
- List<Metrics> getWorkerMetrics(final String clientRole);
+ List<Metrics> getWorkerMetrics(AuthenticationParameters authParams);
- List<WorkerFunctionInstanceStats> getFunctionsMetrics(String clientRole) throws IOException;
+ List<WorkerFunctionInstanceStats> getFunctionsMetrics(AuthenticationParameters authParams) throws IOException;
- List<ConnectorDefinition> getListOfConnectors(String clientRole);
+ List<ConnectorDefinition> getListOfConnectors(AuthenticationParameters authParams);
- void rebalance(final URI uri, final String clientRole);
+ void rebalance(URI uri, AuthenticationParameters authParams);
- void drain(final URI uri, final String workerId, final String clientRole, boolean leaderUri);
+ void drain(URI uri, String workerId, AuthenticationParameters authParams, boolean leaderUri);
- LongRunningProcessStatus getDrainStatus(final URI uri, final String workerId, final String clientRole,
+ LongRunningProcessStatus getDrainStatus(URI uri, String workerId, AuthenticationParameters authParams,
boolean leaderUri);
- Boolean isLeaderReady(final String clientRole);
+ boolean isLeaderReady(AuthenticationParameters authParams);
}
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/WorkerUtilsTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/WorkerUtilsTest.java
index b2e0f0f354c..4f7a6212eb2 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/WorkerUtilsTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/WorkerUtilsTest.java
@@ -47,6 +47,9 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import org.apache.distributedlog.DistributedLogConfiguration;
+import java.util.HashSet;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.common.configuration.PulsarConfigurationLoader;
public class WorkerUtilsTest {
@@ -118,4 +121,15 @@ public class WorkerUtilsTest {
assertEquals(dlogConf.getString("bkc.testKey"), "fakeValue",
"The bookkeeper client config mapping should apply.");
}
+
+ @Test
+ public void testProxyRolesInWorkerConfigMapToServiceConfiguration() throws Exception {
+ URL yamlUrl = getClass().getClassLoader().getResource("test_worker_config.yml");
+ WorkerConfig wc = WorkerConfig.load(yamlUrl.toURI().getPath());
+ ServiceConfiguration conf = PulsarConfigurationLoader.convertFrom(wc);
+ HashSet<String> proxyRoles = new HashSet<>();
+ proxyRoles.add("proxyA");
+ proxyRoles.add("proxyB");
+ assertEquals(conf.getProxyRoles(), proxyRoles);
+ }
}
\ No newline at end of file
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplTest.java
index e2bb78484f8..de89b349345 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplTest.java
@@ -18,18 +18,47 @@
*/
package org.apache.pulsar.functions.worker.rest.api;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertThrows;
+import static org.testng.Assert.assertTrue;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
import org.apache.distributedlog.api.namespace.Namespace;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.broker.authorization.AuthorizationService;
+import org.apache.pulsar.broker.resources.NamespaceResources;
+import org.apache.pulsar.broker.resources.PulsarResources;
+import org.apache.pulsar.broker.resources.TenantResources;
import org.apache.pulsar.client.admin.Namespaces;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.admin.Tenants;
import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.common.configuration.PulsarConfigurationLoader;
import org.apache.pulsar.common.functions.FunctionConfig;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.policies.data.AuthAction;
import org.apache.pulsar.common.policies.data.FunctionInstanceStatsImpl;
import org.apache.pulsar.common.policies.data.FunctionStatsImpl;
+import org.apache.pulsar.common.policies.data.Policies;
import org.apache.pulsar.common.policies.data.TenantInfo;
+import org.apache.pulsar.common.util.RestException;
import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.instance.InstanceConfig;
import org.apache.pulsar.functions.instance.InstanceUtils;
@@ -57,27 +86,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyInt;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.powermock.api.mockito.PowerMockito.doReturn;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
@PrepareForTest({WorkerUtils.class, InstanceUtils.class})
@PowerMockIgnore({ "javax.management.*", "javax.ws.*", "org.apache.logging.log4j.*" })
@@ -110,6 +119,7 @@ public class FunctionsImplTest {
private static final int parallelism = 1;
private static final String workerId = "worker-0";
private static final String superUser = "superUser";
+ private static final String proxyUser = "proxyUser";
private PulsarWorkerService mockedWorkerService;
private PulsarAdmin mockedPulsarAdmin;
@@ -211,7 +221,7 @@ public class FunctionsImplTest {
@Test
public void testStatusEmpty() {
- assertNotNull(this.resource.getFunctionInstanceStatus(tenant, namespace, function, "0", null, null, null));
+ assertNotNull(this.resource.getFunctionInstanceStatus(tenant, namespace, function, "0", null, null));
}
@Test
@@ -245,78 +255,80 @@ public class FunctionsImplTest {
assertNotNull(functionStats.calculateOverall());
}
+ // Suppress the deprecation warnings until we actually remove the deprecated method
+ @SuppressWarnings("deprecation")
@Test
- public void testIsAuthorizedRole() throws PulsarAdminException, InterruptedException, ExecutionException {
+ public void testIsAuthorizedRole() throws Exception {
- TenantInfo tenantInfo = TenantInfo.builder().build();
AuthenticationDataSource authenticationDataSource = mock(AuthenticationDataSource.class);
FunctionsImpl functionImpl = spy(new FunctionsImpl(() -> mockedWorkerService));
- AuthorizationService authorizationService = mock(AuthorizationService.class);
- doReturn(authorizationService).when(mockedWorkerService).getAuthorizationService();
WorkerConfig workerConfig = new WorkerConfig();
workerConfig.setAuthorizationEnabled(true);
- workerConfig.setSuperUserRoles(Collections.singleton(superUser));
+ HashSet<String> superUsers = new HashSet<>();
+ superUsers.add(superUser);
+ superUsers.add(proxyUser);
+ workerConfig.setSuperUserRoles(superUsers);
+ workerConfig.setProxyRoles(Collections.singleton(proxyUser));
+ // TODO remove mocking by relying on TestPulsarResources. Can't do now because this commit needs to be
+ // cherry picked back.
+ PulsarResources pulsarResources = mock(PulsarResources.class);
+ TenantResources tenantResources = mock(TenantResources.class);
+ when(pulsarResources.getTenantResources()).thenReturn(tenantResources);
+ TenantInfo tenantInfo = TenantInfo.builder().adminRoles(Collections.singleton("tenant-admin")).build();
+ when(tenantResources.getTenantAsync("test-tenant"))
+ .thenReturn(CompletableFuture.completedFuture(Optional.of(tenantInfo)));
+ NamespaceResources namespaceResources = mock(NamespaceResources.class);
+ when(pulsarResources.getNamespaceResources()).thenReturn(namespaceResources);
+ Policies p = new Policies();
+ p.auth_policies.getNamespaceAuthentication().put("test-function-user", Collections.singleton(AuthAction.functions));
+ when(namespaceResources.getPoliciesAsync(NamespaceName.get("test-tenant/test-ns")))
+ .thenReturn(CompletableFuture.completedFuture(Optional.of(p)));
+
+ AuthorizationService authorizationService = new AuthorizationService(
+ PulsarConfigurationLoader.convertFrom(workerConfig), pulsarResources);
doReturn(workerConfig).when(mockedWorkerService).getWorkerConfig();
+ doReturn(authorizationService).when(mockedWorkerService).getAuthorizationService();
// test super user
- assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", superUser, authenticationDataSource));
-
- // test pulsar super user
- final String pulsarSuperUser = "pulsarSuperUser";
- when(authorizationService.isSuperUser(eq(pulsarSuperUser), any()))
- .thenReturn(CompletableFuture.completedFuture(true));
- assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", pulsarSuperUser, authenticationDataSource));
- assertTrue(functionImpl.isSuperUser(pulsarSuperUser, null));
+ assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", superUser,
+ authenticationDataSource));
+ assertTrue(functionImpl.isSuperUser(superUser, null));
- // test normal user
- functionImpl = spy(new FunctionsImpl(() -> mockedWorkerService));
- doReturn(false).when(functionImpl).allowFunctionOps(any(), any(), any());
- Tenants tenants = mock(Tenants.class);
- when(tenants.getTenantInfo(any())).thenReturn(tenantInfo);
- PulsarAdmin admin = mock(PulsarAdmin.class);
- when(admin.tenants()).thenReturn(tenants);
- when(this.mockedWorkerService.getBrokerAdmin()).thenReturn(admin);
- when(authorizationService.isTenantAdmin("test-tenant", "test-user", tenantInfo, authenticationDataSource)).thenReturn(CompletableFuture.completedFuture(false));
- when(authorizationService.isSuperUser(eq("test-user"), any())).thenReturn(CompletableFuture.completedFuture(false));
- assertFalse(functionImpl.isAuthorizedRole("test-tenant", "test-ns", "test-user", authenticationDataSource));
+ // test normal user with no permissions
+ assertFalse(functionImpl.isAuthorizedRole("test-tenant", "test-ns", "test-non-admin-user",
+ authenticationDataSource));
// if user is tenant admin
- functionImpl = spy(new FunctionsImpl(() -> mockedWorkerService));
- doReturn(false).when(functionImpl).allowFunctionOps(any(), any(), any());
- tenants = mock(Tenants.class);
- tenantInfo = TenantInfo.builder().adminRoles(Collections.singleton("test-user")).build();
- when(tenants.getTenantInfo(any())).thenReturn(tenantInfo);
-
- admin = mock(PulsarAdmin.class);
- when(admin.tenants()).thenReturn(tenants);
- when(this.mockedWorkerService.getBrokerAdmin()).thenReturn(admin);
- when(authorizationService.isTenantAdmin("test-tenant", "test-user", tenantInfo, authenticationDataSource)).thenReturn(CompletableFuture.completedFuture(true));
- when(authorizationService.isSuperUser("test-user", authenticationDataSource)).thenReturn(CompletableFuture.completedFuture(false));
- assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", "test-user", authenticationDataSource));
+ assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", "tenant-admin",
+ authenticationDataSource));
// test user allow function action
- functionImpl = spy(new FunctionsImpl(() -> mockedWorkerService));
- doReturn(true).when(functionImpl).allowFunctionOps(any(), any(), any());
- tenants = mock(Tenants.class);
- tenantInfo = TenantInfo.builder().build();
- when(tenants.getTenantInfo(any())).thenReturn(tenantInfo);
-
- admin = mock(PulsarAdmin.class);
- when(admin.tenants()).thenReturn(tenants);
- when(this.mockedWorkerService.getBrokerAdmin()).thenReturn(admin);
- when(authorizationService.isTenantAdmin("test-tenant", "test-user", tenantInfo, authenticationDataSource)).thenReturn(CompletableFuture.completedFuture(true));
- assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", "test-user", authenticationDataSource));
+ assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns", "test-function-user",
+ authenticationDataSource));
// test role is null
- functionImpl = spy(new FunctionsImpl(() -> mockedWorkerService));
- doReturn(true).when(functionImpl).allowFunctionOps(any(), any(), any());
- tenants = mock(Tenants.class);
- when(tenants.getTenantInfo(any())).thenReturn(TenantInfo.builder().build());
-
- admin = mock(PulsarAdmin.class);
- when(admin.tenants()).thenReturn(tenants);
- when(this.mockedWorkerService.getBrokerAdmin()).thenReturn(admin);
- assertFalse(functionImpl.isAuthorizedRole("test-tenant", "test-ns", null, authenticationDataSource));
+ assertThrows(RestException.class, () -> functionImpl.isAuthorizedRole("test-tenant",
+ "test-ns", null, authenticationDataSource));
+
+ // test proxy user with no original principal
+ assertFalse(functionImpl.isAuthorizedRole("test-tenant", "test-ns",
+ AuthenticationParameters.builder().clientRole(proxyUser).build()));
+
+ // test proxy user with tenant admin original principal
+ assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns",
+ AuthenticationParameters.builder().clientRole(proxyUser).originalPrincipal("tenant-admin").build()));
+
+ // test proxy user with non admin user
+ assertFalse(functionImpl.isAuthorizedRole("test-tenant", "test-ns",
+ AuthenticationParameters.builder().clientRole(proxyUser).originalPrincipal("test-non-admin-user").build()));
+
+ // test proxy user with allow function action
+ assertTrue(functionImpl.isAuthorizedRole("test-tenant", "test-ns",
+ AuthenticationParameters.builder().clientRole(proxyUser).originalPrincipal("test-function-user").build()));
+
+ // test non-proxy user passing original principal
+ assertFalse(functionImpl.isAuthorizedRole("test-tenant", "test-ns",
+ AuthenticationParameters.builder().clientRole("nobody").originalPrincipal("test-non-admin-user").build()));
}
@Test
@@ -329,21 +341,20 @@ public class FunctionsImplTest {
workerConfig.setAuthorizationEnabled(true);
workerConfig.setSuperUserRoles(Collections.singleton(superUser));
doReturn(workerConfig).when(mockedWorkerService).getWorkerConfig();
- when(authorizationService.isSuperUser(anyString(), any()))
+ when(authorizationService.isSuperUser(any(AuthenticationParameters.class)))
.thenAnswer((invocationOnMock) -> {
- String role = invocationOnMock.getArgument(0, String.class);
+ String role = invocationOnMock.getArgument(0, AuthenticationParameters.class).getClientRole();
return CompletableFuture.completedFuture(superUser.equals(role));
});
- AuthenticationDataSource authenticationDataSource = mock(AuthenticationDataSource.class);
assertTrue(functionImpl.isSuperUser(superUser, null));
assertFalse(functionImpl.isSuperUser("normal-user", null));
assertFalse(functionImpl.isSuperUser( null, null));
// test super roles is null and it's not a pulsar super user
- when(authorizationService.isSuperUser(superUser, null))
- .thenReturn(CompletableFuture.completedFuture(false));
+ when(authorizationService.isSuperUser(AuthenticationParameters.builder().clientRole(superUser).build()))
+ .thenReturn(CompletableFuture.completedFuture(false));
functionImpl = spy(new FunctionsImpl(() -> mockedWorkerService));
workerConfig = new WorkerConfig();
workerConfig.setAuthorizationEnabled(true);
@@ -351,10 +362,10 @@ public class FunctionsImplTest {
assertFalse(functionImpl.isSuperUser(superUser, null));
// test super role is null but the auth datasource contains superuser
- when(authorizationService.isSuperUser(anyString(), any(AuthenticationDataSource.class)))
+ when(authorizationService.isSuperUser(any(AuthenticationParameters.class)))
.thenAnswer((invocationOnMock -> {
- AuthenticationDataSource authData = invocationOnMock.getArgument(1, AuthenticationDataSource.class);
- String user = authData.getHttpHeader("mockedUser");
+ AuthenticationParameters authData = invocationOnMock.getArgument(0, AuthenticationParameters.class);
+ String user = authData.getClientAuthenticationDataSource().getHttpHeader("mockedUser");
return CompletableFuture.completedFuture(superUser.equals(user));
}));
AuthenticationDataSource authData = mock(AuthenticationDataSource.class);
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/WorkerImplTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/WorkerImplTest.java
new file mode 100644
index 00000000000..3285c5e7839
--- /dev/null
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/WorkerImplTest.java
@@ -0,0 +1,118 @@
+/**
+ * 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.functions.worker.rest.api;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import java.util.HashSet;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
+import org.apache.pulsar.broker.authorization.AuthorizationService;
+import org.apache.pulsar.broker.resources.PulsarResources;
+import org.apache.pulsar.common.configuration.PulsarConfigurationLoader;
+import org.apache.pulsar.common.util.RestException;
+import org.apache.pulsar.functions.worker.LeaderService;
+import org.apache.pulsar.functions.worker.MetricsGenerator;
+import org.apache.pulsar.functions.worker.PulsarWorkerService;
+import org.apache.pulsar.functions.worker.WorkerConfig;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Unit test of {@link WorkerImpl} to ensure that all methods properly fail if the {@link AuthenticationParameters}
+ * do not represent a superuser.
+ */
+public class WorkerImplTest {
+ WorkerImpl worker;
+
+ @DataProvider(name = "authParamsForNonSuperusers")
+ public Object[][] partitionedTopicProvider() {
+ return new Object[][] {
+ { AuthenticationParameters.builder().build() }, // all fields null should fail
+ { AuthenticationParameters.builder().clientRole("user").build() }, // Not superuser, no proxy
+ { AuthenticationParameters.builder()
+ .clientRole("proxySuperuser").build() }, // Proxy role needs original principal
+ { AuthenticationParameters.builder()
+ .clientRole("proxyNotSuperuser").build() }, // Proxy role needs original principal
+ { AuthenticationParameters.builder().clientRole("proxyNotSuperuser")
+ .originalPrincipal("superuser").build() }, // Proxy is not superuser
+ { AuthenticationParameters.builder().clientRole("proxyNotSuperuser")
+ .originalPrincipal("user").build() }, // Neither proxy nor original principal is superuser
+ { AuthenticationParameters.builder().clientRole("proxySuperuser")
+ .originalPrincipal("user").build() }, // Original principal is not superuser
+ { AuthenticationParameters.builder().clientRole("user")
+ .originalPrincipal("superuser").build() }, // User is not a proxyRole
+ };
+ }
+
+ @BeforeClass
+ void setup() throws Exception {
+ WorkerConfig config = new WorkerConfig();
+ config.setPulsarFunctionsCluster("testThrowIfNotSuperUserFailures");
+ config.setAuthorizationEnabled(true);
+ HashSet<String> proxyRoles = new HashSet<>();
+ proxyRoles.add("proxySuperuser");
+ proxyRoles.add("proxyNotSuperuser");
+ HashSet<String> superUserRoles = new HashSet<>();
+ superUserRoles.add("superuser");
+ superUserRoles.add("superuser2");
+ superUserRoles.add("proxySuperuser");
+ config.setSuperUserRoles(superUserRoles);
+ config.setProxyRoles(proxyRoles);
+ AuthorizationService authorizationService = new AuthorizationService(
+ PulsarConfigurationLoader.convertFrom(config), mock(PulsarResources.class));
+ PulsarWorkerService pulsarWorkerService = mock(PulsarWorkerService.class);
+ when(pulsarWorkerService.getWorkerConfig()).thenReturn(config);
+ when(pulsarWorkerService.getAuthorizationService()).thenReturn(authorizationService);
+ when(pulsarWorkerService.isInitialized()).thenReturn(true);
+ when(pulsarWorkerService.getMetricsGenerator()).thenReturn(mock(MetricsGenerator.class));
+ LeaderService leaderService = mock(LeaderService.class);
+ when(leaderService.isLeader()).thenReturn(true);
+ when(pulsarWorkerService.getLeaderService()).thenReturn(leaderService);
+ worker = new WorkerImpl(() -> pulsarWorkerService);
+ }
+
+ @Test(dataProvider = "authParamsForNonSuperusers")
+ public void ensureNonSuperuserCombinationsFailAuthorization(AuthenticationParameters authParams) throws Throwable {
+ assertThrowsRestException401(() -> worker.getCluster(authParams));
+ assertThrowsRestException401(() -> worker.getClusterLeader(authParams));
+ assertThrowsRestException401(() -> worker.getAssignments(authParams));
+ assertThrowsRestException401(() -> worker.getWorkerMetrics(authParams));
+ assertThrowsRestException401(() -> worker.getFunctionsMetrics(authParams));
+ assertThrowsRestException401(() -> worker.getListOfConnectors(authParams));
+ assertThrowsRestException401(() -> worker.rebalance(null, authParams));
+ assertThrowsRestException401(() -> worker.drain(null, "test", authParams, false));
+ assertThrowsRestException401(() -> worker.getDrainStatus(null, "test", authParams, false));
+ // This endpoint is not protected
+ assertTrue(worker.isLeaderReady(authParams));
+ }
+
+ private void assertThrowsRestException401(Assert.ThrowingRunnable runnable) throws Throwable {
+ try {
+ runnable.run();
+ fail("Should have thrown RestException");
+ } catch (RestException e) {
+ assertEquals(e.getResponse().getStatus(), 401);
+ }
+ }
+}
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java
index 89fb32adb59..fd5bf2ccef9 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java
@@ -58,6 +58,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.Functions;
import org.apache.pulsar.client.admin.Namespaces;
import org.apache.pulsar.client.admin.Tenants;
@@ -526,8 +527,8 @@ public class FunctionApiV2ResourceTest {
inputStream,
details,
functionPkgUrl,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)),
- null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
@@ -544,8 +545,8 @@ public class FunctionApiV2ResourceTest {
mockedInputStream,
mockedFormData,
null,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)),
- null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
@@ -944,8 +945,8 @@ public class FunctionApiV2ResourceTest {
inputStream,
details,
null,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)),
- null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
@@ -972,8 +973,8 @@ public class FunctionApiV2ResourceTest {
mockedInputStream,
mockedFormData,
null,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)),
- null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
@@ -1055,8 +1056,8 @@ public class FunctionApiV2ResourceTest {
null,
null,
filePackageUrl,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)),
- null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
@@ -1167,7 +1168,7 @@ public class FunctionApiV2ResourceTest {
tenant,
namespace,
function,
- null);
+ AuthenticationParameters.builder().build());
}
private void deregisterDefaultFunction() {
@@ -1175,7 +1176,7 @@ public class FunctionApiV2ResourceTest {
tenant,
namespace,
function,
- null);
+ AuthenticationParameters.builder().build());
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function test-function doesn't exist")
@@ -1284,7 +1285,8 @@ public class FunctionApiV2ResourceTest {
resource.getFunctionInfo(
tenant,
namespace,
- function, null
+ function,
+ AuthenticationParameters.builder().build()
);
}
@@ -1293,7 +1295,8 @@ public class FunctionApiV2ResourceTest {
String json = (String) resource.getFunctionInfo(
tenant,
namespace,
- function, null
+ function,
+ AuthenticationParameters.builder().build()
).getEntity();
FunctionDetails.Builder functionDetailsBuilder = FunctionDetails.newBuilder();
mergeJson(json, functionDetailsBuilder);
@@ -1378,7 +1381,8 @@ public class FunctionApiV2ResourceTest {
) {
resource.listFunctions(
tenant,
- namespace, null
+ namespace,
+ AuthenticationParameters.builder().build()
);
}
@@ -1386,7 +1390,8 @@ public class FunctionApiV2ResourceTest {
private List<String> listDefaultFunctions() {
return new Gson().fromJson((String) resource.listFunctions(
tenant,
- namespace, null
+ namespace,
+ AuthenticationParameters.builder().build()
).getEntity(), List.class);
}
@@ -1413,7 +1418,8 @@ public class FunctionApiV2ResourceTest {
String jarHttpUrl = "https://repo1.maven.org/maven2/org/apache/pulsar/pulsar-common/2.4.2/pulsar-common-2.4.2.jar";
String testDir = FunctionApiV2ResourceTest.class.getProtectionDomain().getCodeSource().getLocation().getPath();
FunctionsImplV2 function = new FunctionsImplV2(() -> mockedWorkerService);
- StreamingOutput streamOutput = (StreamingOutput) function.downloadFunction(jarHttpUrl, null).getEntity();
+ StreamingOutput streamOutput = (StreamingOutput) function.downloadFunction(jarHttpUrl,
+ AuthenticationParameters.builder().build()).getEntity();
File pkgFile = new File(testDir, UUID.randomUUID().toString());
OutputStream output = new FileOutputStream(pkgFile);
streamOutput.write(output);
@@ -1430,7 +1436,8 @@ public class FunctionApiV2ResourceTest {
String fileLocation = file.getAbsolutePath().replace('\\', '/');
String testDir = FunctionApiV2ResourceTest.class.getProtectionDomain().getCodeSource().getLocation().getPath();
FunctionsImplV2 function = new FunctionsImplV2(() -> mockedWorkerService);
- StreamingOutput streamOutput = (StreamingOutput) function.downloadFunction("file:///" + fileLocation, null).getEntity();
+ StreamingOutput streamOutput = (StreamingOutput) function.downloadFunction("file:///" + fileLocation,
+ AuthenticationParameters.builder().build()).getEntity();
File pkgFile = new File(testDir, UUID.randomUUID().toString());
OutputStream output = new FileOutputStream(pkgFile);
streamOutput.write(output);
@@ -1462,7 +1469,8 @@ public class FunctionApiV2ResourceTest {
functionConfig.setOutputSerdeClassName(outputSerdeClassName);
try {
resource.registerFunction(tenant, namespace, function, null, null, filePackageUrl,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)), null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
@@ -1496,7 +1504,8 @@ public class FunctionApiV2ResourceTest {
functionConfig.setOutputSerdeClassName(outputSerdeClassName);
try {
resource.registerFunction(actualTenant, actualNamespace, actualName, null, null, filePackageUrl,
- JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, null)), null);
+ JsonFormat.printer().print(FunctionConfigUtils.convert(functionConfig, (ClassLoader) null)),
+ AuthenticationParameters.builder().build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java
index 837e3211368..54dd939c998 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java
@@ -541,7 +541,7 @@ public class FunctionApiV3ResourceTest {
details,
functionPkgUrl,
functionConfig,
- null, null);
+ null);
}
@@ -555,7 +555,7 @@ public class FunctionApiV3ResourceTest {
mockedFormData,
null,
null,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function config is not provided")
@@ -570,7 +570,7 @@ public class FunctionApiV3ResourceTest {
mockedFormData,
null,
null,
- null, null, null);
+ null, null);
}
private void registerDefaultFunction() {
@@ -587,7 +587,7 @@ public class FunctionApiV3ResourceTest {
mockedFormData,
packageUrl,
functionConfig,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function test-function already exists")
@@ -1005,7 +1005,7 @@ public class FunctionApiV3ResourceTest {
details,
null,
functionConfig,
- null, null, null);
+ null, null);
}
@@ -1033,7 +1033,7 @@ public class FunctionApiV3ResourceTest {
mockedFormData,
packageUrl,
functionConfig,
- null, null, null);
+ null, null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function test-function doesn't exist")
@@ -1110,7 +1110,7 @@ public class FunctionApiV3ResourceTest {
null,
filePackageUrl,
functionConfig,
- null, null, null);
+ null, null);
}
@@ -1236,7 +1236,7 @@ public class FunctionApiV3ResourceTest {
tenant,
namespace,
function,
- null, null);
+ null);
}
private void deregisterDefaultFunction() {
@@ -1244,7 +1244,7 @@ public class FunctionApiV3ResourceTest {
tenant,
namespace,
function,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function test-function doesn't exist")
@@ -1353,7 +1353,7 @@ public class FunctionApiV3ResourceTest {
resource.getFunctionInfo(
tenant,
namespace,
- function,null,null
+ function,null
);
}
@@ -1363,7 +1363,6 @@ public class FunctionApiV3ResourceTest {
tenant,
namespace,
function,
- null,
null
);
}
@@ -1446,7 +1445,7 @@ public class FunctionApiV3ResourceTest {
) {
resource.listFunctions(
tenant,
- namespace,null,null
+ namespace,null
);
}
@@ -1454,7 +1453,7 @@ public class FunctionApiV3ResourceTest {
private List<String> listDefaultFunctions() {
return resource.listFunctions(
tenant,
- namespace,null,null
+ namespace,null
);
}
@@ -1510,7 +1509,7 @@ public class FunctionApiV3ResourceTest {
when(config.isAuthorizationEnabled()).thenReturn(false);
when(worker.getWorkerConfig()).thenReturn(config);
FunctionsImpl function = new FunctionsImpl(()-> worker);
- StreamingOutput streamOutput = function.downloadFunction(jarHttpUrl, null, null);
+ StreamingOutput streamOutput = function.downloadFunction(jarHttpUrl, null);
File pkgFile = new File(testDir, UUID.randomUUID().toString());
OutputStream output = new FileOutputStream(pkgFile);
streamOutput.write(output);
@@ -1532,7 +1531,7 @@ public class FunctionApiV3ResourceTest {
when(config.isAuthorizationEnabled()).thenReturn(false);
when(worker.getWorkerConfig()).thenReturn(config);
FunctionsImpl function = new FunctionsImpl(() -> worker);
- StreamingOutput streamOutput = function.downloadFunction("file:///" + fileLocation, null, null);
+ StreamingOutput streamOutput = function.downloadFunction("file:///" + fileLocation, null);
File pkgFile = new File(testDir, UUID.randomUUID().toString());
OutputStream output = new FileOutputStream(pkgFile);
streamOutput.write(output);
@@ -1562,7 +1561,7 @@ public class FunctionApiV3ResourceTest {
functionConfig.setCustomSerdeInputs(topicsToSerDeClassName);
functionConfig.setOutput(outputTopic);
functionConfig.setOutputSerdeClassName(outputSerdeClassName);
- resource.registerFunction(tenant, namespace, function, null, null, filePackageUrl, functionConfig, null, null);
+ resource.registerFunction(tenant, namespace, function, null, null, filePackageUrl, functionConfig, null);
}
@@ -1591,7 +1590,8 @@ public class FunctionApiV3ResourceTest {
functionConfig.setCustomSerdeInputs(topicsToSerDeClassName);
functionConfig.setOutput(outputTopic);
functionConfig.setOutputSerdeClassName(outputSerdeClassName);
- resource.registerFunction(actualTenant, actualNamespace, actualName, null, null, filePackageUrl, functionConfig, null, null);
+ resource.registerFunction(actualTenant, actualNamespace, actualName, null, null, filePackageUrl, functionConfig,
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function language runtime is either not set or cannot be determined")
@@ -1613,7 +1613,7 @@ public class FunctionApiV3ResourceTest {
functionConfig.setCustomSerdeInputs(topicsToSerDeClassName);
functionConfig.setOutput(outputTopic);
functionConfig.setOutputSerdeClassName(outputSerdeClassName);
- resource.registerFunction(tenant, namespace, function, null, null, filePackageUrl, functionConfig, null, null);
+ resource.registerFunction(tenant, namespace, function, null, null, filePackageUrl, functionConfig, null);
}
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java
index 40ac38ecb16..46af6fa07fe 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java
@@ -52,6 +52,7 @@ import javax.ws.rs.core.Response;
import org.apache.distributedlog.api.namespace.Namespace;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.Functions;
import org.apache.pulsar.client.admin.Namespaces;
import org.apache.pulsar.client.admin.Packages;
@@ -505,7 +506,7 @@ public class SinkApiV3ResourceTest {
details,
pkgUrl,
sinkConfig,
- null, null);
+ null);
}
@@ -519,7 +520,7 @@ public class SinkApiV3ResourceTest {
mockedFormData,
null,
null,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Sink config is not provided")
@@ -533,7 +534,7 @@ public class SinkApiV3ResourceTest {
mockedFormData,
null,
null,
- null, null, null);
+ null, null);
}
private void registerDefaultSink() throws IOException {
@@ -551,7 +552,7 @@ public class SinkApiV3ResourceTest {
mockedFormData,
packageUrl,
sinkConfig,
- null, null);
+ null);
}
}
@@ -641,7 +642,7 @@ public class SinkApiV3ResourceTest {
mockedFormData,
null,
sinkConfig,
- null, null);
+ null);
}
}
@@ -938,7 +939,7 @@ public class SinkApiV3ResourceTest {
details,
null,
sinkConfig,
- null, null, null);
+ null, null);
}
@@ -989,7 +990,7 @@ public class SinkApiV3ResourceTest {
mockedFormData,
packageUrl,
sinkConfig,
- null, null, null);
+ null, null);
}
}
@@ -1086,7 +1087,7 @@ public class SinkApiV3ResourceTest {
null,
filePackageUrl,
sinkConfig,
- null, null, null);
+ null, null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "sink failed to register")
@@ -1210,7 +1211,7 @@ public class SinkApiV3ResourceTest {
tenant,
namespace,
sink,
- null, null);
+ null);
}
@@ -1219,7 +1220,7 @@ public class SinkApiV3ResourceTest {
tenant,
namespace,
sink,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Sink test-sink doesn't exist")
@@ -1406,7 +1407,8 @@ public class SinkApiV3ResourceTest {
resource.getFunctionInfo(
tenant,
namespace,
- sink, null, null
+ sink,
+ AuthenticationParameters.builder().build()
);
}
@@ -1415,7 +1417,8 @@ public class SinkApiV3ResourceTest {
return resource.getSinkInfo(
tenant,
namespace,
- sink
+ sink,
+ AuthenticationParameters.builder().build()
);
}
@@ -1508,7 +1511,8 @@ public class SinkApiV3ResourceTest {
) {
resource.listFunctions(
tenant,
- namespace, null, null
+ namespace,
+ AuthenticationParameters.builder().build()
);
}
@@ -1516,7 +1520,8 @@ public class SinkApiV3ResourceTest {
private List<String> listDefaultSinks() {
return resource.listFunctions(
tenant,
- namespace, null, null
+ namespace,
+ AuthenticationParameters.builder().build()
);
}
diff --git a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java
index b030ed8036b..42ef88a5ff3 100644
--- a/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java
+++ b/pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java
@@ -50,6 +50,7 @@ import javax.ws.rs.core.Response;
import org.apache.distributedlog.api.namespace.Namespace;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.pulsar.broker.authentication.AuthenticationParameters;
import org.apache.pulsar.client.admin.Functions;
import org.apache.pulsar.client.admin.Namespaces;
import org.apache.pulsar.client.admin.Packages;
@@ -476,7 +477,7 @@ public class SourceApiV3ResourceTest {
details,
pkgUrl,
sourceConfig,
- null, null);
+ null);
}
@@ -490,7 +491,7 @@ public class SourceApiV3ResourceTest {
mockedFormData,
null,
null,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Source config is not provided")
@@ -504,7 +505,7 @@ public class SourceApiV3ResourceTest {
mockedFormData,
null,
null,
- null, null, null);
+ null, null);
}
private void registerDefaultSource() throws IOException {
@@ -521,7 +522,7 @@ public class SourceApiV3ResourceTest {
null,
packageUrl,
sourceConfig,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Source test-source already "
@@ -629,7 +630,7 @@ public class SourceApiV3ResourceTest {
mockedFormData,
null,
sourceConfig,
- null, null);
+ null);
}
}
@@ -964,7 +965,7 @@ public class SourceApiV3ResourceTest {
details,
null,
sourceConfig,
- null, null, null);
+ null, null);
}
@@ -1012,7 +1013,7 @@ public class SourceApiV3ResourceTest {
mockedFormData,
packageUrl,
sourceConfig,
- null, null, null);
+ null, null);
}
}
@@ -1108,7 +1109,7 @@ public class SourceApiV3ResourceTest {
null,
filePackageUrl,
sourceConfig,
- null, null, null);
+ null, null);
}
@@ -1235,7 +1236,7 @@ public class SourceApiV3ResourceTest {
tenant,
namespace,
function,
- null, null);
+ null);
}
@@ -1244,7 +1245,7 @@ public class SourceApiV3ResourceTest {
tenant,
namespace,
source,
- null, null);
+ null);
}
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Source test-source doesn't " +
@@ -1436,7 +1437,8 @@ public class SourceApiV3ResourceTest {
resource.getFunctionInfo(
tenant,
namespace,
- source, null, null
+ source,
+ AuthenticationParameters.builder().build()
);
}
@@ -1444,7 +1446,8 @@ public class SourceApiV3ResourceTest {
return resource.getSourceInfo(
tenant,
namespace,
- source
+ source,
+ AuthenticationParameters.builder().build()
);
}
@@ -1527,14 +1530,17 @@ public class SourceApiV3ResourceTest {
) {
resource.listFunctions(
tenant,
- namespace, null, null
+ namespace,
+ AuthenticationParameters.builder().build()
);
}
private List<String> listDefaultSources() {
return resource.listFunctions(
tenant,
- namespace, null, null);
+ namespace,
+ AuthenticationParameters.builder().build()
+ );
}
@Test