You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@shiro.apache.org by "steinarb (via GitHub)" <gi...@apache.org> on 2024/05/26 08:29:06 UTC

[I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

steinarb opened a new issue, #1500:
URL: https://github.com/apache/shiro/issues/1500

   ### Search before asking
   
   - [X] I had searched in the [issues](https://github.com/apache/shiro/issues?q=is%3Aissue) and found no similar issues.
   
   
   ### Environment
   
   OpenJDK Java 17, debian 12.5 "bookworm", amd64, apache karaf 4.4.5 (running on apache felix)
   
   ### Shiro version
   
   SNAPSHOT built from shiro main between 2.0.0 and 2.0.1 (to get the fix for https://github.com/apache/shiro/issues/1383 )
   
   ### What was the actual outcome?
   
   I get the following stack trace for all Shiro filters:
    https://gist.github.com/steinarb/faa44f384b330ae0259cc051036885db
   
   The error message is:
    ```
    org.apache.shiro.config.ConfigurationException: Unable to instantiate class [org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter] for object named 'authc'.  Please ensure you've specified the fully qualified class name correctly.
    ```
   
   This is the code parsing the INI file:
    https://github.com/steinarb/oldalbum/blob/master/oldalbum.web.security/src/main/java/no/priv/bang/oldalbum/web/security/OldAlbumShiroFilter.java#L42
   
   This is the INI file being parsed:
    https://github.com/steinarb/oldalbum/blob/master/oldalbum.web.security/src/main/resources/shiro.ini
   
   This being OSGi, I suspected a classloader issue.
   
   Shiro tries several classloaders:
    https://github.com/apache/shiro/blob/main/lang/src/main/java/org/apache/shiro/lang/util/ClassUtils.java#L153
   
   The classloaders tried, are:
    1. Thread.currentThread().getContextClassLoader()
    2. ClassUtils.class.getClassLoader()
    3. ClassLoader.getSystemClassLoader()
   
   Alternative 1. probably won't work since OSGi doesn't define context class loader behaviour and the context class loader may be null
   
   Alternative 2, could have worked if the shiro-lang bundle had imported package org.apache.shiro.web.filter.authc (which it doesn't)
   
   Alternative 3 won't find anything in OSGi.
   
   
   ### What was the expected outcome?
   
   That the shiro.ini file had been parsed without error and the shiro filter had been started normally (it worked with shiro 1.13)
   
   ### How to reproduce
   
   I haven't pushed my shiro 2.x changes yet.
   
   I'm waiting for shiro 2.0.1 to be released (shiro 2.0.0 will fail in a different part of the build because of https://github.com/apache/shiro/issues/1383 )
   
   ### Debug logs
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2153335740

   Have you tried setting ContextClassLoader before calling INI functionality?  I haven’t tried just a thought. That could alleviate need to change APi
   
   simple reproducer would also be helpful as I am unfamiliar with Karaf


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak closed issue #1500: [Bug] Apache 2.x INI parser can't find classes when running under OSGi
URL: https://github.com/apache/shiro/issues/1500


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2156368988

   @lprimak I tried it now and it worked. So I guess this bug can be closed.
   
   Here is what I did: https://github.com/steinarb/sampleapp/tree/set-threadcontextclassloader-before-ini-parse
   
   1. Revert the workaround https://github.com/steinarb/sampleapp/commit/8e0ff8622c61dfbf9e30b52050d9c5ca9af048cc
   2. Do an explicit import of the package containing PassThruAuthenticationFilter https://github.com/steinarb/sampleapp/commit/fe59167817b7754f9ba5d5a77a3c8d26efce5651
   3. Set the thread context class loader to the class loader of the class calling the parser https://github.com/steinarb/sampleapp/commit/facbe3215e97d62a4a20078d991c9aa4f1c86f3c


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "fpapon (via GitHub)" <gi...@apache.org>.
fpapon commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2151830077

   Hi @steinarb,
   I think the OSGi part of the ini has to be use differently. We cannot know in advance where the class defined in the ini file come from. Just the ones from Shiro but user can create his own.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2155847996

   @fpapon Since instantiating this class when parsing the INI is a regression from 1.13.0 (it worked there) and since OSGi needs all the help it can get, I still think this should be fixed. :smile: 
   
   (also I think that being able to pass a classloader as a parameter to code actively using a classloader, is probably a good design decision in any case)
   
   At the same time, since this had a 1-line workaround https://github.com/apache/shiro/issues/1500#issuecomment-2151577796 it is not something I feel strongly about. :smile: 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2151577796

   I found a workaround that let me use shiro 2.0.1: 
   
   1. remove "authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" from the INI file
   2. before parsing the ini file, create a PassThruAuthenticationFilter instance an put it into the map IniWebEnvironment.getObjects() with key "authc"
   
   https://github.com/steinarb/authservice/commit/1d49451e53251f6ac42024aebdb891a56283a97d
   
   This works, but I see it as a workaround.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2155845898

   @lprimak Re: context class loader: I tried two ways of ensuring that the package containing org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter was available to the code calling the parser:
   
   1. Explicit import of package org.apache.shiro.web.filter.authc in the maven-bundle-plugin config
   2. Instantiating org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter in the class calling the parser (which, looking at the MANIFEST.MF, had the same effect as the first attempt)
   
   Neither of them worked wrt. to the parser instantiating the class, and looking at https://stackoverflow.com/a/23186987 it is not surprising, because if that stack overflow answer is to be believed, in OSGi the ContextClassLoader is undefined and may be null.
   
   re: simple test case/repro: I will see what I can do


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2156191414

   Have you tried setting context class loader? i.e. `Thread.currentThread().setContextClassLoader(MyClass.class.getClassLoader())`
   before calling the INI parser?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2152905549

   @fpapon Well if you have the possibility of alternative 2 above, i.e. send in the classloader of the class calling the INI parser as a parameter, then the person using the parser have the possibility of making the class available by ensuring that the bundle the INI is parsed in, imports the required packages.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2151558867

   Offhand I see two ways that would work:
   
   1. Import all the packages that the INI parser might want to instantiate classes from into
   2. Make it possible for the class using the INI parser to send its own classloader to the INI parser
   
   Downside of alternative1 is potentially introducing some undesirable dependencies to shiro-lang (mostly theoretical when using resolution=optional)
   
   Upside of alternative 1 is that no API changes have to be made.
   
   Upside of alternative 2 is that I'm pretty sure it will work (or at least: can be made to work, always, by the API user, by adjusting the imports of the bundle of the class calling the parser)
   
   Downside of alternative 2 is that the user of the API have to be aware of all packages that need to be imported


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "fpapon (via GitHub)" <gi...@apache.org>.
fpapon commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2153329974

   I think using INI in OSGi env is not a good thing, the best will be to configure Shiro programmatically.
   
   Side notes: I know that Nexus 3 OSS used Apache Karaf and Shiro, may be you can take a look to see how they managed the configuration https://github.com/sonatype/nexus-public/tree/main/components/nexus-security


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org


Re: [I] [Bug] Apache 2.x INI parser can't find classes when running under OSGi [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on issue #1500:
URL: https://github.com/apache/shiro/issues/1500#issuecomment-2156742639

   Awesome, closing


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@shiro.apache.org
For additional commands, e-mail: issues-help@shiro.apache.org