-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from gjhuai/master
修复issues#84
- Loading branch information
Showing
2 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/org/crazycake/shiro/serializer/MultiClassLoaderObjectInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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; | ||
|
||
public class MultiClassLoaderObjectInputStream extends ObjectInputStream { | ||
private static Logger log = LoggerFactory.getLogger(MultiClassLoaderObjectInputStream.class); | ||
|
||
MultiClassLoaderObjectInputStream(InputStream str) throws IOException { | ||
super(str); | ||
} | ||
|
||
@Override | ||
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { | ||
String name = desc.getName(); | ||
//log.debug("resolveClass:"+name); | ||
|
||
try { | ||
ClassLoader cl = Thread.currentThread().getContextClassLoader(); | ||
return Class.forName(name, false, cl); | ||
} catch (Throwable ex) { | ||
log.debug(ex.getMessage()); | ||
// Cannot access thread context ClassLoader - falling back... | ||
} | ||
|
||
try { | ||
// No thread context class loader -> use class loader of this class. | ||
ClassLoader cl = MultiClassLoaderObjectInputStream.class.getClassLoader(); | ||
return Class.forName(name, false, cl); | ||
} catch (Throwable ex) { | ||
log.debug(ex.getMessage()); | ||
// Cannot access thread context ClassLoader - falling back... | ||
} | ||
|
||
// getClassLoader() returning null indicates the bootstrap ClassLoader | ||
try { | ||
ClassLoader cl = ClassLoader.getSystemClassLoader(); | ||
return Class.forName(name, false, cl); | ||
} catch (Throwable ex) { | ||
log.debug(ex.getMessage()); | ||
// Cannot access system ClassLoader - oh well, maybe the caller can live with null... | ||
} | ||
|
||
return super.resolveClass(desc); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters