Search in sources :

Example 1 with TestExternalizableDeserialized

use of example.serialization.TestExternalizableDeserialized in project hazelcast by hazelcast.

the class ExternalizableDeserializationProtectionTest method testExternalizableProtectedOnMember.

@Test
public void testExternalizableProtectedOnMember() {
    JavaSerializationFilterConfig javaSerializationFilterConfig = new JavaSerializationFilterConfig().setDefaultsDisabled(true);
    javaSerializationFilterConfig.getBlacklist().addClasses(TestExternalizableDeserialized.class.getName());
    Config config = smallInstanceConfig();
    config.getSerializationConfig().setJavaSerializationFilterConfig(javaSerializationFilterConfig);
    // the index will force deserialization
    config.getMapConfig("test").addIndexConfig(new IndexConfig(IndexType.HASH, "name"));
    hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    expected.expect(HazelcastSerializationException.class);
    client.getMap("test").put("key", new TestExternalizableDeserialized());
}
Also used : TestExternalizableDeserialized(example.serialization.TestExternalizableDeserialized) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with TestExternalizableDeserialized

use of example.serialization.TestExternalizableDeserialized in project hazelcast by hazelcast.

the class ExternalizableDeserializationProtectionTest method testExternalizableUnprotected.

@Test
public void testExternalizableUnprotected() {
    Config config = smallInstanceConfig();
    config.getMapConfig("test").addIndexConfig(new IndexConfig(IndexType.HASH, "name"));
    hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    client.getMap("test").put("key", new TestExternalizableDeserialized());
    assertTrue(TestExternalizableDeserialized.isDeserialized);
    TestExternalizableDeserialized.isDeserialized = false;
    client.getMap("test").get("key");
    assertTrue(TestExternalizableDeserialized.isDeserialized);
}
Also used : TestExternalizableDeserialized(example.serialization.TestExternalizableDeserialized) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with TestExternalizableDeserialized

use of example.serialization.TestExternalizableDeserialized in project hazelcast by hazelcast.

the class ExternalizableDeserializationProtectionTest method testExternalizableProtectedOnClient.

@Test
public void testExternalizableProtectedOnClient() {
    JavaSerializationFilterConfig javaSerializationFilterConfig = new JavaSerializationFilterConfig().setDefaultsDisabled(true);
    javaSerializationFilterConfig.getBlacklist().addClasses(TestExternalizableDeserialized.class.getName());
    Config config = smallInstanceConfig();
    hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig1 = new ClientConfig();
    HazelcastInstance client1 = hazelcastFactory.newHazelcastClient(clientConfig1);
    client1.getMap("test").put("key", new TestExternalizableDeserialized());
    // we don't have an index on map, so the value should not be deserialized
    assertFalse(TestExternalizableDeserialized.isDeserialized);
    // deserialized on client
    client1.getMap("test").get("key");
    assertTrue(TestExternalizableDeserialized.isDeserialized);
    TestExternalizableDeserialized.isDeserialized = false;
    ClientConfig clientConfig2 = new ClientConfig();
    clientConfig2.getSerializationConfig().setJavaSerializationFilterConfig(javaSerializationFilterConfig);
    HazelcastInstance client2 = hazelcastFactory.newHazelcastClient(clientConfig2);
    expected.expect(HazelcastSerializationException.class);
    client2.getMap("test").get("key");
}
Also used : TestExternalizableDeserialized(example.serialization.TestExternalizableDeserialized) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)3 Config (com.hazelcast.config.Config)3 IndexConfig (com.hazelcast.config.IndexConfig)3 JavaSerializationFilterConfig (com.hazelcast.config.JavaSerializationFilterConfig)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 TestExternalizableDeserialized (example.serialization.TestExternalizableDeserialized)3 Test (org.junit.Test)3