I've been trying to subclass Wicket's WebSession so I can implement a basic authentication system. I have followed the guidelines in the Wicket reference library. When I try the following in my WebPage, I get a ClassCastException:
((AppSession)Session.get()).setUid()
Here is the full error:
java.lang.ClassCastException: org.apache.wicket.protocol.http.WebSession cannot be cast to com.example.webapp.AppSession
I've been searching the web for hours and tried everything I could. I would really appreciate some help. Also, please let me know if there is a better way of doing this. I'm really new to wicket.
Thank you.
AppSession.java
public final class AppSession extends WebSession {
private Integer uid;
public AppSession(Request request) {
super(request);
}
public final Integer getUid() {
return uid;
}
public final void setUid(Integer uid) {
this.uid = uid;
}
public static AppSession get() {
return (AppSession)Session.get();
}
}
App.java
public class App extends WebApplication {
public App() {
super();
new AnnotatedMountScanner().scanPackage("com.example.webapp").mount(this);
}
@Override
public Session newSession(Request request, Response response) {
return new AppSession(request);
}
@Override
public Class getHomePage() {
return null;
}
}