Search in sources :

Example 1 with AccessTokenValidator

use of org.apache.kafka.common.security.oauthbearer.secured.AccessTokenValidator 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);
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Namespace(net.sourceforge.argparse4j.inf.Namespace) AccessTokenValidator(org.apache.kafka.common.security.oauthbearer.secured.AccessTokenValidator) AccessTokenRetriever(org.apache.kafka.common.security.oauthbearer.secured.AccessTokenRetriever) CloseableVerificationKeyResolver(org.apache.kafka.common.security.oauthbearer.secured.CloseableVerificationKeyResolver) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException)

Aggregations

ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)1 Namespace (net.sourceforge.argparse4j.inf.Namespace)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 AccessTokenRetriever (org.apache.kafka.common.security.oauthbearer.secured.AccessTokenRetriever)1 AccessTokenValidator (org.apache.kafka.common.security.oauthbearer.secured.AccessTokenValidator)1 CloseableVerificationKeyResolver (org.apache.kafka.common.security.oauthbearer.secured.CloseableVerificationKeyResolver)1