Search in sources :

Example 6 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project schema-registry by confluentinc.

the class SchemaRegistryErrorHandlerTest method setupBasicAuthClient.

private void setupBasicAuthClient(String user, String password) {
    String restUrl = new StringBuilder(restApp.restConnect).insert(getSchemaRegistryProtocol().length() + 3, user + ":" + password + "@").toString();
    restApp.restClient = new RestService(restUrl);
    BasicAuthCredentialProvider basicAuthCredentialProvider = BasicAuthCredentialProviderFactory.getBasicAuthCredentialProvider("URL", new HashMap<String, String>());
    restApp.restClient.setBasicAuthCredentialProvider(basicAuthCredentialProvider);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService)

Example 7 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project flink by apache.

the class CachedSchemaCoderProviderTest method testThatBasicAuthIsNotInitializedForNoBasicAuthProperties.

@Test
public void testThatBasicAuthIsNotInitializedForNoBasicAuthProperties() {
    CachedSchemaCoderProvider provider = initCachedSchemaCoderProvider(new HashMap<>());
    BasicAuthCredentialProvider basicAuthCredentialProvider = getBasicAuthFromProvider(provider);
    assertNull(basicAuthCredentialProvider);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) Test(org.junit.Test)

Example 8 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project flink-mirror by flink-ci.

the class CachedSchemaCoderProviderTest method testThatBasicAuthIsNotInitializedForNoBasicAuthProperties.

@Test
public void testThatBasicAuthIsNotInitializedForNoBasicAuthProperties() {
    CachedSchemaCoderProvider provider = initCachedSchemaCoderProvider(new HashMap<>());
    BasicAuthCredentialProvider basicAuthCredentialProvider = getBasicAuthFromProvider(provider);
    assertNull(basicAuthCredentialProvider);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) Test(org.junit.Test)

Example 9 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project schema-registry by confluentinc.

the class RestServiceTest method testSetHttpHeaders.

/*
 * Test setHttpHeaders (private method) indirectly through getAllSubjects.
 */
@Test
public void testSetHttpHeaders() throws Exception {
    RestService restService = new RestService("http://localhost:8081");
    BasicAuthCredentialProvider basicAuthCredentialProvider = createMock(BasicAuthCredentialProvider.class);
    restService.setHttpHeaders(ImmutableMap.of("api-key", "test-api-key", "source-app", "foo"));
    HttpURLConnection httpURLConnection = createNiceMock(HttpURLConnection.class);
    InputStream inputStream = createNiceMock(InputStream.class);
    expectNew(URL.class, anyString()).andReturn(url);
    expect(url.openConnection()).andReturn(httpURLConnection);
    expect(httpURLConnection.getResponseCode()).andReturn(HttpURLConnection.HTTP_OK);
    // Make sure that the Authorization header is set with the correct value for "user:password"
    httpURLConnection.setRequestProperty("api-key", "test-api-key");
    httpURLConnection.setRequestProperty("source-app", "foo");
    expectLastCall().once();
    expect(httpURLConnection.getInputStream()).andReturn(inputStream);
    expect(inputStream.read(anyObject(), anyInt(), anyInt())).andDelegateTo(createInputStream("[\"abc\"]")).anyTimes();
    replay(URL.class, url);
    replay(HttpURLConnection.class, httpURLConnection);
    replay(InputStream.class, inputStream);
    restService.getAllSubjects();
    verify(httpURLConnection);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project schema-registry by confluentinc.

the class RestService method configure.

@Override
public void configure(Map<String, ?> configs) {
    String basicCredentialsSource = (String) configs.get(SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE);
    String bearerCredentialsSource = (String) configs.get(SchemaRegistryClientConfig.BEARER_AUTH_CREDENTIALS_SOURCE);
    if (isNonEmpty(basicCredentialsSource) && isNonEmpty(bearerCredentialsSource)) {
        throw new ConfigException(String.format("Only one of '%s' and '%s' may be specified", SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE, SchemaRegistryClientConfig.BEARER_AUTH_CREDENTIALS_SOURCE));
    } else if (isNonEmpty(basicCredentialsSource)) {
        BasicAuthCredentialProvider basicAuthCredentialProvider = BasicAuthCredentialProviderFactory.getBasicAuthCredentialProvider(basicCredentialsSource, configs);
        setBasicAuthCredentialProvider(basicAuthCredentialProvider);
    } else if (isNonEmpty(bearerCredentialsSource)) {
        BearerAuthCredentialProvider bearerAuthCredentialProvider = BearerAuthCredentialProviderFactory.getBearerAuthCredentialProvider(bearerCredentialsSource, configs);
        setBearerAuthCredentialProvider(bearerAuthCredentialProvider);
    }
    String proxyHost = (String) configs.get(SchemaRegistryClientConfig.PROXY_HOST);
    Object proxyPortVal = configs.get(SchemaRegistryClientConfig.PROXY_PORT);
    Integer proxyPort = proxyPortVal instanceof String ? Integer.valueOf((String) proxyPortVal) : (Integer) proxyPortVal;
    if (isValidProxyConfig(proxyHost, proxyPort)) {
        setProxy(proxyHost, proxyPort);
    }
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) BearerAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.bearerauth.BearerAuthCredentialProvider) ConfigException(org.apache.kafka.common.config.ConfigException) SchemaString(io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)

Aggregations

BasicAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider)11 Test (org.junit.Test)8 HashMap (java.util.HashMap)3 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)1 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)1 SslFactory (io.confluent.kafka.schemaregistry.client.security.SslFactory)1 BasicAuthCredentialProviderFactory (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProviderFactory)1 UserInfoCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider)1 BearerAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.bearerauth.BearerAuthCredentialProvider)1 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)1 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)1 Inject (jakarta.inject.Inject)1