use of org.apache.kafka.common.security.scram.ScramCredential in project apache-kafka-on-k8s by banzaicloud.
the class SaslAuthenticatorTest method updateScramCredentialCache.
@SuppressWarnings("unchecked")
private void updateScramCredentialCache(String username, String password) throws NoSuchAlgorithmException {
for (String mechanism : (List<String>) saslServerConfigs.get(BrokerSecurityConfigs.SASL_ENABLED_MECHANISMS_CONFIG)) {
ScramMechanism scramMechanism = ScramMechanism.forMechanismName(mechanism);
if (scramMechanism != null) {
ScramFormatter formatter = new ScramFormatter(scramMechanism);
ScramCredential credential = formatter.generateCredential(password, 4096);
credentialCache.cache(scramMechanism.mechanismName(), ScramCredential.class).put(username, credential);
}
}
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class ScramCredentialUtils method credentialFromString.
public static ScramCredential credentialFromString(String str) {
Properties props = toProps(str);
if (props.size() != 4 || !props.containsKey(SALT) || !props.containsKey(STORED_KEY) || !props.containsKey(SERVER_KEY) || !props.containsKey(ITERATIONS)) {
throw new IllegalArgumentException("Credentials not valid: " + str);
}
byte[] salt = Base64.getDecoder().decode(props.getProperty(SALT));
byte[] storedKey = Base64.getDecoder().decode(props.getProperty(STORED_KEY));
byte[] serverKey = Base64.getDecoder().decode(props.getProperty(SERVER_KEY));
int iterations = Integer.parseInt(props.getProperty(ITERATIONS));
return new ScramCredential(salt, storedKey, serverKey, iterations);
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class ScramFormatter method generateCredential.
public ScramCredential generateCredential(byte[] salt, byte[] saltedPassword, int iterations) {
try {
byte[] clientKey = clientKey(saltedPassword);
byte[] storedKey = storedKey(clientKey);
byte[] serverKey = serverKey(saltedPassword);
return new ScramCredential(salt, storedKey, serverKey, iterations);
} catch (InvalidKeyException e) {
throw new KafkaException("Could not create credential", e);
}
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class SaslAuthenticatorTest method updateScramCredentialCache.
@SuppressWarnings("unchecked")
private void updateScramCredentialCache(String username, String password) throws NoSuchAlgorithmException {
for (String mechanism : (List<String>) saslServerConfigs.get(BrokerSecurityConfigs.SASL_ENABLED_MECHANISMS_CONFIG)) {
ScramMechanism scramMechanism = ScramMechanism.forMechanismName(mechanism);
if (scramMechanism != null) {
ScramFormatter formatter = new ScramFormatter(scramMechanism);
ScramCredential credential = formatter.generateCredential(password, 4096);
credentialCache.cache(scramMechanism.mechanismName(), ScramCredential.class).put(username, credential);
}
}
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class ScramCredentialUtilsTest method generateCredential.
@Test
public void generateCredential() {
ScramCredential credential1 = formatter.generateCredential("password", 4096);
ScramCredential credential2 = formatter.generateCredential("password", 4096);
// Random salt should ensure that the credentials persisted are different every time
assertNotEquals(ScramCredentialUtils.credentialToString(credential1), ScramCredentialUtils.credentialToString(credential2));
}
Aggregations