-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Bug] OSGi shiro unable to restore rememberme session #2083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The core of the problem is this:
The class ClassResolvingObjectInputStream is in the shiro-lang OSGi bundle (i.e. jar file with import-package and export-package declarations in the MANIFEST.MF). For a class to be loaded and, found by ClassResolvingObjectInputStream, the package the class resides (i.e. org.apache.shiro.subject for SimplePrincipalCollection) in needs to be imported into shiro-lang. And the package org.apache.shiro.subject (found in shiro-core) is not listed in the Import-Package declaration of the shiro-lang MANIFEST.MF (formatted for readability):
Below is the export-package of the MANIFEST.MF of shiro-core, also reformatted for readability, and I see one obvious problem: packages in shiro-core require packages from shiro-lang (which means shiro-lang can't import packages from shiro-core, because then you would have a loop). So this requires changes to shiro to fix. There are two ways of breaking the loop:
Export-package of the MANIFEST.MF of shiro-core, reformatted for readability:
|
Nope. It is an OSGi import problem, which #1449 also is, but very different in nature (different packages and different bundles involved). This issue is a class in shiro-lang not able to create an instance of a class in shiro-core (because shiro-lang doesn't import the package). And shiro-lang can't import the package from shiro-core because shiro-core imports a package from shiro-lang and introducing a cross dependency would make the bundles refuse to load. I tried splitting subject out into a separate bundle, but the classes in subject require a lot of packages in shiro-core (and two packages from shiro-lang):
Most troublesome are org.apache.shiro.lang because that means that the classes here and the classes in lang that wants to use them have a cross dependency (even if I were to split out all of the reset of the packages which are all in shiro-core). Short story: I don't know any way of fixing this other than moving shiro-lang back into shiro-core (which IMO would be the wrong thing to do). |
Hm... maybe setting thread context class loader to the thread of the class calling ClassResolvingObjectInputStream (like in #1500 (comment)) would be a workaround? But I don't know where the calling code is? Maybe in shiro-core somewhere? Actually, the more I think about it, this issue is more similar to #1500 than #1449 because this is a case of reflection not being able to load a class by name. And as I recall, there was code in Shiro trying several classloaders, and the thread context class loader was one of them? (my suggestion was to send a classloader in as a parameter, but setting the classloader as suggested by @lprimak worked). #1449 is different because that means the OSGi bundle doesn't start up because all of its manifest imports can't be resolved (not missing classes during reflection, but problems with OSGi). I have no idea why that hasn't bitten me as well? Ah: I'm not using annotations from either javax.annotation.security or jakarta.annotation.security. I define access to paths in shiro.ini. |
@fpapon Possibly another OSGi / Karaf issue |
…g can find classes in shiro-core to fix apache#2083
I have made a one-liner fix: #2084 I have tested it by rebuilding all apps in myapps-test with shiro 2.0.0-SNAPSHOT with my fix and the stack trace on restoring serialized remember me went away. The fix is the same as I used as a workaround here: #1500 (comment) |
A good practice when switching the TCCL, is to:
|
That's exactly what I did in #2085 |
Also, thank you for your continued involvement Steinar, this is very helpful! |
Check! Not much experience with TCCL #1500 (comment) was the first time I encountered the concept. |
It's a common trick in OSGi world :) |
Search before asking
Environment
Apache karaf 4.4.7, Java 21.0.4+8-LTS-274, debian 12.10 "bookworm", amd64
Shiro version
Shiro 2.0.2
What was the actual outcome?
When restoring rememberme sessions I get the following stack traces in the log:
What was the expected outcome?
No errors on rememberme restore.
How to reproduce
Run an application that uses shiro rememberme shiro on an OSGi platform
Debug logs
No response
The text was updated successfully, but these errors were encountered: