Search in sources :

Example 1 with BasicCredentials

use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.

the class BasicAuthFunctionalTest method shouldNotBeAbleToUseCliWithInvalidPassword.

@Test
public void shouldNotBeAbleToUseCliWithInvalidPassword() {
    // Given:
    final BasicCredentials wrongPassword = BasicCredentials.of(USER_NO_ACCESS.username(), "wrong");
    // Then:
    assertThat(canMakeCliRequest(wrongPassword), is(ERROR_CODE_UNAUTHORIZED));
}
Also used : BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 2 with BasicCredentials

use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.

the class HighAvailabilityTestUtil method waitForStreamsMetadataToInitialize.

static void waitForStreamsMetadataToInitialize(final TestKsqlRestApp restApp, List<KsqlHostInfoEntity> hosts, final Optional<BasicCredentials> credentials) {
    while (true) {
        ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(restApp, credentials);
        List<KsqlHostInfoEntity> initialized = hosts.stream().filter(hostInfo -> Optional.ofNullable(clusterStatusResponse.getClusterStatus().get(hostInfo)).map(hostStatusEntity -> hostStatusEntity.getActiveStandbyPerQuery().isEmpty()).isPresent()).collect(Collectors.toList());
        if (initialized.size() == hosts.size())
            break;
    }
    try {
        Thread.sleep(200);
    } catch (final Exception e) {
    // Meh
    }
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) RestResponse(io.confluent.ksql.rest.client.RestResponse) HeartbeatResponse(io.confluent.ksql.rest.entity.HeartbeatResponse) Function(java.util.function.Function) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Pair(io.confluent.ksql.util.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with BasicCredentials

use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.

the class RestIntegrationTestUtil method rawRestRequest.

static VertxCompletableFuture<Void> rawRestRequest(final TestKsqlRestApp restApp, final HttpVersion httpVersion, final HttpMethod method, final String uri, final Object requestBody, final String mediaType, final Consumer<Buffer> chunkConsumer, final Optional<BasicCredentials> credentials) {
    final byte[] bytes;
    try {
        bytes = ApiJsonMapper.INSTANCE.get().writeValueAsBytes(requestBody);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    HttpClientOptions options = new HttpClientOptions().setDefaultPort(restApp.getHttpListener().getPort()).setDefaultHost(restApp.getHttpListener().getHost()).setVerifyHost(false);
    if (httpVersion == HttpVersion.HTTP_2) {
        options.setProtocolVersion(HttpVersion.HTTP_2);
    }
    final Vertx vertx = Vertx.vertx();
    final HttpClient httpClient = vertx.createHttpClient(options);
    final VertxCompletableFuture<Void> vcf = new VertxCompletableFuture<>();
    final HttpClientRequest httpClientRequest = httpClient.request(method, uri, resp -> {
        resp.handler(buffer -> {
            try {
                chunkConsumer.accept(buffer);
            } catch (final Throwable t) {
                vcf.completeExceptionally(t);
            }
        });
        resp.endHandler(v -> {
            chunkConsumer.accept(null);
            vcf.complete(null);
        });
    }).exceptionHandler(vcf::completeExceptionally);
    httpClientRequest.putHeader("Accept", mediaType);
    credentials.ifPresent(basicCredentials -> httpClientRequest.putHeader("Authorization", createBasicAuthHeader(basicCredentials)));
    Buffer bodyBuffer = Buffer.buffer(bytes);
    httpClientRequest.end(bodyBuffer);
    // cleanup
    vcf.handle((v, throwable) -> {
        httpClient.close();
        vertx.close();
        return null;
    });
    return vcf;
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) MultiMap(io.vertx.core.MultiMap) CommandStatuses(io.confluent.ksql.rest.entity.CommandStatuses) RestResponse(io.confluent.ksql.rest.client.RestResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) HttpVersion(io.vertx.core.http.HttpVersion) ACCEPT(io.netty.handler.codec.http.HttpHeaderNames.ACCEPT) Map(java.util.Map) URI(java.net.URI) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) UrlEscapers(com.google.common.net.UrlEscapers) ApiJsonMapper(io.confluent.ksql.rest.ApiJsonMapper) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Status(io.confluent.ksql.rest.entity.CommandStatus.Status) Optional(java.util.Optional) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) AUTHORIZATION(io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION) HttpClient(io.vertx.core.http.HttpClient) HttpResponse(io.vertx.ext.web.client.HttpResponse) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) WebClient(io.vertx.ext.web.client.WebClient) POST(io.vertx.core.http.HttpMethod.POST) BodyCodec(io.vertx.ext.web.codec.BodyCodec) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) CompletableFuture(java.util.concurrent.CompletableFuture) WebsocketVersion(io.vertx.core.http.WebsocketVersion) ServerClusterId(io.confluent.ksql.rest.entity.ServerClusterId) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Charset(java.nio.charset.Charset) WriteStream(io.vertx.core.streams.WriteStream) HttpClientOptions(io.vertx.core.http.HttpClientOptions) TestDataProvider(io.confluent.ksql.util.TestDataProvider) HTTP_1_1(io.vertx.core.http.HttpVersion.HTTP_1_1) Credentials(io.confluent.ksql.test.util.secure.Credentials) Vertx(io.vertx.core.Vertx) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) ServerMetadata(io.confluent.ksql.rest.entity.ServerMetadata) KsqlMediaType(io.confluent.ksql.rest.entity.KsqlMediaType) HttpRequest(io.vertx.ext.web.client.HttpRequest) Consumer(java.util.function.Consumer) HttpMethod(io.vertx.core.http.HttpMethod) HealthCheckResponse(io.confluent.ksql.rest.entity.HealthCheckResponse) Collections(java.util.Collections) Buffer(io.vertx.core.buffer.Buffer) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) Vertx(io.vertx.core.Vertx) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Example 4 with BasicCredentials

