我想密码保护Wicket中的网页,以便用户只有在他/她登录后才能访问它.
我也想要显示登录页面的页面,然后在登录用户试图访问的原始页面之后.
怎么用wicket完成?我已经创建了一个登录页面并扩展了会话类.
框架提供的方法是为您的应用程序提供IAuthorizationStrategy实例,例如,通过添加到您的Application init()方法:
init() {
...
getSecuritySettings().setAuthorizationStrategy(...)
}
Run Code Online (Sandbox Code Playgroud)
的围墙门授权功能的工作的例子是在检票的东西在这里,这表明一些相当复杂的东西.对于非常简单的情况,请查看SimplePageAuthorizationStrategy.在一个非常基本的层面上,这可以像这样使用(取自链接的Javadoc):
SimplePageAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy(
MySecureWebPage.class, MySignInPage.class)
{
protected boolean isAuthorized()
{
// Authorize access based on user authentication in the session
return (((MySession)Session.get()).isSignedIn());
}
};
getSecuritySettings().setAuthorizationStrategy(authorizationStrategy);
Run Code Online (Sandbox Code Playgroud)
编辑以回应评论
我认为最好的前进方式,如果你只是想使用类似的东西SimplePageAuthorizationStrategy而不是那个类本身.我做了类似的事情来捕获使用自定义注释注释的页面:
IAuthorizationStrategy authorizationStrategy = new AbstractPageAuthorizationStrategy()
{
protected boolean isPageAuthorized(java.lang.Class<Page.class> pageClass)
{
if (pageClass.getAnnotation(Protected.class) != null) {
return (((MySession)Session.get()).isSignedIn());
} else {
return true;
}
}
};
Run Code Online (Sandbox Code Playgroud)
然后你需要注册一个类似于SimplePageAuthorizationStrategy(链接到源代码)的IUnauthorizedComponentInstantiationListener,它应该是这样的:
new IUnauthorizedComponentInstantiationListener()
{
public void onUnauthorizedInstantiation(final Component component)
{
if (component instanceof Page)
{
throw new RestartResponseAtInterceptPageException(MySignInPage.class);
}
else
{
throw new UnauthorizedInstantiationException(component.getClass());
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1230 次 |
| 最近记录: |