Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static token provider: adding optional lsrc-id and pool-id #2625

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,37 @@

import java.net.URL;
import java.util.Map;
import org.apache.kafka.common.security.oauthbearer.secured.ConfigurationUtils;

public class StaticTokenCredentialProvider implements BearerAuthCredentialProvider {

private String bearerToken;
private String targetSchemaRegistry;
private String targetIdentityPoolId;

@Override
public String alias() {
return "STATIC_TOKEN";
}

@Override
public String getTargetSchemaRegistry() {
return this.targetSchemaRegistry;
}

@Override
public String getTargetIdentityPoolId() {
return this.targetIdentityPoolId;
}

@Override
public void configure(Map<String, ?> configs) {
ConfigurationUtils cu = new ConfigurationUtils(configs);
targetSchemaRegistry = cu.validateString(
SchemaRegistryClientConfig.BEARER_AUTH_LOGICAL_CLUSTER, false);
targetIdentityPoolId = cu.validateString(
SchemaRegistryClientConfig.BEARER_AUTH_IDENTITY_POOL_ID, false);

bearerToken = (String) configs.get(SchemaRegistryClientConfig.BEARER_AUTH_TOKEN_CONFIG);
if (bearerToken != null && !bearerToken.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public void configure(Map<String, ?> configs) {
JaasOptionsUtils jou = new JaasOptionsUtils((Map<String, Object>) jaasconfig);

targetSchemaRegistry = cu.validateString(
SchemaRegistryClientConfig.BEARER_AUTH_LOGICAL_CLUSTER);
SchemaRegistryClientConfig.BEARER_AUTH_LOGICAL_CLUSTER, false);

// if the schema registry oauth configs are set it is given higher preference
targetIdentityPoolId = cu.get(SchemaRegistryClientConfig.BEARER_AUTH_IDENTITY_POOL_ID) != null
? cu.validateString(SchemaRegistryClientConfig.BEARER_AUTH_IDENTITY_POOL_ID)
: jou.validateString(SASL_IDENTITY_POOL_CONFIG);
: jou.validateString(SASL_IDENTITY_POOL_CONFIG, false);

tokenRetriever = new CachedOauthTokenRetriever();
tokenRetriever.configure(getTokenRetriever(cu, jou), getTokenValidator(cu, configs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public class StaticTokenCredentialProviderTest {
public void testBearerToken() throws MalformedURLException {
Map<String, Object> clientConfig = new HashMap<>();
clientConfig.put(SchemaRegistryClientConfig.BEARER_AUTH_TOKEN_CONFIG, "auth-token");
clientConfig.put(SchemaRegistryClientConfig.BEARER_AUTH_LOGICAL_CLUSTER, "lsrc-xyz123");
StaticTokenCredentialProvider provider = new StaticTokenCredentialProvider();
provider.configure(clientConfig);
Assert.assertEquals("auth-token", provider.getBearerToken(new URL("http://localhost")));
Assert.assertEquals("lsrc-xyz123", provider.getTargetSchemaRegistry());
Assert.assertNull(provider.getTargetIdentityPoolId());
}

@Test(expected = ConfigException.class)
Expand Down