Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

java.lang.ClassNotFoundException: org.springframework.security.core.context.SecurityContextImpl #1

Closed
songyunlu opened this issue Sep 13, 2013 · 6 comments

Comments

@songyunlu
Copy link

Hi:

I have added AmazonDynamoDBSessionManagerForTomcat-1.0.0.jar to the lib directory of my Tomcat installation and tried to store session in DynamoDB. Howerver when DynamoDBSessionManager tries to load sessions from dynamodb, it throws java.lang.ClassNotFoundException:org.springframework.security.core.context.SecurityContextImpl.

Since I use Spring Security for authentication stuff. It seems that the session manager cannot deserialize the session value to the SecurityContextImpl because it cannot find the classes.

I have tried to add the dependencies (Spring Security) to the lib directory of the Tomcat installation, but in the end, I got the same exception with classes of my domain object.

Should I put all classes of my domain object into the lib directory? or Is there any intuitive way to solve this problem? thx.

@spgmx
Copy link

spgmx commented Nov 16, 2013

It's a bug in the DynamoDBSessionStore. It uses the current classloader to load the classes. But the current loader is the shared loader from tomcat and not that from the webapp.
org.apache.catalina.util.CustomObjectInputStream will do the trick.

@fulghum
Copy link
Contributor

fulghum commented Nov 20, 2013

Yup, spgmx is correct. We're working on the fix and hope to have something out soon.

@fulghum
Copy link
Contributor

fulghum commented Nov 21, 2013

Good news... the latest release and source code resolves the issue around using the incorrect class loader during deserialization. I have a hunch that it will resolve this issue as well, but definitely let us know if you're still seeing problems after picking up the latest release.

You can grab the jar from GitHub; just make sure to pull the old version out of Tomcat's lib dir. We'll get the Eclipse plugin updated with the latest release soon, too.

@spgmx
Copy link

spgmx commented Dec 12, 2013

Works now! ;)

@jdahlbom
Copy link

Please update the version in pom.xml, now the fixed version is the same 1.0.0 as before.

@wyangnz
Copy link

wyangnz commented Feb 5, 2015

Hi fulghum,
We have Liferay 6.1 CE with Tomcat bundle runs on AWS EC2. The DBSessionManager does not work. It shows "java.lang.ClassNotFoundException: com.liferay.portal.servlet.PortalSessionActivationListener" and other classes in liferay. In the Liferay/Tomcat bundle, the Liferay portal is under [tomcat-home]/webapps/ROOT and there is file [tomcat-home]/conf/Catalina/localhost/ROOT.xml which is almost empty. It appears the classLoader for the webapp cannot load class in webapps/ROOT/ path.
I made small changes on DynamoDBSessionStore as follows, it works but I am not sure if there is a better solution.

    CustomObjectInputStream objectInputStream = null;
    ObjectInputStream objectInputStream2 = null;
    try {
        Container webapp = getManager().getContainer();
        objectInputStream = new CustomObjectInputStream(inputStream, webapp.getLoader().getClassLoader());
        readObject = objectInputStream.readObject();
    }    catch(java.lang.ClassNotFoundException e) { 
        objectInputStream2 = new ObjectInputStream(inputStream);
        readObject = objectInputStream2.readObject();
    } finally {
        try { 
            if(objectInputStream != null) {
                objectInputStream.close(); 
            } 
            if (objectInputStream2 != null){
                objectInputStream2.close();
            }
        }catch (Exception e){}
    }

Thanks in advance for any suggestion.

Weimin

shorea pushed a commit that referenced this issue Mar 11, 2015
Migrated to Java7 & Tomcat8
@shorea shorea closed this as completed Mar 31, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants