我試圖創建一個Wicket 7.8.0應用程序,一切工作正常,除了頁面重定向到登錄前訪問原來的頁面。重定向到原來的頁面不工作
每當我試圖訪問受保護頁面沒有被登錄,我被正確地重定向到SignIn頁面,但是一旦我登錄了,我就會被重定向到主頁而不是原始頁面。
這裏是我的應用程序類:
public class MyApplication extends AuthenticatedWebApplication {
...
@Override
public void init() {
super.init();
MetaDataRoleAuthorizationStrategy.authorize(HomePage.class, "TEST_ROLE");
MetaDataRoleAuthorizationStrategy.authorize(SecuredPage.class, "TEST_ROLE");
this.mountPage("signin", SignInPage.class);
this.mountPage("homepage", HomePage.class);
this.mountPage("secured/secured", SecuredPage.class);
//this page is secured with annotations
this.mountPage("secured/another", AnotherSecuredPage.class);
this.getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
}
}
爲了登錄,我使用了一個非常簡化的登錄頁面:當我在已登錄
public class SignInPage extends WebPage {
private String username;
private String password;
private static final long serialVersionUID = 8096706227164750788L;
public SignInPage() {
this.add(new FeedbackPanel("feedback"));
final Form<SignInPage> form = new Form<>("form");
form.add(new TextField<>("username", new PropertyModel<String>(this, "username")));
form.add(new PasswordTextField("password", new PropertyModel<String>(this, "password")));
form.add(new SubmitLink("submit") {
private static final long serialVersionUID = 6057698894229534492L;
@Override
public void onSubmit() {
final Session session = SignInPage.this.getSession();
if(session.signIn(SignInPage.this.username, SignInPage.this.password)) {
this.continueToOriginalDestination();
setResponsePage(getApplication().getHomePage());
}
else {
SignInPage.this.error("Bad username/password combo!");
}
}
});
final WebClientInfo clientInfo = (WebClientInfo) this.getSession().getClientInfo();
this.add(new Label("userAgent", clientInfo.getUserAgent()));
this.add(form);
}
}
在至少一次應用程序雖然,如果我再次註銷,重定向到原始頁面每次重新登錄時都有效。
我在做什麼錯了?
更好地看看wicket-examples,你不需要爲這個頁面設計一個'母類':https://github.com/apache/wicket/blob/master/wicket-auth-roles/src /main/java/org/apache/wicket/authroles/authentication/AuthenticatedWebApplication.java – svenmeier
的確,我沒有注意到這一點!這就是定義onConfigure()方法首先不被調用的原因。 –