use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.

the class TestKsqlRestApp method closePersistentQueries.

public void closePersistentQueries(final Optional<BasicCredentials> credentials) {
    try (final KsqlRestClient client = buildKsqlClient(credentials)) {
        // Filter source tables queries because they cannot be terminated manually
        final Set<String> queriesToTerminate = getPersistentQueries(client).stream().filter(query -> !query.getQueryString().startsWith("CREATE SOURCE TABLE")).map(RunningQuery::getId).map(QueryId::toString).collect(Collectors.toSet());
        terminateQueries(queriesToTerminate, client);
    }
}
Also used : Arrays(java.util.Arrays) StreamsList(io.confluent.ksql.rest.entity.StreamsList) URL(java.net.URL) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) InternalKsqlClientFactory(io.confluent.ksql.rest.server.services.InternalKsqlClientFactory) BiFunction(java.util.function.BiFunction) ServiceContext(io.confluent.ksql.services.ServiceContext) KsqlQueryType(io.confluent.ksql.util.KsqlConstants.KsqlQueryType) RestResponse(io.confluent.ksql.rest.client.RestResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) NetworkState(io.confluent.ksql.rest.server.NetworkDisruptorClient.NetworkState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) QueryId(io.confluent.ksql.query.QueryId) URI(java.net.URI) ImmutableMap(com.google.common.collect.ImmutableMap) PropertiesUtil(io.confluent.ksql.properties.PropertiesUtil) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Collectors(java.util.stream.Collectors) SimpleKsqlClient(io.confluent.ksql.services.SimpleKsqlClient) TestRestServiceContextFactory(io.confluent.ksql.rest.server.services.TestRestServiceContextFactory) DisabledKsqlClient(io.confluent.ksql.services.DisabledKsqlClient) CountDownLatch(java.util.concurrent.CountDownLatch) ConsistencyLevel(io.confluent.ksql.util.ClientConfig.ConsistencyLevel) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) VersionCheckerAgent(io.confluent.ksql.version.metrics.VersionCheckerAgent) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) Iterables(com.google.common.collect.Iterables) InternalSimpleKsqlClientFactory(io.confluent.ksql.rest.server.services.TestRestServiceContextFactory.InternalSimpleKsqlClientFactory) EmbeddedSingleNodeKafkaCluster(io.confluent.ksql.test.util.EmbeddedSingleNodeKafkaCluster) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) HashMap(java.util.HashMap) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) ReservedInternalTopics(io.confluent.ksql.util.ReservedInternalTopics) Supplier(java.util.function.Supplier) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) TestDefaultKsqlClientFactory(io.confluent.ksql.rest.server.services.TestDefaultKsqlClientFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) LinkedList(java.util.LinkedList) LinkedHashSet(java.util.LinkedHashSet) SocketAddress(io.vertx.core.net.SocketAddress) Iterator(java.util.Iterator) Vertx(io.vertx.core.Vertx) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) ServiceContextFactory(io.confluent.ksql.services.ServiceContextFactory) Collections(java.util.Collections) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery)

Example 5 with BasicCredentials

use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.

the class BasicAuthFunctionalTest method shouldNotBeAbleToUseWsWithInvalidPassword.

@Test
public void shouldNotBeAbleToUseWsWithInvalidPassword() throws Exception {
    // Given:
    final BasicCredentials wrongPassword = BasicCredentials.of(USER_NO_ACCESS.username(), "wrong");
    // Then:
    assertThat(makeWsRequest(Optional.of(wrongPassword)), is(UNAUTHORIZED.code()));
}
Also used : BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Aggregations

BasicCredentials (io.confluent.ksql.rest.client.BasicCredentials)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)3 RestResponse (io.confluent.ksql.rest.client.RestResponse)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 IntegrationTest (io.confluent.common.utils.IntegrationTest)2 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)2 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)2 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)2 Vertx (io.vertx.core.Vertx)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Iterables (com.google.common.collect.Iterables)1 UrlEscapers (com.google.common.net.UrlEscapers)1