Search in sources :

Example 1 with AuthPolicies

use of org.apache.pulsar.common.policies.data.AuthPolicies in project incubator-pulsar by apache.

the class PersistentTopicsBase method internalGetPermissionsOnTopic.

protected Map<String, Set<AuthAction>> internalGetPermissionsOnTopic() {
    // This operation should be reading from zookeeper and it should be allowed without having admin privileges
    validateAdminAccessOnProperty(namespaceName.getProperty());
    String topicUri = topicName.toString();
    try {
        Policies policies = policiesCache().get(path(POLICIES, namespaceName.toString())).orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace does not exist"));
        Map<String, Set<AuthAction>> permissions = Maps.newTreeMap();
        AuthPolicies auth = policies.auth_policies;
        // First add namespace level permissions
        for (String role : auth.namespace_auth.keySet()) {
            permissions.put(role, auth.namespace_auth.get(role));
        }
        // Then add topic level permissions
        if (auth.destination_auth.containsKey(topicUri)) {
            for (Map.Entry<String, Set<AuthAction>> entry : auth.destination_auth.get(topicUri).entrySet()) {
                String role = entry.getKey();
                Set<AuthAction> topicPermissions = entry.getValue();
                if (!permissions.containsKey(role)) {
                    permissions.put(role, topicPermissions);
                } else {
                    // Do the union between namespace and topic level
                    Set<AuthAction> union = Sets.union(permissions.get(role), topicPermissions);
                    permissions.put(role, union);
                }
            }
        }
        return permissions;
    } catch (Exception e) {
        log.error("[{}] Failed to get permissions for topic {}", clientAppId(), topicUri, e);
        throw new RestException(e);
    }
}
Also used : AuthPolicies(org.apache.pulsar.common.policies.data.AuthPolicies) AuthPolicies(org.apache.pulsar.common.policies.data.AuthPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) RestException(org.apache.pulsar.broker.web.RestException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) RestException(org.apache.pulsar.broker.web.RestException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) AuthAction(org.apache.pulsar.common.policies.data.AuthAction)

Aggregations

IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)1 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicBusyException (org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)1 RestException (org.apache.pulsar.broker.web.RestException)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)1 PreconditionFailedException (org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)1 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)1 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)1 AuthPolicies (org.apache.pulsar.common.policies.data.AuthPolicies)1 Policies (org.apache.pulsar.common.policies.data.Policies)1 KeeperException (org.apache.zookeeper.KeeperException)1