[
https://issues.apache.org/jira/browse/SHIRO-537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16697763#comment-16697763
]
Steinar Bang commented on SHIRO-537:
------------------------------------
I encountered this issue when trying to move a use of shiro from an [OSGi
declarative
services|http://blog.vogella.com/2016/06/21/getting-started-with-osgi-declarative-services/]
component using the [web whiteboard
extender|http://ops4j.github.io/pax/web/SNAPSHOT/User-Guide.html#whiteboard-extender],
running in [apache karaf|https://karaf.apache.org], from version 1.3.1 to
1.4.1-SNAPSHOT (ie. built locally from the current shiro master).
I replaced the following [activate method of a DS
component|https://github.com/steinarb/ukelonn/blob/master/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java#L59]
{code:java}
@Activate
public void activate() {
WebIniSecurityManagerFactory securityManagerFactory = new
WebIniSecurityManagerFactory(INI_FILE);
DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager)
securityManagerFactory.createInstance();
setSecurityManager(securityManager);
UkelonnRealm realm =
createRealmProgramaticallyBecauseOfShiroIniClassCastException();
securityManager.setRealm(realm);
IniFilterChainResolverFactory filterChainResolverFactory = new
IniFilterChainResolverFactory(INI_FILE, securityManagerFactory.getBeans());
FilterChainResolver resolver =
filterChainResolverFactory.createInstance();
setFilterChainResolver(resolver);
}
{code}
with
{code:java}
@Activate
public void activate() {
IniWebEnvironment webenvironment = new IniWebEnvironment();
webenvironment.setIni(INI_FILE);
webenvironment.setServletContext(getServletContext());
webenvironment.init();
DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager)
webenvironment.getSecurityManager();
UkelonnRealm realm =
createRealmProgramaticallyBecauseOfShiroIniClassCastException();
securityManager.setRealm(realm);
setSecurityManager(securityManager);
setFilterChainResolver(webenvironment.getFilterChainResolver());
}
{code}
(i) _Note_: INIT_FILE is loaded in a static initializer that loads the
shiro.ini file from the classpath in an OSGi context, it's a bit further up in[
the component
class|https://github.com/steinarb/ukelonn/blob/master/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java#L42].
The activator fails when the IniWebEnvironment constructor tries to create an
IniSecurityManagerFactory instance using reflection and is getting a
NoClassDefFoundError:
{noformat}
2018-11-22T22:21:08,482 | ERROR | features-1-thread-1 | security
| 71 - no.priv.bang.ukelonn.web.security - 1.0.0.SNAPSHOT |
[no.priv.bang.ukelonn.web.security.UkelonnShiroFilter(5)] The activate method
has thrown an exception
java.lang.NoClassDefFoundError:
org/apache/shiro/config/IniSecurityManagerFactory
at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]
at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[?:?]
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2410)
~[?:?]
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2194)
~[?:?]
at
org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1607)
~[?:?]
at
org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
~[?:?]
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053)
~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
at
org.apache.shiro.web.env.IniWebEnvironment.<init>(IniWebEnvironment.java:60)
~[?:?]
at
no.priv.bang.ukelonn.web.security.UkelonnShiroFilter.activate(UkelonnShiroFilter.java:64)
~[?:?]
...
{noformat}
> Class load issue in OSGI in ClassUtils
> --------------------------------------
>
> Key: SHIRO-537
> URL: https://issues.apache.org/jira/browse/SHIRO-537
> Project: Shiro
> Issue Type: Bug
> Affects Versions: 1.2.3
> Environment: OSGi Felix 4.0.3
> Reporter: Tom Nelson
> Priority: Major
>
> I had the same issue that is described in:
> http://stackoverflow.com/questions/20653146/how-to-load-class-in-an-osgi-e4-environment-while-using-shiro
> where it was suggested a bug was entered but never was, so here it is. A
> similar workaround worked for me:
> Thread currentThread = Thread.currentThread();
> ClassLoader originalCl = currentThread.getContextClassLoader();
> try {
> Class<?> clazz = ((InfrastructureServer)
> server).getBundleContext().getBundle()
>
> .loadClass(CustomRolePermissionResolver.class.getName());
> ClassLoader bundleClassLoader = clazz.getClassLoader();
> currentThread.setContextClassLoader(bundleClassLoader);
> webappContext.deploy(httpServer);
> } catch (ClassNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } finally {
> currentThread.setContextClassLoader(originalCl);
> }
> In addition, commons-collections 3.2.1 must be used in an OSGi environment, I
> suggest bumping your dependency.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)