Search in sources :

Example 1 with BasicCallbackHandler

use of org.infinispan.client.hotrod.security.BasicCallbackHandler in project infinispan by infinispan.

the class AuthenticationConfigurationBuilder method create.

@Override
public AuthenticationConfiguration create() {
    String mech = saslMechanism == null ? DEFAULT_MECHANISM : saslMechanism;
    CallbackHandler cbh = callbackHandler;
    if (cbh == null) {
        if (OAUTHBEARER_MECH.equals(mech)) {
            cbh = new TokenCallbackHandler(token);
        } else if (username != null) {
            cbh = new BasicCallbackHandler(username, realm != null ? realm : DEFAULT_REALM, password);
        } else if (EXTERNAL_MECH.equals(mech) || GSSAPI_MECH.equals(mech) || GS2_KRB5_MECH.equals(mech)) {
            cbh = new VoidCallbackHandler();
        }
    }
    return new AuthenticationConfiguration(cbh, clientSubject, enabled, mech, saslProperties, serverName != null ? serverName : DEFAULT_SERVER_NAME);
}
Also used : TokenCallbackHandler(org.infinispan.client.hotrod.security.TokenCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) TokenCallbackHandler(org.infinispan.client.hotrod.security.TokenCallbackHandler) VoidCallbackHandler(org.infinispan.client.hotrod.security.VoidCallbackHandler) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) VoidCallbackHandler(org.infinispan.client.hotrod.security.VoidCallbackHandler)

Example 2 with BasicCallbackHandler

use of org.infinispan.client.hotrod.security.BasicCallbackHandler in project infinispan by infinispan.

the class CustomPropertiesTest method testDefaultClient.

