Search in sources :

Example 6 with KsqlTopicAuthorizationException

use of io.confluent.ksql.exception.KsqlTopicAuthorizationException in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException.

@Test
public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException() {
    // Given:
    when(mockStatementParser.<Query>parseSingleStatement(PUSH_QUERY_STRING)).thenReturn(query);
    doThrow(new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(TOPIC_NAME))).when(authorizationValidator).checkAuthorization(any(), any(), any());
    // When:
    final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
    final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
    final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) AUTHORIZATION_ERROR_RESPONSE.getEntity();
    assertEquals(response.getStatus(), AUTHORIZATION_ERROR_RESPONSE.getStatus());
    assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}
Also used : KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Query(io.confluent.ksql.parser.tree.Query) MetricsCallbackHolder(io.confluent.ksql.api.server.MetricsCallbackHolder) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 7 with KsqlTopicAuthorizationException

use of io.confluent.ksql.exception.KsqlTopicAuthorizationException in project ksql by confluentinc.

the class KafkaTopicClientImpl method createTopic.

@Override
public void createTopic(final String topic, final int numPartitions, final short replicationFactor, final Map<String, ?> configs, final CreateTopicsOptions createOptions) {
    if (isTopicExists(topic)) {
        validateTopicProperties(topic, numPartitions, replicationFactor);
        return;
    }
    final short resolvedReplicationFactor = replicationFactor == TopicProperties.DEFAULT_REPLICAS ? getDefaultClusterReplication() : replicationFactor;
    final NewTopic newTopic = new NewTopic(topic, numPartitions, resolvedReplicationFactor);
    newTopic.configs(toStringConfigs(configs));
    try {
        LOG.info("Creating topic '{}' {}", topic, (createOptions.shouldValidateOnly()) ? "(ONLY VALIDATE)" : "");
        ExecutorUtil.executeWithRetries(() -> adminClient.get().createTopics(Collections.singleton(newTopic), createOptions).all().get(), ExecutorUtil.RetryBehaviour.ON_RETRYABLE);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new KafkaResponseGetFailedException("Failed to guarantee existence of topic " + topic, e);
    } catch (final TopicExistsException e) {
        // if the topic already exists, it is most likely because another node just created it.
        // ensure that it matches the partition count and replication factor before returning
        // success
        validateTopicProperties(topic, numPartitions, replicationFactor);
    } catch (final TopicAuthorizationException e) {
        throw new KsqlTopicAuthorizationException(AclOperation.CREATE, Collections.singleton(topic));
    } catch (final Exception e) {
        throw new KafkaResponseGetFailedException("Failed to guarantee existence of topic " + topic, e);
    }
}
Also used : KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) NewTopic(org.apache.kafka.clients.admin.NewTopic) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) KafkaDeleteTopicsException(io.confluent.ksql.exception.KafkaDeleteTopicsException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) ExecutionException(java.util.concurrent.ExecutionException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) TopicDeletionDisabledException(org.apache.kafka.common.errors.TopicDeletionDisabledException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) KsqlException(io.confluent.ksql.util.KsqlException) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException)

Aggregations

KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)7 Test (org.junit.Test)4 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)3 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)3 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)3 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)3 KsqlException (io.confluent.ksql.util.KsqlException)3 ExecutionException (java.util.concurrent.ExecutionException)3 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)3 KafkaDeleteTopicsException (io.confluent.ksql.exception.KafkaDeleteTopicsException)2 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 Query (io.confluent.ksql.parser.tree.Query)2 KsqlServerException (io.confluent.ksql.util.KsqlServerException)2 TopicDeletionDisabledException (org.apache.kafka.common.errors.TopicDeletionDisabledException)2 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)2 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)2 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)2 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 KsqlSchemaAuthorizationException (io.confluent.ksql.exception.KsqlSchemaAuthorizationException)1 MetaStore (io.confluent.ksql.metastore.MetaStore)1