Search in sources :

Example 1 with ClassAllowList

use of org.infinispan.commons.configuration.ClassAllowList in project infinispan by infinispan.

the class JavaSerializationTranscoderTest method setUp.

@BeforeClass(alwaysRun = true)
public void setUp() {
    dataSrc = new Person("Joe");
    Address address = new Address();
    address.setCity("London");
    dataSrc.setAddress(address);
    transcoder = new JavaSerializationTranscoder(new ClassAllowList(Collections.singletonList(".*")));
    supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
Also used : Address(org.infinispan.test.data.Address) JavaSerializationTranscoder(org.infinispan.encoding.impl.JavaSerializationTranscoder) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) Person(org.infinispan.test.data.Person) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ClassAllowList

use of org.infinispan.commons.configuration.ClassAllowList in project infinispan by infinispan.

the class JbossMarshallingModule method cacheManagerStarting.

@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
    PERSISTENCE.jbossMarshallingDetected();
    Marshaller userMarshaller = globalConfiguration.serialization().marshaller();
    if (userMarshaller instanceof JBossUserMarshaller) {
        // Core automatically registers a transcoder for the user marshaller
        // Initialize the externalizers from the serialization configuration
        ((JBossUserMarshaller) userMarshaller).initialize(gcr);
    } else {
        // Register a JBoss Marshalling transcoder, ignoring any configured externalizers
        ClassAllowList classAllowList = gcr.getComponent(EmbeddedCacheManager.class).getClassAllowList();
        ClassLoader classLoader = globalConfiguration.classLoader();
        GenericJBossMarshaller jbossMarshaller = new GenericJBossMarshaller(classLoader, classAllowList);
        EncoderRegistry encoderRegistry = gcr.getComponent(EncoderRegistry.class);
        encoderRegistry.registerTranscoder(new JBossMarshallingTranscoder(jbossMarshaller));
    }
}
Also used : GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) JBossUserMarshaller(org.infinispan.jboss.marshalling.core.JBossUserMarshaller) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) JBossMarshallingTranscoder(org.infinispan.jboss.marshalling.dataconversion.JBossMarshallingTranscoder) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) JBossUserMarshaller(org.infinispan.jboss.marshalling.core.JBossUserMarshaller)

Example 3 with ClassAllowList

use of org.infinispan.commons.configuration.ClassAllowList in project infinispan by infinispan.

the class EncoderRegistryFactory method construct.

@Override
public Object construct(String componentName) {
    ClassLoader classLoader = globalConfiguration.classLoader();
    EncoderRegistryImpl encoderRegistry = new EncoderRegistryImpl();
    ClassAllowList classAllowList = embeddedCacheManager.getClassAllowList();
    encoderRegistry.registerEncoder(IdentityEncoder.INSTANCE);
    encoderRegistry.registerEncoder(UTF8Encoder.INSTANCE);
    encoderRegistry.registerEncoder(new JavaSerializationEncoder(classAllowList));
    encoderRegistry.registerEncoder(new GlobalMarshallerEncoder(globalMarshaller.wired()));
    // Default and binary transcoder use the user marshaller to convert data to/from a byte array
    encoderRegistry.registerTranscoder(new DefaultTranscoder(userMarshaller));
    encoderRegistry.registerTranscoder(new BinaryTranscoder(userMarshaller));
    // Core transcoders are always available
    encoderRegistry.registerTranscoder(new ProtostreamTranscoder(ctxRegistry, classLoader));
    encoderRegistry.registerTranscoder(new JavaSerializationTranscoder(classAllowList));
    // Wraps the GlobalMarshaller so that it can be used as a transcoder
    // Keeps application/x-infinispan-marshalling available for backwards compatibility
    encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(globalMarshaller.wired()));
    // Make the user marshaller's media type available as well
    // As custom marshaller modules like Kryo and Protostuff do not define their own transcoder
    encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(userMarshaller));
    encoderRegistry.registerWrapper(ByteArrayWrapper.INSTANCE);
    encoderRegistry.registerWrapper(IdentityWrapper.INSTANCE);
    return encoderRegistry;
}
Also used : EncoderRegistryImpl(org.infinispan.marshall.core.EncoderRegistryImpl) DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) TranscoderMarshallerAdapter(org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) BinaryTranscoder(org.infinispan.commons.dataconversion.BinaryTranscoder) JavaSerializationTranscoder(org.infinispan.encoding.impl.JavaSerializationTranscoder) ProtostreamTranscoder(org.infinispan.encoding.ProtostreamTranscoder) GlobalMarshallerEncoder(org.infinispan.commons.dataconversion.GlobalMarshallerEncoder) JavaSerializationEncoder(org.infinispan.commons.dataconversion.JavaSerializationEncoder)