@Test
public void testDefaultClient() throws Exception {
    // when
    Configuration configuration = remoteCacheManager.getConfiguration();
    String hostObtainedFromPropertiesFile = configuration.servers().get(0).host();
    int portObtainedFromPropertiesFile = configuration.servers().get(0).port();
    // Connection
    assertThat(hostObtainedFromPropertiesFile).isEqualTo("127.0.0.1");
    assertThat(portObtainedFromPropertiesFile).isEqualTo(6667);
    assertThat(configuration.tcpNoDelay()).isFalse();
    assertThat(configuration.tcpKeepAlive()).isTrue();
    assertThat(configuration.clientIntelligence()).isEqualTo(ClientIntelligence.TOPOLOGY_AWARE);
    assertThat(configuration.socketTimeout()).isEqualTo(3000);
    assertThat(configuration.connectionTimeout()).isEqualTo(5000);
    assertThat(configuration.maxRetries()).isEqualTo(42);
    assertThat(configuration.batchSize()).isEqualTo(90);
    assertThat(configuration.version()).isEqualTo(ProtocolVersion.PROTOCOL_VERSION_28);
    // Connection pool properties
    assertThat(configuration.connectionPool().maxActive()).isEqualTo(91);
    assertThat(configuration.connectionPool().exhaustedAction()).isEqualTo(ExhaustedAction.EXCEPTION);
    assertThat(configuration.connectionPool().maxWait()).isEqualTo(20001);
    assertThat(configuration.connectionPool().minIdle()).isEqualTo(1001);
    assertThat(configuration.connectionPool().minEvictableIdleTime()).isEqualTo(9001);
    assertThat(configuration.connectionPool().maxPendingRequests()).isEqualTo(846);
    // Thread pool properties
    assertThat(configuration.asyncExecutorFactory().factoryClass()).isEqualTo(DefaultAsyncExecutorFactory.class);
    // TODO: how to assert thread pool size ? default_executor_factory.pool_size
    // Marshalling properties
    assertThat(configuration.marshallerClass()).isEqualTo(JavaSerializationMarshaller.class);
    assertThat(configuration.keySizeEstimate()).isEqualTo(123456);
    assertThat(configuration.valueSizeEstimate()).isEqualTo(789012);
    assertThat(configuration.forceReturnValues()).isTrue();
    assertThat(configuration.serialWhitelist()).contains("SERIAL-KILLER");
    // TODO: Consistent Hash Impl ??
    // assertThat(configuration.consistentHashImpl().getClass().toString()).isEqualTo("");
    // Encryption properties
    assertThat(configuration.security().ssl().enabled()).isTrue();
    assertThat(configuration.security().ssl().keyStoreFileName()).isEqualTo("keyStoreFile");
    assertThat(configuration.security().ssl().keyStoreType()).isEqualTo("JKS");
    assertThat(configuration.security().ssl().keyStorePassword()).hasSize(12);
    assertThat(configuration.security().ssl().keyAlias()).isEqualTo("aliasKey");
    assertThat(configuration.security().ssl().keyStoreCertificatePassword()).hasSize(9);
    assertThat(configuration.security().ssl().trustStoreFileName()).isEqualTo("trustFileName");
    assertThat(configuration.security().ssl().trustStorePath()).isNull();
    assertThat(configuration.security().ssl().trustStoreType()).isEqualTo("LOL");
    assertThat(configuration.security().ssl().trustStorePassword().length).isEqualTo(13);
    assertThat(configuration.security().ssl().sniHostName()).isEqualTo("oihost");
    assertThat(configuration.security().ssl().protocol()).isEqualTo("TLSv1.3");
    // authentication
    assertThat(configuration.security().authentication().enabled()).isTrue();
    assertThat(configuration.security().authentication().saslMechanism()).isEqualTo("DIGEST-MD5");
    assertThat(configuration.security().authentication().callbackHandler()).isInstanceOf(BasicCallbackHandler.class);
    assertThat(configuration.security().authentication().serverName()).isEqualTo("my_ela_server_name");
    BasicCallbackHandler basicCallbackHandler = (BasicCallbackHandler) configuration.security().authentication().callbackHandler();
    NameCallback nameCallback = new NameCallback("test", "test");
    PasswordCallback passwordCallback = new PasswordCallback("test", false);
    RealmCallback realmCallback = new RealmCallback("test", "test");
    basicCallbackHandler.handle(new Callback[] { nameCallback, passwordCallback, realmCallback });
    assertThat(nameCallback.getName()).isEqualTo("elaia");
    assertThat(passwordCallback.getPassword()).isEqualTo("elapass".toCharArray());
    assertThat(realmCallback.getText()).isEqualTo("elarealm");
    assertThat(configuration.security().authentication().saslProperties()).hasSize(1);
    assertThat(configuration.security().authentication().saslProperties()).containsOnlyKeys("prop1");
    assertThat(configuration.security().authentication().saslProperties()).containsValues("value1");
    // Transaction properties
    // TODO: transaction_manager_lookup??
    assertThat(configuration.transaction().transactionMode()).isEqualTo(TransactionMode.FULL_XA);
    assertThat(configuration.transaction().timeout()).isEqualTo(50001);
    // near cache
    assertThat(configuration.nearCache().mode()).isEqualTo(NearCacheMode.INVALIDATED);
    assertThat(configuration.nearCache().maxEntries()).isEqualTo(10000);
    assertThat(configuration.nearCache().cacheNamePattern().pattern()).isEqualTo("nearSuperCache*");
    // xsite
    assertThat(configuration.clusters()).hasSize(2);
    ClusterConfiguration siteA = configuration.clusters().get(0);
    ClusterConfiguration siteB = configuration.clusters().get(1);
    assertThat(siteA.getClusterName()).isEqualTo("siteA");
    assertThat(siteB.getClusterName()).isEqualTo("siteB");
    assertThat(siteA.getCluster()).extracting("host", "port").containsExactly(tuple("hostA1", 11222), tuple("hostA2", 11223));
    assertThat(siteB.getCluster()).extracting("host", "port").containsExactly(tuple("hostB1", 11224), tuple("hostB2", 11225));
    // statistics
    assertThat(configuration.statistics().enabled()).isTrue();
    assertThat(configuration.statistics().jmxEnabled()).isTrue();
    assertThat(configuration.statistics().jmxName()).isEqualTo("elaJmx");
    assertThat(configuration.statistics().jmxDomain()).isEqualTo("elaJmxDom2");
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) Configuration(org.infinispan.client.hotrod.configuration.Configuration) InfinispanRemoteAutoConfiguration(org.infinispan.spring.starter.remote.InfinispanRemoteAutoConfiguration) InfinispanRemoteCacheManagerAutoConfiguration(org.infinispan.spring.starter.remote.InfinispanRemoteCacheManagerAutoConfiguration) ClusterConfiguration(org.infinispan.client.hotrod.configuration.ClusterConfiguration) PasswordCallback(javax.security.auth.callback.PasswordCallback) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) ClusterConfiguration(org.infinispan.client.hotrod.configuration.ClusterConfiguration) RealmCallback(javax.security.sasl.RealmCallback) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with BasicCallbackHandler

