Java 如何在wicket登录页面中使用path参数

Java 如何在wicket登录页面中使用path参数,java,login,wicket,Java,Login,Wicket,我有一个安装了路径参数的受保护wicket页,例如: class MyApp extends AuthenticatedWebApplication { @Override protected void init() { mountPage("/login/${site}", MyLoginPage.class); mountPage("/admin/${site}", MyAdminPage.class); } @Override protected Class&l

我有一个安装了路径参数的受保护wicket页,例如:

class MyApp extends AuthenticatedWebApplication {
  @Override protected void init() {
    mountPage("/login/${site}", MyLoginPage.class);
    mountPage("/admin/${site}", MyAdminPage.class);
  }
  @Override protected Class<? extends WebPage> getSignInPageClass() {
    return MyLoginPage.class;
} }

@AuthorizeInstantiation("ADMIN")
class MyAdminPage extends WebPage { ... }
MyApp类扩展了AuthenticatedWebApplication{ @重写受保护的void init(){ mountPage(“/login/${site}”,MyLoginPage.class); mountPage(“/admin/${site}”,MyAdminPage.class); }
@Override protected ClassOverride method restartResponseAtSignInPage调用您的登录页面并生成一个特定于您的站点的参数。我给您举了一个完整上下文路径的示例,因为我不知道您使用什么来标识站点

class MyApp extends AuthenticatedWebApplication {

    @Override protected void init() {
        super.init();
        mountPage("/login/${site}", MyLoginPage.class);
        mountPage("/admin/${site}", MyAdminPage.class);
    }

    @Override   
    public void restartResponseAtSignInPage() {
        // contextPath is just an example, implement here anything 
        // you use to identify the page or site
        String contextPath = RequestCycle.get().getRequest().getContextPath();
        throw new RestartResponseAtInterceptPageException(new MyLoginPage(new PageParameters().add("site", contextPath)));
    }
}
编辑

注1:如果必须继续使用原始请求中的任何参数,请参阅如何从请求周期提取参数

IRequestParameters requestParameters = RequestCycle.get().getRequestParameters();
注2:您确实可以覆盖原始AuthenticatedWebApplication的全部功能,因为最终的方法有点复杂。可能您必须修改以下代码才能准确提取我不太清楚的站点参数

class MyApp extends AuthenticatedWebApplication {

@Override 
protected void init() {
    super.init();
    mount("/login/${site}", MyLoginPage.class);
    mountPage("/admin/${site}", MyAdminPage.class);
    getSecuritySettings().setUnauthorizedComponentInstantiationListener(new IUnauthorizedComponentInstantiationListener() {

        @Override
        public void onUnauthorizedInstantiation(Component component) {
            MyApp.this.onMyUnauthorizedInstantiation(Component component);

        }
    });
}

public void onMyUnauthorizedInstantiation(final Component component) {
    if (component instanceof Page)
    {
        if (!AbstractAuthenticatedWebSession.get().isSignedIn())
        {
            // Redirect to intercept page to let the user sign in
            restartResponseAtSignInPage((Page)component);
        }
        else
        {
            onUnauthorizedPage((Page)component);
        }
    }
    else
    {
        // The component was not a page, so throw an exception
        throw new UnauthorizedInstantiationException(component.getClass());
    }
}


@Override   
public void restartResponseAtSignInPage(Page page) {
    // contextPath is just an example, implement here anything 
    // you use to identify the page or site
    throw new RestartResponseAtInterceptPageException(new MyLoginPage(new PageParameters().add("site", page.getPageParameters().get("site").toString("defaultValue"))));
}

}

你已经看过continueToOriginalDestination方法了吗()?我只会挂载我的(安全的)页面,如果你在调用它们时没有登录,你会被重定向到登录页面,然后从那里转到原始站点。而不需要将URL作为参数传递。问题是传递“站点”原始页面的页面参数指向登录页面本身,而不是指向原始页面。重定向到原始页面不是问题。但是为什么需要“站点”-登录页面中的参数?因为我需要用于登录过程的站点,同一个登录可以在不同的站点上使用多次。我不希望用户在登录之前选择该站点,并且该站点必须是可书签的。将站点参数存储在会话中如何(ci.apache.org/projects/wicket/apidocs/6.0.x/org/apache/wicket/Session.html)?我以前已经尝试过,但我想从请求中获取原始页面参数,以获得正确的站点。我可以通过手动解析请求的客户端URL来使用解决方法,但这很容易出错,因为它依赖于页面装载方式的假设。我想理论上我可以访问页面参数,正如我所看到的那样在此方法中设置断点时,堆栈跟踪中向上的某个位置。