我试图创建一个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()方法首先不被调用的原因。 –