Hi Dragon, I believe what Kalle and Thiago are saying is that @Inject in your realm will not work unless your realm is itself a service or a component (such as a page).
In your code, the "RRealm realm" is a plain old java object instantiated using "new". Tapestry IoC injection service will not be invoked during such conventional instantiation, and the hibernate field you are trying to @Inject inside such realm object will definitely be NULL. As described by Kalle and Thiago, you have two ways to solve this. 1. Tell Tapestry to build "RRealm realm" as if it is a service by using the @Autobuild annotation. That way, Tapestry IoC will take on the responsibility of building the object (no longer a need for you to call "new"), during which @Inject will be honored. Specifically, you should change the "addRealm" method declaration to add another parameter: @Autobuild RRealm realm. That parameter will be automagically provided by Tapestry, with all @Inject-ed dependencies resolved. 2. You can make RRealm a Tapestry IoC service (by creating an interface, an implementation, and bind the two in AppModule). Lastly, make sure whatever you are trying to @Inject (sounds like a hibernate instance) is itself a Tapestry IoC serivce. If not, Tapestry will throw an exception. Hope this helps. On Tue, Nov 18, 2014 at 3:24 PM, dragon <milim...@gmail.com> wrote: > > On 11/18/2014 02:50 PM, Kalle Korhonen wrote: > > You make your AuthorizingRealm a Tapestry service or at least let the ioc > > @Autobuild it for you. This is all fairly well covered at > > http://tynamo.org/tapestry-security+guide but sounds like you might not > be > > using tapestry-security. Anyway, here's an sample service realm (in JPA > but > > same difference): > > > https://github.com/tynamo/tynamo-federatedaccounts/blob/master/tynamo-federatedaccounts-test/src/test/java/org/tynamo/security/federatedaccounts/testapp/services/UserRealm.java > > . > I am using tynamo-security and setting the config and the realm via the > AppModule: > > @Contribute(WebSecurityManager.class) > public static void addRealms(Configuration<Realm> configuration) { > CredentialsMatcher credentialsMatcher = new RCredentialsMatcher(); > RRealm realm = new RRealm(); > realm.setCredentialsMatcher(credentialsMatcher); > configuration.add(realm); > } > > When the realm is created any @Inject is ignored (Session is always > NULL). I have looked at the tynamo page and I do not see where its > described or shown using the realm as a service.. am i missing something? > > Thanks > > > > Kalle > > > > On Tue, Nov 18, 2014 at 11:40 AM, dragon <milim...@gmail.com> wrote: > > > >> Im trying to access a hibernate entity/database from a shiro > >> AuthorizingRealm extending class. Since the tapestry IOC does not inject > >> outside Pages / Components, how do i access the Hibernate Session so i > >> can access the database? > >> > >> > >> Thanks for any suggestions. > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > >> For additional commands, e-mail: users-h...@tapestry.apache.org > >> > >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Best Regards Harry Zhou