use of org.apache.kafka.common.security.scram.ScramCredential in project apache-kafka-on-k8s by banzaicloud.
the class SaslAuthenticatorTest method updateTokenCredentialCache.
private void updateTokenCredentialCache(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);
server.tokenCache().credentialCache(scramMechanism.mechanismName()).put(username, credential);
}
}
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class ScramCredentialUtilsTest method stringConversion.
@Test
public void stringConversion() {
ScramCredential credential = formatter.generateCredential("password", 1024);
assertTrue(credential.salt().length > 0, "Salt must not be empty");
assertTrue(credential.storedKey().length > 0, "Stored key must not be empty");
assertTrue(credential.serverKey().length > 0, "Server key must not be empty");
ScramCredential credential2 = ScramCredentialUtils.credentialFromString(ScramCredentialUtils.credentialToString(credential));
assertArrayEquals(credential.salt(), credential2.salt());
assertArrayEquals(credential.storedKey(), credential2.storedKey());
assertArrayEquals(credential.serverKey(), credential2.serverKey());
assertEquals(credential.iterations(), credential2.iterations());
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class ScramCredentialUtilsTest method scramCredentialCache.
@Test
public void scramCredentialCache() throws Exception {
CredentialCache cache = new CredentialCache();
ScramCredentialUtils.createCache(cache, Arrays.asList("SCRAM-SHA-512", "PLAIN"));
assertNotNull(cache.cache(ScramMechanism.SCRAM_SHA_512.mechanismName(), ScramCredential.class), "Cache not created for enabled mechanism");
assertNull(cache.cache(ScramMechanism.SCRAM_SHA_256.mechanismName(), ScramCredential.class), "Cache created for disabled mechanism");
CredentialCache.Cache<ScramCredential> sha512Cache = cache.cache(ScramMechanism.SCRAM_SHA_512.mechanismName(), ScramCredential.class);
ScramFormatter formatter = new ScramFormatter(ScramMechanism.SCRAM_SHA_512);
ScramCredential credentialA = formatter.generateCredential("password", 4096);
sha512Cache.put("userA", credentialA);
assertEquals(credentialA, sha512Cache.get("userA"));
assertNull(sha512Cache.get("userB"), "Invalid user credential");
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class SaslAuthenticatorTest method updateTokenCredentialCache.
@SuppressWarnings("unchecked")
private void updateTokenCredentialCache(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);
server.tokenCache().credentialCache(scramMechanism.mechanismName()).put(username, credential);
}
}
}
use of org.apache.kafka.common.security.scram.ScramCredential in project kafka by apache.
the class ScramSaslServerTest method setUp.
@BeforeEach
public void setUp() throws Exception {
mechanism = ScramMechanism.SCRAM_SHA_256;
formatter = new ScramFormatter(mechanism);
CredentialCache.Cache<ScramCredential> credentialCache = new CredentialCache().createCache(mechanism.mechanismName(), ScramCredential.class);
credentialCache.put(USER_A, formatter.generateCredential("passwordA", 4096));
credentialCache.put(USER_B, formatter.generateCredential("passwordB", 4096));
ScramServerCallbackHandler callbackHandler = new ScramServerCallbackHandler(credentialCache, new DelegationTokenCache(ScramMechanism.mechanismNames()));
saslServer = new ScramSaslServer(mechanism, new HashMap<String, Object>(), callbackHandler);
}
Aggregations