@Harald & @Les : thank you for your answers.

I managed to work around JEE objects injection, by adding
some utility static factory code in order to get arbitrary class
objects in .ini ; not always an applicable solution though.

I noticed two strange things with INI however :

1 - it is not possible to dereference properties of referenced objects
  at the right of the = sign.
  obj.prop = $ref works, but obj = $ref.prop does not.
  I was very disappointed by this limitation.

2 - when injecting a property whose setter expects say a Set,
  special handling is performed (split string with comma and build
  a set before injection or so...).
  But this is performed /also/ for references, thus this does not work
  if myUrlsSetRef is already a Set :
  obj.urlsSet = $myUrlsSetRef
  because shiro wraps the referenced set into a new set with 1 element.
  I had to create a fake setter with Object attribute type to avoid this.
  I'd suggest to disable this wrapping mechanism for references
  (but it may break compatibility).

I'll try to have a look to CDI, in case it would simplify objects graph
construction.

Regards,

  M. Maison


Le 08/03/2013 22:44, Harald Wellmann a écrit :
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


Reply via email to