use of org.infinispan.client.hotrod.security.BasicCallbackHandler in project infinispan by infinispan.

the class ConfigurationTest method testNoTransactionOverwrite.

public void testNoTransactionOverwrite() {
    ConfigurationBuilder builder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
    builder.remoteCache("tx-cache").transactionMode(TransactionMode.FULL_XA).transactionManagerLookup(RemoteTransactionManagerLookup.getInstance());
    builder.transactionTimeout(1234, TimeUnit.MILLISECONDS);
    Properties p = new Properties();
    p.setProperty(SERVER_LIST, "host1:11222; host2:11222");
    p.setProperty(AUTH_USERNAME, "admin");
    p.setProperty(AUTH_PASSWORD, "password");
    p.setProperty(AUTH_REALM, "default");
    p.setProperty(SASL_MECHANISM, "SCRAM-SHA-512");
    builder.withProperties(p);
    Configuration config = builder.build();
    assertEquals(TransactionMode.FULL_XA, config.remoteCaches().get("tx-cache").transactionMode());
    assertEquals(RemoteTransactionManagerLookup.getInstance(), config.remoteCaches().get("tx-cache").transactionManagerLookup());
    assertEquals(1234, config.transactionTimeout());
    assertEquals(2, config.servers().size());
    assertServer("host1", 11222, config.servers().get(0));
    assertServer("host2", 11222, config.servers().get(1));
    assertEquals("SCRAM-SHA-512", config.security().authentication().saslMechanism());
    CallbackHandler ch = config.security().authentication().callbackHandler();
    assertEquals(BasicCallbackHandler.class, ch.getClass());
    BasicCallbackHandler bch = (BasicCallbackHandler) ch;
    assertEquals("admin", bch.getUsername());
    assertArrayEquals("password".toCharArray(), bch.getPassword());
    assertEquals("default", bch.getRealm());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) Properties(java.util.Properties) ConfigurationProperties(org.infinispan.client.hotrod.impl.ConfigurationProperties)

Example 4 with BasicCallbackHandler

use of org.infinispan.client.hotrod.security.BasicCallbackHandler in project infinispan by infinispan.

the class ConfigurationTest method testConfigurationViaURI.

