use of org.apache.kafka.common.config.types.Password in project kafka by apache.
the class LoginManagerTest method setUp.
@BeforeEach
public void setUp() {
dynamicPlainContext = new Password(PlainLoginModule.class.getName() + " required user=\"plainuser\" password=\"plain-secret\";");
dynamicDigestContext = new Password(TestDigestLoginModule.class.getName() + " required user=\"digestuser\" password=\"digest-secret\";");
TestJaasConfig.createConfiguration("SCRAM-SHA-256", Collections.singletonList("SCRAM-SHA-256"));
}
use of org.apache.kafka.common.config.types.Password in project kafka by apache.
the class TestSslUtils method exportPrivateKey.
public static Password exportPrivateKey(String storePath, Password storePassword, Password keyPassword, String storeType, Password pemKeyPassword) throws Exception {
try (FileInputStream in = new FileInputStream(storePath)) {
KeyStore ks = KeyStore.getInstance(storeType);
ks.load(in, storePassword.value().toCharArray());
String alias = ks.aliases().nextElement();
return new Password(pem((PrivateKey) ks.getKey(alias, keyPassword.value().toCharArray()), pemKeyPassword));
}
}
use of org.apache.kafka.common.config.types.Password in project kafka by apache.
the class TestSslUtils method convertToPem.
public static void convertToPem(Map<String, Object> sslProps, boolean writeToFile, boolean encryptPrivateKey) throws Exception {
String tsPath = (String) sslProps.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG);
String tsType = (String) sslProps.get(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG);
Password tsPassword = (Password) sslProps.remove(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG);
Password trustCerts = (Password) sslProps.remove(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG);
if (trustCerts == null && tsPath != null) {
trustCerts = exportCertificates(tsPath, tsPassword, tsType);
}
if (trustCerts != null) {
if (tsPath == null) {
tsPath = File.createTempFile("truststore", ".pem").getPath();
sslProps.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, tsPath);
}
sslProps.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, PEM_TYPE);
if (writeToFile)
writeToFile(tsPath, trustCerts);
else {
sslProps.put(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG, trustCerts);
sslProps.remove(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG);
}
}
String ksPath = (String) sslProps.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG);
Password certChain = (Password) sslProps.remove(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG);
Password key = (Password) sslProps.remove(SslConfigs.SSL_KEYSTORE_KEY_CONFIG);
if (certChain == null && ksPath != null) {
String ksType = (String) sslProps.get(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG);
Password ksPassword = (Password) sslProps.remove(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG);
Password keyPassword = (Password) sslProps.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG);
certChain = exportCertificates(ksPath, ksPassword, ksType);
Password pemKeyPassword = encryptPrivateKey ? keyPassword : null;
key = exportPrivateKey(ksPath, ksPassword, keyPassword, ksType, pemKeyPassword);
if (!encryptPrivateKey)
sslProps.remove(SslConfigs.SSL_KEY_PASSWORD_CONFIG);
}
if (certChain != null) {
if (ksPath == null) {
ksPath = File.createTempFile("keystore", ".pem").getPath();
sslProps.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, ksPath);
}
sslProps.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, PEM_TYPE);
if (writeToFile)
writeToFile(ksPath, key, certChain);
else {
sslProps.put(SslConfigs.SSL_KEYSTORE_KEY_CONFIG, key);
sslProps.put(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG, certChain);
sslProps.remove(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG);
}
}
}
use of org.apache.kafka.common.config.types.Password in project kafka by apache.
the class AbstractConfigTest method testValuesWithSecondaryPrefix.
@Test
public void testValuesWithSecondaryPrefix() {
String prefix = "listener.name.listener1.";
Password saslJaasConfig1 = new Password("test.myLoginModule1 required;");
Password saslJaasConfig2 = new Password("test.myLoginModule2 required;");
Password saslJaasConfig3 = new Password("test.myLoginModule3 required;");
Properties props = new Properties();
props.put("listener.name.listener1.test-mechanism.sasl.jaas.config", saslJaasConfig1.value());
props.put("test-mechanism.sasl.jaas.config", saslJaasConfig2.value());
props.put("sasl.jaas.config", saslJaasConfig3.value());
props.put("listener.name.listener1.gssapi.sasl.kerberos.kinit.cmd", "/usr/bin/kinit2");
props.put("listener.name.listener1.gssapi.sasl.kerberos.service.name", "testkafka");
props.put("listener.name.listener1.gssapi.sasl.kerberos.min.time.before.relogin", "60000");
props.put("ssl.provider", "TEST");
TestSecurityConfig config = new TestSecurityConfig(props);
Map<String, Object> valuesWithPrefixOverride = config.valuesWithPrefixOverride(prefix);
// prefix with mechanism overrides global
assertTrue(config.unused().contains("listener.name.listener1.test-mechanism.sasl.jaas.config"));
assertTrue(config.unused().contains("test-mechanism.sasl.jaas.config"));
assertEquals(saslJaasConfig1, valuesWithPrefixOverride.get("test-mechanism.sasl.jaas.config"));
assertEquals(saslJaasConfig3, valuesWithPrefixOverride.get("sasl.jaas.config"));
assertFalse(config.unused().contains("listener.name.listener1.test-mechanism.sasl.jaas.config"));
assertFalse(config.unused().contains("test-mechanism.sasl.jaas.config"));
assertFalse(config.unused().contains("sasl.jaas.config"));
// prefix with mechanism overrides default
assertFalse(config.unused().contains("sasl.kerberos.kinit.cmd"));
assertTrue(config.unused().contains("listener.name.listener1.gssapi.sasl.kerberos.kinit.cmd"));
assertFalse(config.unused().contains("gssapi.sasl.kerberos.kinit.cmd"));
assertFalse(config.unused().contains("sasl.kerberos.kinit.cmd"));
assertEquals("/usr/bin/kinit2", valuesWithPrefixOverride.get("gssapi.sasl.kerberos.kinit.cmd"));
assertFalse(config.unused().contains("listener.name.listener1.sasl.kerberos.kinit.cmd"));
// prefix override for mechanism with no default
assertFalse(config.unused().contains("sasl.kerberos.service.name"));
assertTrue(config.unused().contains("listener.name.listener1.gssapi.sasl.kerberos.service.name"));
assertFalse(config.unused().contains("gssapi.sasl.kerberos.service.name"));
assertFalse(config.unused().contains("sasl.kerberos.service.name"));
assertEquals("testkafka", valuesWithPrefixOverride.get("gssapi.sasl.kerberos.service.name"));
assertFalse(config.unused().contains("listener.name.listener1.gssapi.sasl.kerberos.service.name"));
// unset with no default
assertTrue(config.unused().contains("ssl.provider"));
assertNull(valuesWithPrefixOverride.get("gssapi.ssl.provider"));
assertTrue(config.unused().contains("ssl.provider"));
}
use of org.apache.kafka.common.config.types.Password in project kafka by apache.
the class ConfigDefTest method testBasicTypes.
@Test
public void testBasicTypes() {
ConfigDef def = new ConfigDef().define("a", Type.INT, 5, Range.between(0, 14), Importance.HIGH, "docs").define("b", Type.LONG, Importance.HIGH, "docs").define("c", Type.STRING, "hello", Importance.HIGH, "docs").define("d", Type.LIST, Importance.HIGH, "docs").define("e", Type.DOUBLE, Importance.HIGH, "docs").define("f", Type.CLASS, Importance.HIGH, "docs").define("g", Type.BOOLEAN, Importance.HIGH, "docs").define("h", Type.BOOLEAN, Importance.HIGH, "docs").define("i", Type.BOOLEAN, Importance.HIGH, "docs").define("j", Type.PASSWORD, Importance.HIGH, "docs");
Properties props = new Properties();
props.put("a", "1 ");
props.put("b", 2);
props.put("d", " a , b, c");
props.put("e", 42.5d);
props.put("f", String.class.getName());
props.put("g", "true");
props.put("h", "FalSE");
props.put("i", "TRUE");
props.put("j", "password");
Map<String, Object> vals = def.parse(props);
assertEquals(1, vals.get("a"));
assertEquals(2L, vals.get("b"));
assertEquals("hello", vals.get("c"));
assertEquals(asList("a", "b", "c"), vals.get("d"));
assertEquals(42.5d, vals.get("e"));
assertEquals(String.class, vals.get("f"));
assertEquals(true, vals.get("g"));
assertEquals(false, vals.get("h"));
assertEquals(true, vals.get("i"));
assertEquals(new Password("password"), vals.get("j"));
assertEquals(Password.HIDDEN, vals.get("j").toString());
}
Aggregations