Package org.apache.pulsar.broker.web
Class PulsarWebResource
- java.lang.Object
-
- org.apache.pulsar.broker.web.PulsarWebResource
-
- Direct Known Subclasses:
AdminResource,BrokersBase,ClustersBase,TenantsBase,TopicLookupBase
public abstract class PulsarWebResource extends java.lang.ObjectBase class for Web resources in Pulsar. It provides basic authorization functions.
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.servlet.http.HttpServletRequesthttpRequestprotected static intNOT_IMPLEMENTEDprotected javax.servlet.ServletContextservletContextprotected javax.ws.rs.core.UriInfouri
-
Constructor Summary
Constructors Constructor Description PulsarWebResource()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.pulsar.broker.resources.BookieResourcesbookieResources()protected java.util.concurrent.CompletableFuture<java.lang.Void>canUpdateCluster(java.lang.String tenant, java.util.Set<java.lang.String> oldClusters, java.util.Set<java.lang.String> newClusters)protected static java.util.concurrent.CompletableFuture<java.lang.Void>checkAuthorizationAsync(PulsarService pulsarService, org.apache.pulsar.common.naming.TopicName topicName, java.lang.String role, org.apache.pulsar.broker.authentication.AuthenticationDataSource authenticationData)static java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ClusterDataImpl>checkLocalOrGetPeerReplicationCluster(PulsarService pulsarService, org.apache.pulsar.common.naming.NamespaceName namespace)static java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ClusterDataImpl>checkLocalOrGetPeerReplicationCluster(PulsarService pulsarService, org.apache.pulsar.common.naming.NamespaceName namespace, boolean allowDeletedNamespace)java.lang.StringclientAppId()Gets a caller id (IP + role).org.apache.pulsar.broker.authentication.AuthenticationDataHttpsclientAuthData()protected org.apache.pulsar.broker.resources.ClusterResourcesclusterResources()protected org.apache.pulsar.broker.ServiceConfigurationconfig()protected org.apache.pulsar.broker.resources.DynamicConfigurationResourcesdynamicConfigurationResources()protected static java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ClusterData>getClusterDataIfDifferentCluster(PulsarService pulsar, java.lang.String cluster, java.lang.String clientAppId)protected org.apache.pulsar.broker.resources.LocalPoliciesResourcesgetLocalPolicies()protected org.apache.pulsar.broker.resources.PulsarResourcesgetPulsarResources()protected java.lang.VoidhandleCommonRestAsyncException(javax.ws.rs.container.AsyncResponse asyncResponse, java.lang.Throwable ex)protected java.util.concurrent.CompletableFuture<java.lang.Void>hasActiveNamespace(java.lang.String tenant)protected booleanhasSuperUserAccess()protected java.util.concurrent.CompletableFuture<java.lang.Boolean>isBundleOwnedByAnyBroker(org.apache.pulsar.common.naming.NamespaceName fqnn, org.apache.pulsar.common.policies.data.BundlesData bundles, java.lang.String bundleRange)Checks whether a given bundle is currently loaded by any broker.static booleanisClientAuthenticated(java.lang.String appId)protected booleanisLeaderBroker()protected static booleanisLeaderBroker(PulsarService pulsar)booleanisRequestHttps()static com.fasterxml.jackson.databind.ObjectMapperjsonMapper()protected org.apache.pulsar.broker.resources.NamespaceResources.IsolationPolicyResourcesnamespaceIsolationPolicies()protected org.apache.pulsar.broker.resources.NamespaceResourcesnamespaceResources()java.lang.StringoriginalPrincipal()protected PulsarServicepulsar()protected org.apache.pulsar.broker.resources.ResourceGroupResourcesresourceGroupResources()voidsetPulsar(PulsarService pulsar)static java.lang.StringsplitPath(java.lang.String source, int slice)protected org.apache.pulsar.broker.resources.TenantResourcestenantResources()protected org.apache.pulsar.broker.resources.TopicResourcestopicResources()protected voidvalidateAdminAccessForTenant(java.lang.String tenant)Checks that the http client role has admin access to the specified tenant.protected static voidvalidateAdminAccessForTenant(PulsarService pulsar, java.lang.String clientAppId, java.lang.String originalPrincipal, java.lang.String tenant, org.apache.pulsar.broker.authentication.AuthenticationDataSource authenticationData)protected static java.util.concurrent.CompletableFuture<java.lang.Void>validateAdminAccessForTenantAsync(PulsarService pulsar, java.lang.String clientAppId, java.lang.String originalPrincipal, java.lang.String tenant, org.apache.pulsar.broker.authentication.AuthenticationDataSource authenticationData)protected voidvalidateBrokerName(java.lang.String broker)Redirect the call to the specified broker.protected voidvalidateBundleOwnership(java.lang.String tenant, java.lang.String cluster, java.lang.String namespace, boolean authoritative, boolean readOnly, NamespaceBundle bundle)voidvalidateBundleOwnership(NamespaceBundle bundle, boolean authoritative, boolean readOnly)protected voidvalidateClusterExists(java.lang.String cluster)protected voidvalidateClusterForTenant(java.lang.String tenant, java.lang.String cluster)protected voidvalidateClusterOwnership(java.lang.String cluster)Check if the cluster exists and redirect the call to the owning cluster.protected voidvalidateGlobalNamespaceOwnership(org.apache.pulsar.common.naming.NamespaceName namespace)If the namespace is global, validate the following - 1.protected java.util.concurrent.CompletableFuture<java.lang.Void>validateGlobalNamespaceOwnershipAsync(org.apache.pulsar.common.naming.NamespaceName namespace)protected NamespaceBundlevalidateNamespaceBundleOwnership(org.apache.pulsar.common.naming.NamespaceName fqnn, org.apache.pulsar.common.policies.data.BundlesData bundles, java.lang.String bundleRange, boolean authoritative, boolean readOnly)protected NamespaceBundlevalidateNamespaceBundleRange(org.apache.pulsar.common.naming.NamespaceName fqnn, org.apache.pulsar.common.policies.data.BundlesData bundles, java.lang.String bundleRange)voidvalidateNamespaceOperation(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.NamespaceOperation operation)java.util.concurrent.CompletableFuture<java.lang.Void>validateNamespaceOperationAsync(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.NamespaceOperation operation)voidvalidateNamespacePolicyOperation(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.PolicyName policy, org.apache.pulsar.common.policies.data.PolicyOperation operation)voidvalidatePoliciesReadOnlyAccess()voidvalidateSuperUserAccess()Checks whether the user has Pulsar Super-User access to the system.voidvalidateTenantOperation(java.lang.String tenant, org.apache.pulsar.common.policies.data.TenantOperation operation)voidvalidateTopicOperation(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation)voidvalidateTopicOperation(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation, java.lang.String subscription)java.util.concurrent.CompletableFuture<java.lang.Void>validateTopicOperationAsync(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation)java.util.concurrent.CompletableFuture<java.lang.Void>validateTopicOperationAsync(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation, java.lang.String subscription)protected voidvalidateTopicOwnership(org.apache.pulsar.common.naming.TopicName topicName, boolean authoritative)Checks whether the broker is the owner of the namespace.protected java.util.concurrent.CompletableFuture<java.lang.Void>validateTopicOwnershipAsync(org.apache.pulsar.common.naming.TopicName topicName, boolean authoritative)voidvalidateTopicPolicyOperation(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.PolicyName policy, org.apache.pulsar.common.policies.data.PolicyOperation operation)
-
-
-
Field Detail
-
servletContext
@Context protected javax.servlet.ServletContext servletContext
-
httpRequest
@Context protected javax.servlet.http.HttpServletRequest httpRequest
-
uri
@Context protected javax.ws.rs.core.UriInfo uri
-
NOT_IMPLEMENTED
protected static final int NOT_IMPLEMENTED
- See Also:
- Constant Field Values
-
-
Method Detail
-
pulsar
protected PulsarService pulsar()
-
config
protected org.apache.pulsar.broker.ServiceConfiguration config()
-
splitPath
public static java.lang.String splitPath(java.lang.String source, int slice)
-
clientAppId
public java.lang.String clientAppId()
Gets a caller id (IP + role).- Returns:
- the web service caller identification
-
originalPrincipal
public java.lang.String originalPrincipal()
-
clientAuthData
public org.apache.pulsar.broker.authentication.AuthenticationDataHttps clientAuthData()
-
isRequestHttps
public boolean isRequestHttps()
-
isClientAuthenticated
public static boolean isClientAuthenticated(java.lang.String appId)
-
hasSuperUserAccess
protected boolean hasSuperUserAccess()
-
validateSuperUserAccess
public void validateSuperUserAccess()
Checks whether the user has Pulsar Super-User access to the system.- Throws:
javax.ws.rs.WebApplicationException- if not authorized
-
validateAdminAccessForTenant
protected void validateAdminAccessForTenant(java.lang.String tenant)
Checks that the http client role has admin access to the specified tenant.- Parameters:
tenant- the tenant id- Throws:
javax.ws.rs.WebApplicationException- if not authorized
-
validateAdminAccessForTenantAsync
protected static java.util.concurrent.CompletableFuture<java.lang.Void> validateAdminAccessForTenantAsync(PulsarService pulsar, java.lang.String clientAppId, java.lang.String originalPrincipal, java.lang.String tenant, org.apache.pulsar.broker.authentication.AuthenticationDataSource authenticationData)
-
validateAdminAccessForTenant
protected static void validateAdminAccessForTenant(PulsarService pulsar, java.lang.String clientAppId, java.lang.String originalPrincipal, java.lang.String tenant, org.apache.pulsar.broker.authentication.AuthenticationDataSource authenticationData) throws java.lang.Exception
- Throws:
java.lang.Exception
-
validateClusterForTenant
protected void validateClusterForTenant(java.lang.String tenant, java.lang.String cluster)
-
validateClusterOwnership
protected void validateClusterOwnership(java.lang.String cluster) throws javax.ws.rs.WebApplicationExceptionCheck if the cluster exists and redirect the call to the owning cluster.- Parameters:
cluster- Cluster name- Throws:
java.lang.Exception- In case the redirect happensjavax.ws.rs.WebApplicationException
-
getClusterDataIfDifferentCluster
protected static java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ClusterData> getClusterDataIfDifferentCluster(PulsarService pulsar, java.lang.String cluster, java.lang.String clientAppId)
-
validateBundleOwnership
protected void validateBundleOwnership(java.lang.String tenant, java.lang.String cluster, java.lang.String namespace, boolean authoritative, boolean readOnly, NamespaceBundle bundle)
-
validateNamespaceBundleRange
protected NamespaceBundle validateNamespaceBundleRange(org.apache.pulsar.common.naming.NamespaceName fqnn, org.apache.pulsar.common.policies.data.BundlesData bundles, java.lang.String bundleRange)
-
isBundleOwnedByAnyBroker
protected java.util.concurrent.CompletableFuture<java.lang.Boolean> isBundleOwnedByAnyBroker(org.apache.pulsar.common.naming.NamespaceName fqnn, org.apache.pulsar.common.policies.data.BundlesData bundles, java.lang.String bundleRange)Checks whether a given bundle is currently loaded by any broker.
-
validateNamespaceBundleOwnership
protected NamespaceBundle validateNamespaceBundleOwnership(org.apache.pulsar.common.naming.NamespaceName fqnn, org.apache.pulsar.common.policies.data.BundlesData bundles, java.lang.String bundleRange, boolean authoritative, boolean readOnly)
-
validateBundleOwnership
public void validateBundleOwnership(NamespaceBundle bundle, boolean authoritative, boolean readOnly) throws java.lang.Exception
- Throws:
java.lang.Exception
-
validateTopicOwnership
protected void validateTopicOwnership(org.apache.pulsar.common.naming.TopicName topicName, boolean authoritative)Checks whether the broker is the owner of the namespace. Otherwise it will raise an exception to redirect the client to the appropriate broker. If no broker owns the namespace yet, this function will try to acquire the ownership by default.- Parameters:
topicName- topic nameauthoritative-
-
validateTopicOwnershipAsync
protected java.util.concurrent.CompletableFuture<java.lang.Void> validateTopicOwnershipAsync(org.apache.pulsar.common.naming.TopicName topicName, boolean authoritative)
-
validateGlobalNamespaceOwnership
protected void validateGlobalNamespaceOwnership(org.apache.pulsar.common.naming.NamespaceName namespace)
If the namespace is global, validate the following - 1. If replicated clusters are configured for this global namespace 2. If local cluster belonging to this namespace is replicated 3. If replication is enabled for this namespace
It validates if local cluster is part of replication-cluster. If local cluster is not part of the replication cluster then it redirects request to peer-cluster if any of the peer-cluster is part of replication-cluster of this namespace. If none of the cluster is part of the replication cluster then it fails the validation.- Parameters:
namespace-- Throws:
java.lang.Exception
-
validateGlobalNamespaceOwnershipAsync
protected java.util.concurrent.CompletableFuture<java.lang.Void> validateGlobalNamespaceOwnershipAsync(org.apache.pulsar.common.naming.NamespaceName namespace)
-
checkLocalOrGetPeerReplicationCluster
public static java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ClusterDataImpl> checkLocalOrGetPeerReplicationCluster(PulsarService pulsarService, org.apache.pulsar.common.naming.NamespaceName namespace)
-
checkLocalOrGetPeerReplicationCluster
public static java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ClusterDataImpl> checkLocalOrGetPeerReplicationCluster(PulsarService pulsarService, org.apache.pulsar.common.naming.NamespaceName namespace, boolean allowDeletedNamespace)
-
checkAuthorizationAsync
protected static java.util.concurrent.CompletableFuture<java.lang.Void> checkAuthorizationAsync(PulsarService pulsarService, org.apache.pulsar.common.naming.TopicName topicName, java.lang.String role, org.apache.pulsar.broker.authentication.AuthenticationDataSource authenticationData)
-
setPulsar
public void setPulsar(PulsarService pulsar)
-
isLeaderBroker
protected boolean isLeaderBroker()
-
isLeaderBroker
protected static boolean isLeaderBroker(PulsarService pulsar)
-
validateTenantOperation
public void validateTenantOperation(java.lang.String tenant, org.apache.pulsar.common.policies.data.TenantOperation operation)
-
validateNamespaceOperation
public void validateNamespaceOperation(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.NamespaceOperation operation)
-
validateNamespaceOperationAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> validateNamespaceOperationAsync(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.NamespaceOperation operation)
-
validateNamespacePolicyOperation
public void validateNamespacePolicyOperation(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.PolicyName policy, org.apache.pulsar.common.policies.data.PolicyOperation operation)
-
getPulsarResources
protected org.apache.pulsar.broker.resources.PulsarResources getPulsarResources()
-
tenantResources
protected org.apache.pulsar.broker.resources.TenantResources tenantResources()
-
clusterResources
protected org.apache.pulsar.broker.resources.ClusterResources clusterResources()
-
bookieResources
protected org.apache.pulsar.broker.resources.BookieResources bookieResources()
-
topicResources
protected org.apache.pulsar.broker.resources.TopicResources topicResources()
-
namespaceResources
protected org.apache.pulsar.broker.resources.NamespaceResources namespaceResources()
-
resourceGroupResources
protected org.apache.pulsar.broker.resources.ResourceGroupResources resourceGroupResources()
-
getLocalPolicies
protected org.apache.pulsar.broker.resources.LocalPoliciesResources getLocalPolicies()
-
namespaceIsolationPolicies
protected org.apache.pulsar.broker.resources.NamespaceResources.IsolationPolicyResources namespaceIsolationPolicies()
-
dynamicConfigurationResources
protected org.apache.pulsar.broker.resources.DynamicConfigurationResources dynamicConfigurationResources()
-
jsonMapper
public static com.fasterxml.jackson.databind.ObjectMapper jsonMapper()
-
validatePoliciesReadOnlyAccess
public void validatePoliciesReadOnlyAccess()
-
hasActiveNamespace
protected java.util.concurrent.CompletableFuture<java.lang.Void> hasActiveNamespace(java.lang.String tenant)
-
validateClusterExists
protected void validateClusterExists(java.lang.String cluster)
-
canUpdateCluster
protected java.util.concurrent.CompletableFuture<java.lang.Void> canUpdateCluster(java.lang.String tenant, java.util.Set<java.lang.String> oldClusters, java.util.Set<java.lang.String> newClusters)
-
validateBrokerName
protected void validateBrokerName(java.lang.String broker)
Redirect the call to the specified broker.- Parameters:
broker- Broker name
-
validateTopicPolicyOperation
public void validateTopicPolicyOperation(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.PolicyName policy, org.apache.pulsar.common.policies.data.PolicyOperation operation)
-
validateTopicOperation
public void validateTopicOperation(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation)
-
validateTopicOperation
public void validateTopicOperation(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation, java.lang.String subscription)
-
validateTopicOperationAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> validateTopicOperationAsync(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation)
-
validateTopicOperationAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> validateTopicOperationAsync(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.TopicOperation operation, java.lang.String subscription)
-
handleCommonRestAsyncException
protected java.lang.Void handleCommonRestAsyncException(javax.ws.rs.container.AsyncResponse asyncResponse, java.lang.Throwable ex)
-
-