public void testConfigurationViaURI() {
    Configuration configuration = HotRodURI.create("hotrod://host1").toConfigurationBuilder().build();
    assertEquals(1, configuration.servers().size());
    assertFalse(configuration.security().ssl().enabled());
    assertFalse(configuration.security().authentication().enabled());
    configuration = HotRodURI.create("hotrod://host1?socket_timeout=5000&connect_timeout=1000").toConfigurationBuilder().build();
    assertEquals(1, configuration.servers().size());
    assertFalse(configuration.security().ssl().enabled());
    assertFalse(configuration.security().authentication().enabled());
    assertEquals(5000, configuration.socketTimeout());
    assertEquals(1000, configuration.connectionTimeout());
    configuration = HotRodURI.create("hotrod://host2:11322").toConfigurationBuilder().build();
    assertEquals(1, configuration.servers().size());
    assertEquals("host2", configuration.servers().get(0).host());
    assertEquals(11322, configuration.servers().get(0).port());
    assertFalse(configuration.security().ssl().enabled());
    assertFalse(configuration.security().authentication().enabled());
    configuration = HotRodURI.create("hotrod://user:password@host1:11222").toConfigurationBuilder().build();
    assertEquals(1, configuration.servers().size());
    assertFalse(configuration.security().ssl().enabled());
    assertTrue(configuration.security().authentication().enabled());
    BasicCallbackHandler callbackHandler = (BasicCallbackHandler) configuration.security().authentication().callbackHandler();
    assertEquals("user", callbackHandler.getUsername());
    assertArrayEquals("password".toCharArray(), callbackHandler.getPassword());
    configuration = HotRodURI.create("hotrod://host1:11222,host2:11322,host3").toConfigurationBuilder().build();
    assertEquals(3, configuration.servers().size());
    assertEquals("host1", configuration.servers().get(0).host());
    assertEquals(11222, configuration.servers().get(0).port());
    assertEquals("host2", configuration.servers().get(1).host());
    assertEquals(11322, configuration.servers().get(1).port());
    assertEquals("host3", configuration.servers().get(2).host());
    assertEquals(11222, configuration.servers().get(2).port());
    assertFalse(configuration.security().ssl().enabled());
    configuration = HotRodURI.create("hotrods://user:password@host1:11222,host2:11322?trust_store_path=cert.pem").toConfigurationBuilder().build();
    assertEquals(2, configuration.servers().size());
    assertEquals("host1", configuration.servers().get(0).host());
    assertEquals(11222, configuration.servers().get(0).port());
    assertEquals("host2", configuration.servers().get(1).host());
    assertEquals(11322, configuration.servers().get(1).port());
    assertTrue(configuration.security().ssl().enabled());
    assertTrue(configuration.security().authentication().enabled());
    callbackHandler = (BasicCallbackHandler) configuration.security().authentication().callbackHandler();
    assertEquals("user", callbackHandler.getUsername());
    assertArrayEquals("password".toCharArray(), callbackHandler.getPassword());
    expectException(IllegalArgumentException.class, "ISPN004095:.*", () -> HotRodURI.create("http://host1"));
    expectException(IllegalArgumentException.class, "ISPN004096:.*", () -> HotRodURI.create("hotrod://host1?property"));
}
Also used : BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler)

Example 5 with BasicCallbackHandler

use of org.infinispan.client.hotrod.security.BasicCallbackHandler in project infinispan by infinispan.

the class Common method createSubject.

public static Subject createSubject(String principal, String realm, char[] password) {
    return Exceptions.unchecked(() -> {
        LoginContext context = new LoginContext("KDC", null, new BasicCallbackHandler(principal, realm, password), createJaasConfiguration(false));
        context.login();
        return context.getSubject();
    });
}
Also used : LoginContext(javax.security.auth.login.LoginContext) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler)

Aggregations

BasicCallbackHandler (org.infinispan.client.hotrod.security.BasicCallbackHandler)6 CallbackHandler (javax.security.auth.callback.CallbackHandler)2 NameCallback (javax.security.auth.callback.NameCallback)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 RealmCallback (javax.security.sasl.RealmCallback)2 ClusterConfiguration (org.infinispan.client.hotrod.configuration.ClusterConfiguration)2 Configuration (org.infinispan.client.hotrod.configuration.Configuration)2 InfinispanRemoteAutoConfiguration (org.infinispan.spring.starter.remote.InfinispanRemoteAutoConfiguration)2 InfinispanRemoteCacheManagerAutoConfiguration (org.infinispan.spring.starter.remote.InfinispanRemoteCacheManagerAutoConfiguration)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Properties (java.util.Properties)1 LoginContext (javax.security.auth.login.LoginContext)1 ConfigurationProperties (org.infinispan.client.hotrod.impl.ConfigurationProperties)1 TokenCallbackHandler (org.infinispan.client.hotrod.security.TokenCallbackHandler)1 VoidCallbackHandler (org.infinispan.client.hotrod.security.VoidCallbackHandler)1