What I did for that was store the userId in an ASO and then use a threaded
HiveMind service (which can look up the ASO through the
ApplicationStateManager) to query for the User object as it is needed (lazy
initialization) based on the userId stored in the ASO...
<contribution configuration-id="tapestry.state.ApplicationObjects">
<state-object name="UserSession" scope="session">
<create-instance class="com.martialware.web.state.UserSession"/>
</state-object>
</contribution>
<service-point id="SecurityContext"
interface="com.martialware.web.service.SecurityContext">
<invoke-factory model="threaded">
<construct
class="com.martialware.web.service.impl.SecurityContextImpl"/>
</invoke-factory>
</service-point>
public class SecurityContextImpl implements SecurityContext
{
private ApplicationStateManager stateManager;
private SecurityService securityService;
private UserRepository userRepository;
private User user;
public void authenticate( String userName, String password ) throws
InvalidPasswordException,
InvalidUserIdException
{
securityService.authenticate( userName, password );
getUserSession().setUserId( userName );
}
public boolean isAuthenticated()
{
final UserSession userSession = getUserSession();
return userSession.getUserId() != null;
}
public void logout()
{
getUserSession().setUserId( null );
}
public User getUser()
{
if( user == null )
{
if( isAuthenticated() )
{
user = userRepository.getUserByUserId(
getUserSession().getUserId() );
}
}
return user;
}
private UserSession getUserSession()
{
final UserSession userSession = ( UserSession ) stateManager.get(
UserSession.NAME );
return userSession;
}
public void setUserRepository( UserRepository userRepository )
{
this.userRepository = userRepository;
}
public void setSecurityService( SecurityService securityService )
{
this.securityService = securityService;
}
public void setStateManager( ApplicationStateManager stateManager )
{
this.stateManager = stateManager;
}
}
-----Original Message-----
From: Anthony Fox [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 23, 2006 8:57 AM
To: Tapestry users
Subject: Re: hibernate detached objects as persistent page properties
Thanks for the code. I'll take a look and see if I can incorporate
this in my application.
One further question, how have people dealt with detached hibernate
objects in the session? In my case, which I imagine is a common case
for a lot of people, after the user has authenticated, I store the
User object in my Visit object. The user object is a hibernate
detached entity. As the user performs actions on the site, I update
the user object including updating lazy loaded collections that map
the user object to other tables. I suppose I have to reattach the
User object for each request but this doesn't seem terribly efficient.
What have others done?
On 2/22/06, James Carman <[EMAIL PROTECTED]> wrote:
> Oh, forgot to mention on thing (and that's what this whole thread is all
> about). There's a new page persistence strategy implemented in there too.
> Just declare your page properties as stored using "entity" like this...
>
> @Persist("entity")
> public abstract Account getAccount();
>
> And, Tapernate will store the object (it has to be a single object at the
> moment; it doesn't support collections) in the session using only its
> identity and automatically reconstitute it when you come back each time.
> Now, if the object is an entity object, but it isn't persistent yet, it'll
> just keep it in the session as-is without translating it into its
identity.
> Hope this stuff works for you guys! Let me know if I can help with
> anything.
>
>
> -----Original Message-----
> From: Andreas Bulling [mailto:[EMAIL PROTECTED] On Behalf Of
> Andreas Bulling
> Sent: Wednesday, February 22, 2006 1:33 PM
> To: Tapestry users
> Subject: Re: hibernate detached objects as persistent page properties
>
> On 22. Feb 2006 - 13:30:00, James Carman wrote:
> | Okay, folks. I've abstracted out the Hibernate/Tapestry stuff into its
> own
> | project called "Tapernate." You can download the source and build it
> | yourself (the libs are there for you) from SVN:
> |
> | http://www.carmanconsulting.com/svn/public/tapernate/trunk
>
> *Running to fire up the browser... ;)*
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]