Resource names don't work for CDI managed beans in general, which aren't
registered in JNDI, unless they are EJBs.
Any object created by Shiro from a class name listed in shiro.ini is not
managed by CDI, so injection does not work.
As a workaround, to inject CDI beans into my Shiro realm implementation,
I'm currently using BeanProvider.injectFields() from Apache DeltaSpike
(requires a 0.4 SNAPSHOT build).
What I'd really like to see is a CdiEnvironment constructing all Shiro
objects as CDI managed beans. .ini syntax may be handy for URLs, but for
all object graph construction, I'd rather use @Produces and @Inject.
Best regards,
Harald
Am 08.03.2013 01:58, schrieb Les Hazlewood:
Hi Mo,
I *think* the simplest thing for JEE would be to use the
JndiObjectFactory to pull it from the JEE JNDI context. For example,
to look up a JNDI datasource and use it with the JdbcRealm:
[main]
...
datasource = org.apache.shiro.jndi.JndiObjectFactory
datasource.resourceName = jdbc/mydatasource
# if the JNDI name is prefixed with java:comp/env (like a JEE environment),
# uncomment this line:
#datasource.resourceRef = true
jdbcRealm = com.foo.my.JdbcRealm
jdbcRealm.datasource = $datasource
Please let us know if this does not meet your needs - JEE CDI is where
we'd like a lot of help from the community if possible.
Thanks,
Les
On Sat, Mar 2, 2013 at 1:48 AM, Mo Maison <[email protected]> wrote:
I use shiro in a JEE6 environment, configuring it thanks to
a simple .ini resource in classpath.
With Ini Shiro creates all objects graph by itself (reflectively,
using class names and empty constructors).
Unless I missed something, using this way of proceeding
it is not possible to inject existing external objects into
Ini variables. For example, injecting a JEE managed object
would be desirable.
Studying code, it might be sufficient to use
new ReflectionBuilder( defaults)
this constructor is called from
IniSecurityManagerFactory.buildInstances()
and defaults is got by calling createDefaults() which could
be overriden in IniSecurityManagerFactory, but I didn't manage
to make it work.
Did I miss something ?
Is there any easy way to achieve this injection ? It would be nice
to accept an initial objects map in Ini configuration API.
Or should I forget completely about Ini configuration limitations
and use something different like Spring or CDI ?
Thank you for your advices.
Regards,
M. Maison