Hi Tauren
I've done something similar.. Have no trouble with..
Disclaimer, below code are really ugly and I need to clean it up...
package zeuzgroup.application;
import org.apache.wicket.Request;
import org.apache.wicket.authentication.AuthenticatedWebSession;
import org.apache.wicket.authorization.strategies.role.Roles;
import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.spring.injection.annot.SpringBean;
import zeuzgroup.application.models.BaseEntityDetachableModel;
import zeuzgroup.core.Person;
import zeuzgroup.core.provider.IDBDao;
import zeuzgroup.core.user.UserType;
public class ZeuzSession extends AuthenticatedWebSession {
private boolean authorized = false;
private BaseEntityDetachableModel<Person> personModel;
@SpringBean(name = "dBDao")
protected IDBDao dBDao;
protected ZeuzSession(Request request) {
super(request);
InjectorHolder.getInjector().inject(this);
}
@Override
protected void detach() {
super.detach();
if (personModel != null) {
personModel.detach();
}
}
public boolean isAuthorized() {
return authorized;
}
public void setAuthorized(boolean authorized) {
this.authorized = authorized;
if (authorized) {
getPerson().setLoggedIn(true);
}
// Call below too!
signIn(getPerson().getAlias(), getPerson().getPassword());
}
public Person getPerson() {
if (personModel != null) {
Person person = (Person) personModel.getObject();
if (person == null) {
person = new Person();
person.setUserType(UserType.Guest);
}
return person;
} else {
Person person = new Person();
person.setUserType(UserType.Guest);
return person;
}
}
public BaseEntityDetachableModel<Person> getPersonModel() {
return personModel;
}
public void setPerson(Person person) {
if (personModel != null) {
personModel.setBaseEntityDetachableModel(person);
} else {
personModel = new BaseEntityDetachableModel<Person>(person);
}
}
public void onBeforeDestroy() {
getPerson().setLoggedIn(false);
}
@Override
public boolean authenticate(String username, String password) {
Person person = new Person();
person.setAlias(username);
person.setPassword(password);
return dBDao.authorizePerson(person);
}
@Override
public Roles getRoles() {
// If the user is signed in, they have these roles
// user always are associated with a person
return new Roles(getPerson().getUserType().toString());
}
}
2009/2/20 Tauren Mills <[email protected]>
> The WIA book and other example apps I've found online often show a
> User object being stored in the session:
>
> class BlogSession extends WebSession {
> private User user;
> }
>
> But does it make sense to do this if your User object is loaded from a
> persistence layer (Hibernate) and can contain a large tree of
> dependent objects? For instance, what if my User object has a
> hierarchy like this:
>
> User
> Name
> Password
> Set<Blog>
> Blog
> Set<BlogEntry>
> BlogEntry
> Set<Tag>
> Set<Tag>
>
> Would this store the entire hierarchy of blogs, tags, blog entries,
> etc. into the session? I've been experimenting with storing an LDM
> of the user in the session instead of the User directly:
>
> class BlogSession extends WebSession {
> private DetachableUserModel userModel;
> }
>
> But I'm getting Hibernate LazyInit errors. So it leaves me wondering
> if LDMs in Session aren't automatically loaded since it isn't a
> Component. I haven't really dug into what is going on yet. I first
> wanted to find out what is common practice for a situation like this.
>
> Oh, and this isn't my actual User object -- just and example for
> illustrative purposes. I'm not building a blog, and the properties
> and sets of objects in my User need to be there.
>
> Thanks!
> Tauren
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>