You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shiro.apache.org by "Lenny Primak (Created) (JIRA)" <ji...@apache.org> on 2011/12/14 18:33:30 UTC
[jira] [Created] (SHIRO-334) DefaultSerializer does not load
classes from the ContextClassLoader, causing RememberMe to not work
DefaultSerializer does not load classes from the ContextClassLoader, causing RememberMe to not work
---------------------------------------------------------------------------------------------------
Key: SHIRO-334
URL: https://issues.apache.org/jira/browse/SHIRO-334
Project: Shiro
Issue Type: Bug
Components: Authentication (log-in)
Affects Versions: 1.1.0, 1.2.0, 1.3.0, 2.0.0
Environment: JEE Server (Glassfish) where Shiro JAR files are not in the same ClassLoader as the Application JARs
Reporter: Lenny Primak
RememberMe functionality does not work because Shiro is in a different class loader than the RememberMe serializable class,
The only thing that needs to change is the resolveClass() function,
and it should use Thread.currentThread().getContextClassLoader().loadClass() to load the class,
as that works in all cases and all class loader configurations.
I fixed this in my code by overriding DefaultSerializer, but this should be the default behavior:
private static class Serialize<T> extends DefaultSerializer<T>
{
@Override
public T deserialize(byte[] serialized) throws SerializationException
{
if (serialized == null)
{
String msg = "argument cannot be null.";
throw new IllegalArgumentException(msg);
}
ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
BufferedInputStream bis = new BufferedInputStream(bais);
try
{
ObjectInputStream ois = new ObjectInputStream(bis)
{
@Override
public Class resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
{
// ************ THIS IS THE LINE THAT WAS CHANGED ********************
return Thread.currentThread().getContextClassLoader().loadClass(desc.getName());
}
};
@SuppressWarnings({"unchecked"})
T deserialized = (T) ois.readObject();
ois.close();
return deserialized;
} catch (Exception e)
{
String msg = "Unable to deserialze argument byte array.";
throw new SerializationException(msg, e);
}
}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (SHIRO-334) DefaultSerializer does not load
classes from the ContextClassLoader, causing RememberMe to not work
Posted by "Les Hazlewood (Resolved) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SHIRO-334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Les Hazlewood resolved SHIRO-334.
---------------------------------
Resolution: Fixed
Fix Version/s: 1.2.0
Assignee: Les Hazlewood
Resolved in trunk, rev. 1214564.
Created a new ClassResolvingObjectInputStream: http://svn.apache.org/repos/asf/shiro/trunk/core/src/main/java/org/apache/shiro/io/ClassResolvingObjectInputStream.java
And changed the DefaultSerializer implementation (line 75) to use it instead of ObjectInputStream.
Please re-open if there are any issues with the committed solution.
> DefaultSerializer does not load classes from the ContextClassLoader, causing RememberMe to not work
> ---------------------------------------------------------------------------------------------------
>
> Key: SHIRO-334
> URL: https://issues.apache.org/jira/browse/SHIRO-334
> Project: Shiro
> Issue Type: Bug
> Components: Authentication (log-in)
> Affects Versions: 1.1.0, 1.2.0, 1.3.0, 2.0.0
> Environment: JEE Server (Glassfish) where Shiro JAR files are not in the same ClassLoader as the Application JARs
> Reporter: Lenny Primak
> Assignee: Les Hazlewood
> Fix For: 1.2.0
>
>
> RememberMe functionality does not work because Shiro is in a different class loader than the RememberMe serializable class,
> The only thing that needs to change is the resolveClass() function,
> and it should use Thread.currentThread().getContextClassLoader().loadClass() to load the class,
> as that works in all cases and all class loader configurations.
> I fixed this in my code by overriding DefaultSerializer, but this should be the default behavior:
> private static class Serialize<T> extends DefaultSerializer<T>
> {
> @Override
> public T deserialize(byte[] serialized) throws SerializationException
> {
> if (serialized == null)
> {
> String msg = "argument cannot be null.";
> throw new IllegalArgumentException(msg);
> }
> ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
> BufferedInputStream bis = new BufferedInputStream(bais);
> try
> {
> ObjectInputStream ois = new ObjectInputStream(bis)
> {
> @Override
> public Class resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
> {
> // ************ THIS IS THE LINE THAT WAS CHANGED ********************
> return Thread.currentThread().getContextClassLoader().loadClass(desc.getName());
> }
> };
> @SuppressWarnings({"unchecked"})
> T deserialized = (T) ois.readObject();
> ois.close();
> return deserialized;
> } catch (Exception e)
> {
> String msg = "Unable to deserialze argument byte array.";
> throw new SerializationException(msg, e);
> }
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Closed] (SHIRO-334) DefaultSerializer does not load classes
from the ContextClassLoader, causing RememberMe to not work
Posted by "Les Hazlewood (Closed) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SHIRO-334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Les Hazlewood closed SHIRO-334.
-------------------------------
Closing with the 1.2.0 release.
> DefaultSerializer does not load classes from the ContextClassLoader, causing RememberMe to not work
> ---------------------------------------------------------------------------------------------------
>
> Key: SHIRO-334
> URL: https://issues.apache.org/jira/browse/SHIRO-334
> Project: Shiro
> Issue Type: Bug
> Components: Authentication (log-in)
> Affects Versions: 1.1.0, 1.2.0, 1.3.0, 2.0.0
> Environment: JEE Server (Glassfish) where Shiro JAR files are not in the same ClassLoader as the Application JARs
> Reporter: Lenny Primak
> Assignee: Les Hazlewood
> Fix For: 1.2.0
>
>
> RememberMe functionality does not work because Shiro is in a different class loader than the RememberMe serializable class,
> The only thing that needs to change is the resolveClass() function,
> and it should use Thread.currentThread().getContextClassLoader().loadClass() to load the class,
> as that works in all cases and all class loader configurations.
> I fixed this in my code by overriding DefaultSerializer, but this should be the default behavior:
> private static class Serialize<T> extends DefaultSerializer<T>
> {
> @Override
> public T deserialize(byte[] serialized) throws SerializationException
> {
> if (serialized == null)
> {
> String msg = "argument cannot be null.";
> throw new IllegalArgumentException(msg);
> }
> ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
> BufferedInputStream bis = new BufferedInputStream(bais);
> try
> {
> ObjectInputStream ois = new ObjectInputStream(bis)
> {
> @Override
> public Class resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
> {
> // ************ THIS IS THE LINE THAT WAS CHANGED ********************
> return Thread.currentThread().getContextClassLoader().loadClass(desc.getName());
> }
> };
> @SuppressWarnings({"unchecked"})
> T deserialized = (T) ois.readObject();
> ois.close();
> return deserialized;
> } catch (Exception e)
> {
> String msg = "Unable to deserialze argument byte array.";
> throw new SerializationException(msg, e);
> }
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira