Search in sources :

Example 1 with CredentialCache

use of org.apache.kafka.common.security.authenticator.CredentialCache in project apache-kafka-on-k8s by banzaicloud.

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 not created for enabled mechanism", cache.cache(ScramMechanism.SCRAM_SHA_512.mechanismName(), ScramCredential.class));
    assertNull("Cache created for disabled mechanism", cache.cache(ScramMechanism.SCRAM_SHA_256.mechanismName(), ScramCredential.class));
    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("Invalid user credential", sha512Cache.get("userB"));
}
Also used : CredentialCache(org.apache.kafka.common.security.authenticator.CredentialCache) Test(org.junit.Test)

Example 2 with CredentialCache

use of org.apache.kafka.common.security.authenticator.CredentialCache 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");
}
Also used : ScramCredential(org.apache.kafka.common.security.scram.ScramCredential) CredentialCache(org.apache.kafka.common.security.authenticator.CredentialCache) Test(org.junit.jupiter.api.Test)

Example 3 with CredentialCache

use of org.apache.kafka.common.security.authenticator.CredentialCache 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);
}
Also used : ScramCredential(org.apache.kafka.common.security.scram.ScramCredential) HashMap(java.util.HashMap) CredentialCache(org.apache.kafka.common.security.authenticator.CredentialCache) DelegationTokenCache(org.apache.kafka.common.security.token.delegation.internals.DelegationTokenCache) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CredentialCache

use of org.apache.kafka.common.security.authenticator.CredentialCache 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 not created for enabled mechanism", cache.cache(ScramMechanism.SCRAM_SHA_512.mechanismName(), ScramCredential.class));
    assertNull("Cache created for disabled mechanism", cache.cache(ScramMechanism.SCRAM_SHA_256.mechanismName(), ScramCredential.class));
    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("Invalid user credential", sha512Cache.get("userB"));
}
Also used : CredentialCache(org.apache.kafka.common.security.authenticator.CredentialCache) Test(org.junit.Test)

Example 5 with CredentialCache

use of org.apache.kafka.common.security.authenticator.CredentialCache in project apache-kafka-on-k8s by banzaicloud.

the class ScramSaslServerTest method setUp.

@Before
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);
}
Also used : HashMap(java.util.HashMap) CredentialCache(org.apache.kafka.common.security.authenticator.CredentialCache) DelegationTokenCache(org.apache.kafka.common.security.token.delegation.DelegationTokenCache) Before(org.junit.Before)

Aggregations

CredentialCache (org.apache.kafka.common.security.authenticator.CredentialCache)5 HashMap (java.util.HashMap)2 ScramCredential (org.apache.kafka.common.security.scram.ScramCredential)2 Test (org.junit.Test)2 DelegationTokenCache (org.apache.kafka.common.security.token.delegation.DelegationTokenCache)1 DelegationTokenCache (org.apache.kafka.common.security.token.delegation.internals.DelegationTokenCache)1 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1