@Test(expected = ConfigException.class) public void testClientJaasConfigWithKerberos() throws IOException { Map<String, Object> clientConfig = new HashMap<>(); clientConfig.put(SaslConfigs.SASL_JAAS_CONFIG, new Password("com.sun.security.auth.module.Krb5LoginModule required " + " useKeyTab=true " + " storeKey=true " + " keyTab=\"/etc/security/keytabs/kafka_client.keytab\" " + " principal=\"kafka-client-1@EXAMPLE.COM\";")); Configuration.setConfiguration(null); SaslBasicAuthCredentialProvider provider = new SaslBasicAuthCredentialProvider(); provider.configure(clientConfig); }
@Override public void configure(Map<String, ?> configs) { Map<String, Object> updatedConfigs = getConfigsForJaasUtil(configs); JaasContext jaasContext = JaasContext.loadClientContext(updatedConfigs); List<AppConfigurationEntry> appConfigurationEntries = jaasContext.configurationEntries(); if (appConfigurationEntries != null && !appConfigurationEntries.isEmpty()) { Map<String, ?> options = appConfigurationEntries.get(0).getOptions(); StringBuilder userInfoBuilder = new StringBuilder(); if (options.containsKey("username")) { userInfoBuilder.append(options.get("username")).append(":").append(options.get("password")); userInfo = userInfoBuilder.toString(); } } if (userInfo == null || userInfo.isEmpty()) { throw new ConfigException("Provided SASL Login module doesn't provide username and password" + " options and can't be inherited"); } }
SaslBasicAuthCredentialProvider implements BasicAuthCredentialProvider { @Override public void configure(Map<String, ?> configs) { Map<String, Object> updatedConfigs = getConfigsForJaasUtil(configs); JaasContext jaasContext = JaasContext.loadClientContext(updatedConfigs); List<AppConfigurationEntry> appConfigurationEntries = jaasContext.configurationEntries(); if (appConfigurationEntries != null && !appConfigurationEntries.isEmpty()) { Map<String, ?> options = appConfigurationEntries.get(0).getOptions(); StringBuilder userInfoBuilder = new StringBuilder(); if (options.containsKey("username")) { userInfoBuilder.append(options.get("username")).append(":").append(options.get("password")); userInfo = userInfoBuilder.toString(); } } if (userInfo == null || userInfo.isEmpty()) { throw new ConfigException("Provided SASL Login module doesn't provide username and password" + " options and can't be inherited"); } } }
SaslBasicAuthCredentialProvider implements BasicAuthCredentialProvider { @Override public void configure(Map<String, ?> configs) { Map<String, Object> updatedConfigs = getConfigsForJaasUtil(configs); JaasContext jaasContext = JaasContext.loadClientContext(updatedConfigs); List<AppConfigurationEntry> appConfigurationEntries = jaasContext.configurationEntries(); if (appConfigurationEntries != null && !appConfigurationEntries.isEmpty()) { Map<String, ?> options = appConfigurationEntries.get(0).getOptions(); StringBuilder userInfoBuilder = new StringBuilder(); if (options.containsKey("username")) { userInfoBuilder.append(options.get("username")).append(":").append(options.get("password")); userInfo = userInfoBuilder.toString(); } } if (userInfo == null || userInfo.isEmpty()) { throw new ConfigException("Provided SASL Login module doesn't provide username and password" + " options and can't be inherited"); } }  }
SaslBasicAuthCredentialProvider implements BasicAuthCredentialProvider { @Override public void configure(Map<String, ?> configs) { Map<String, Object> updatedConfigs = getConfigsForJaasUtil(configs); JaasContext jaasContext = JaasContext.loadClientContext(updatedConfigs); List<AppConfigurationEntry> appConfigurationEntries = jaasContext.configurationEntries(); if (appConfigurationEntries != null && !appConfigurationEntries.isEmpty()) { Map<String, ?> options = appConfigurationEntries.get(0).getOptions(); StringBuilder userInfoBuilder = new StringBuilder(); if (options.containsKey("username")) { userInfoBuilder.append(options.get("username")).append(":").append(options.get("password")); userInfo = userInfoBuilder.toString(); } } if (userInfo == null || userInfo.isEmpty()) { throw new ConfigException("Provided SASL Login module doesn't provide username and password" + " options and can't be inherited"); } }  @Override String alias(); @Override void configure(Map<String, ?> configs); @Override String getUserInfo(URL url); }
SaslBasicAuthCredentialProvider implements BasicAuthCredentialProvider { @Override public void configure(Map<String, ?> configs) { Map<String, Object> updatedConfigs = getConfigsForJaasUtil(configs); JaasContext jaasContext = JaasContext.loadClientContext(updatedConfigs); List<AppConfigurationEntry> appConfigurationEntries = jaasContext.configurationEntries(); if (appConfigurationEntries != null && !appConfigurationEntries.isEmpty()) { Map<String, ?> options = appConfigurationEntries.get(0).getOptions(); StringBuilder userInfoBuilder = new StringBuilder(); if (options.containsKey("username")) { userInfoBuilder.append(options.get("username")).append(":").append(options.get("password")); userInfo = userInfoBuilder.toString(); } } if (userInfo == null || userInfo.isEmpty()) { throw new ConfigException("Provided SASL Login module doesn't provide username and password" + " options and can't be inherited"); } }  @Override String alias(); @Override void configure(Map<String, ?> configs); @Override String getUserInfo(URL url);  }