On Wed, Mar 28, 2012 at 2:57 PM, Crentana <i...@crentana.de> wrote: > Im quite new to tapestry and tapestry-security. But i cant find a way to get > an user object. I guess I have to query the db whenever I need it? (I know > Subject.getPrincipal, but im asking because i could imagine there is a > standard way.)
I've built systems and web applications long enough that I just know there's no standard way. FederatedAccounts module's FederatedAccount interface comes closest to what I've dared to making an attempt at standardizing any User interface, and even that is optional. The needs are vastly different and the different User objects simply just don't share any common structure. > If I have to implement it on my own, i guess there is no way to cache an > Object(in this case the DB-UserObject) in a service for a Request? There are a few reasonable models and you can certainly cache the user object for the lifetime of a request. In principle, you could stick the whole User object as a principal of Subject, but it's not a great idea, sorry I mentioned it first :) A lightweight CurrentUser session state object is a widely used approach and we have an example of it at http://svn.codehaus.org/tynamo/trunk/tynamo-example-federatedaccounts/src/main/java/org/tynamo/examples/federatedaccounts/services/AppModule.java (and related classes, see http://tynamo.org/tapestry-security+guide). If you need the whole User object for most requests and it's a heavyweight, it might be feasible to create per-thread service for obtaining the user object. See http://tapestry.apache.org/defining-tapestry-ioc-services.html for creating a per thread service, it should be pretty straight-forwarded. Finally, if you are using any reasonable persistence layer, the user object you just fetched will likely be cached in L1/L2 caches for subsequent queries which offers very reasonable performance without being a memory hog (almost) out-of-the-box (for jpa specific, see https://blogs.oracle.com/carolmcdonald/entry/jpa_caching for example) - so you may want to measure the performance you are getting before doing anything more complicated. Kalle --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org