All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.crazycake.shiro.serializer.MultiClassLoaderObjectInputStream Maven / Gradle / Ivy

Go to download

shiro only provide the support of ehcache and concurrentHashMap. Here is an implement of redis cache can be used by shiro. Hope it will help you!

The newest version!
package org.crazycake.shiro.serializer;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * For fixing https://github.com/alexxiyang/shiro-redis/issues/84
 */
public class MultiClassLoaderObjectInputStream extends ObjectInputStream {
	private static Logger logger = LoggerFactory.getLogger(MultiClassLoaderObjectInputStream.class);
	
	MultiClassLoaderObjectInputStream(InputStream str) throws IOException {
		super(str);
	}

	@Override
	protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
        String name = desc.getName();

		try {
			ClassLoader cl = Thread.currentThread().getContextClassLoader();
			return Class.forName(name, false, cl);
		} catch (Throwable ex) {
			logger.debug("Cannot access thread context ClassLoader!", ex);
		}
		
		try {
			ClassLoader cl = MultiClassLoaderObjectInputStream.class.getClassLoader();
			return Class.forName(name, false, cl);
		} catch (Throwable ex) {
			logger.debug("Cannot access application ClassLoader", ex);
		}
		
		try {
			ClassLoader cl = ClassLoader.getSystemClassLoader();
			return Class.forName(name, false, cl);
		} catch (Throwable ex) {
			logger.debug("Cannot access system ClassLoader", ex);
		}

        return super.resolveClass(desc);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy