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?
Access Hibernate with out apache Tapestry injection
138 Views Asked by Milimber At
3
There are 3 best solutions below
0
On
Tapestry IOC can only @Inject into a service that it has created itself. If you have constructed the AuthorizingRealm using new then the instance is not under IOC control and won't be injected.
Either @Autobuild the AuthorizingRealm instance or declare it as a service in your IOC module.
0
On
Try add this to your AppModule (MongoDB example):
@Contribute(WebSecurityManager.class)
public static void addRealms(Configuration<Realm> configuration, @Autobuild MongoRealm realm)
{
configuration.add(realm);
}
and provide also your AuthorizingRealm:
public class MongoRealm extends AuthorizingRealm
{
@Inject
private SomeDAO someDAO;
...
}
If you can get access to the Tapestry Registry (it is stored in the Servlet Context, for example), then you can gain access to the necessary services inside Tapestry and ultimately to the Hibernate Session.