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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations