use of org.apache.kafka.common.security.oauthbearer.secured.CloseableVerificationKeyResolver in project kafka by apache.
the class OAuthCompatibilityTool method main.
public static void main(String[] args) {
ArgsHandler argsHandler = new ArgsHandler();
Namespace namespace;
try {
namespace = argsHandler.parseArgs(args);
} catch (ArgumentParserException e) {
Exit.exit(1);
return;
}
ConfigHandler configHandler = new ConfigHandler(namespace);
Map<String, ?> configs = configHandler.getConfigs();
Map<String, Object> jaasConfigs = configHandler.getJaasOptions();
try {
String accessToken;
{
// Client side...
try (AccessTokenRetriever atr = AccessTokenRetrieverFactory.create(configs, jaasConfigs)) {
atr.init();
AccessTokenValidator atv = AccessTokenValidatorFactory.create(configs);
System.out.println("PASSED 1/5: client configuration");
accessToken = atr.retrieve();
System.out.println("PASSED 2/5: client JWT retrieval");
atv.validate(accessToken);
System.out.println("PASSED 3/5: client JWT validation");
}
}
{
// Broker side...
try (CloseableVerificationKeyResolver vkr = VerificationKeyResolverFactory.create(configs, jaasConfigs)) {
vkr.init();
AccessTokenValidator atv = AccessTokenValidatorFactory.create(configs, vkr);
System.out.println("PASSED 4/5: broker configuration");
atv.validate(accessToken);
System.out.println("PASSED 5/5: broker JWT validation");
}
}
System.out.println("SUCCESS");
Exit.exit(0);
} catch (Throwable t) {
System.out.println("FAILED:");
t.printStackTrace();
if (t instanceof ConfigException) {
System.out.printf("%n");
argsHandler.parser.printHelp();
}
Exit.exit(1);
}
}
Aggregations