Example 4 with ClassAllowList

use of org.infinispan.commons.configuration.ClassAllowList in project infinispan by infinispan.

the class PersistenceMockUtil method mockCache.

private static Cache mockCache(String nodeName, Configuration configuration, TimeService timeService, ClassAllowList allowList, ScheduledExecutorService timeoutScheduledExecutor) {
    String cacheName = "mock-cache";
    AdvancedCache cache = mock(AdvancedCache.class, RETURNS_DEEP_STUBS);
    GlobalConfiguration gc = new GlobalConfigurationBuilder().transport().nodeName(nodeName).build();
    Set<String> cachesSet = new HashSet<>();
    EmbeddedCacheManager cm = mock(EmbeddedCacheManager.class);
    when(cm.getCacheManagerConfiguration()).thenReturn(gc);
    when(cm.getClassAllowList()).thenReturn(new ClassAllowList());
    GlobalComponentRegistry gcr = new GlobalComponentRegistry(gc, cm, cachesSet, TestModuleRepository.defaultModuleRepository(), mock(ConfigurationManager.class));
    BasicComponentRegistry gbcr = gcr.getComponent(BasicComponentRegistry.class);
    gbcr.replaceComponent(TimeService.class.getName(), timeService, true);
    gbcr.replaceComponent(KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR, timeoutScheduledExecutor, false);
    ComponentRegistry registry = new ComponentRegistry(cacheName, configuration, cache, gcr, configuration.getClass().getClassLoader());
    when(cache.getCacheManager().getGlobalComponentRegistry()).thenReturn(gcr);
    when(cache.getClassLoader()).thenReturn(PersistenceMockUtil.class.getClassLoader());
    when(cache.getCacheManager().getCacheManagerConfiguration()).thenReturn(gc);
    when(cache.getCacheManager().getClassAllowList()).thenReturn(allowList);
    when(cache.getName()).thenReturn(cacheName);
    when(cache.getAdvancedCache()).thenReturn(cache);
    when(cache.getComponentRegistry()).thenReturn(registry);
    when(cache.getStatus()).thenReturn(ComponentStatus.RUNNING);
    when(cache.getCacheConfiguration()).thenReturn(configuration);
    return cache;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) TimeService(org.infinispan.commons.time.TimeService) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) AdvancedCache(org.infinispan.AdvancedCache) ConfigurationManager(org.infinispan.configuration.ConfigurationManager) HashSet(java.util.HashSet)

Example 5 with ClassAllowList

use of org.infinispan.commons.configuration.ClassAllowList in project infinispan by infinispan.

the class BinaryTranscoderTest method prepare.

@BeforeClass
public static void prepare() {
    final ClassAllowList allowList = new ClassAllowList();
    allowList.addRegexps(".*");
    marshaller = new JavaSerializationMarshaller(allowList);
    binaryTranscoder = new BinaryTranscoder(marshaller);
}
Also used : ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller) BeforeClass(org.junit.BeforeClass)

Aggregations

ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)10 JavaSerializationMarshaller (org.infinispan.commons.marshall.JavaSerializationMarshaller)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 JavaSerializationTranscoder (org.infinispan.encoding.impl.JavaSerializationTranscoder)2 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)2 SerializationContextRegistry (org.infinispan.marshall.protostream.impl.SerializationContextRegistry)2 Address (org.infinispan.test.data.Address)2 Person (org.infinispan.test.data.Person)2 BeforeClass (org.junit.BeforeClass)2 BeforeClass (org.testng.annotations.BeforeClass)2 HashSet (java.util.HashSet)1 AdvancedCache (org.infinispan.AdvancedCache)1 MarshallerRegistry (org.infinispan.client.hotrod.impl.MarshallerRegistry)1 BinaryTranscoder (org.infinispan.commons.dataconversion.BinaryTranscoder)1 DefaultTranscoder (org.infinispan.commons.dataconversion.DefaultTranscoder)1 GlobalMarshallerEncoder (org.infinispan.commons.dataconversion.GlobalMarshallerEncoder)1 JavaSerializationEncoder (org.infinispan.commons.dataconversion.JavaSerializationEncoder)1 Transcoder (org.infinispan.commons.dataconversion.Transcoder)1 TranscoderMarshallerAdapter (org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1