Java中的重定向问题(Wicket)
我有一个从 WebPage 继承的页面,并受下面的类保护:
public final class WiaAuthorizationStrategy implements
IAuthorizationStrategy,
IUnauthorizedComponentInstantiationListener {
private RealmPolicy roleManager;
private static WiaAuthorizationStrategy instance;
private WiaAuthorizationStrategy() {
roleManager = RealmPolicy.getInstance();
}
public static WiaAuthorizationStrategy getInstance() {
if(instance == null)
instance = new WiaAuthorizationStrategy();
return instance;
}
public boolean isInstantiationAuthorized(Class componentClass) {
if (ProtectedPage.class.isAssignableFrom(componentClass)) {
if (WiaSession.get().getUser() == null) {
return false;
}
if(!roleManager.isAuthorized(WiaSession.get().getUser().getRole(), componentClass.getName()))//WiaSession.get().isAuthenticated();
{
WiaSession.get().setAccess(false);
return false;
}
else
return true;
}
return true;
}
public void onUnauthorizedInstantiation(Component component) {
throw new RestartResponseAtInterceptPageException(
Login.class);
}
public boolean isActionAuthorized(Component component, Action action) {
//System.out.println("Name:" + component.getClass().getName() + "\n Action:" + action.getName() + "\nUser:" + WiaSession.get().getUser());
if (action.equals(Component.RENDER)) {
if (roleManager.containClass(component.getClass().getName()))
{
if (WiaSession.get().getUser() != null) {
if(!roleManager.isAuthorized(WiaSession.get().getUser().getRole(), component.getClass().getName()))
{
WiaSession.get().setAccess(false);
return false;
}
return true;
}
return false;
}
}
return true;
}
}
当我进入该页面时,一切正常,但当我按 Ctrl+F5 时,页面重定向到登录页面,这是进入受保护页面的默认设置。 我尝试调试代码,发现 ProtectedPage 类中的 super() 函数执行此操作,并且在调试中我无法输入这部分代码。 这个类存在于下面:
public abstract class ProtectedPage extends WebPage {
public ProtectedPage() {
---->>> 极好的(); 验证访问(); 我
protected void verifyAccess() {
// Redirect to Login page on invalid access.
if (!isUserLoggedIn()) {
throw new RestartResponseAtInterceptPageException(Login.class);
}
}
protected boolean isUserLoggedIn() {
return ((WiaSession) getSession()).isAuthenticated();
}
}
已经签署了 ---->>> 登录代码。 谁能帮我解决这个问题吗?
I have a page that is inherited from WebPage and is protected by class below:
public final class WiaAuthorizationStrategy implements
IAuthorizationStrategy,
IUnauthorizedComponentInstantiationListener {
private RealmPolicy roleManager;
private static WiaAuthorizationStrategy instance;
private WiaAuthorizationStrategy() {
roleManager = RealmPolicy.getInstance();
}
public static WiaAuthorizationStrategy getInstance() {
if(instance == null)
instance = new WiaAuthorizationStrategy();
return instance;
}
public boolean isInstantiationAuthorized(Class componentClass) {
if (ProtectedPage.class.isAssignableFrom(componentClass)) {
if (WiaSession.get().getUser() == null) {
return false;
}
if(!roleManager.isAuthorized(WiaSession.get().getUser().getRole(), componentClass.getName()))//WiaSession.get().isAuthenticated();
{
WiaSession.get().setAccess(false);
return false;
}
else
return true;
}
return true;
}
public void onUnauthorizedInstantiation(Component component) {
throw new RestartResponseAtInterceptPageException(
Login.class);
}
public boolean isActionAuthorized(Component component, Action action) {
//System.out.println("Name:" + component.getClass().getName() + "\n Action:" + action.getName() + "\nUser:" + WiaSession.get().getUser());
if (action.equals(Component.RENDER)) {
if (roleManager.containClass(component.getClass().getName()))
{
if (WiaSession.get().getUser() != null) {
if(!roleManager.isAuthorized(WiaSession.get().getUser().getRole(), component.getClass().getName()))
{
WiaSession.get().setAccess(false);
return false;
}
return true;
}
return false;
}
}
return true;
}
}
when I enter that page it is ok and everything works but when I press Ctrl+F5 the page redirect to Login Page which is default for entring protected pages.
I tried to debug the code and I found that the super() function in ProtectedPage class do this and in debugging I cannot enter this part of code. this class exists below:
public abstract class ProtectedPage extends WebPage {
public ProtectedPage() {
---->>> super();
verifyAccess();
}
protected void verifyAccess() {
// Redirect to Login page on invalid access.
if (!isUserLoggedIn()) {
throw new RestartResponseAtInterceptPageException(Login.class);
}
}
protected boolean isUserLoggedIn() {
return ((WiaSession) getSession()).isAuthenticated();
}
}
I have signed that by ---->>> sign in the code.
Can anyone help me with this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当你安装了 IAuthorizationStrategy 时,不要使用 verifyAccess 之类的东西; 后者应该为您完成全部工作。
Don't use something like verifyAccess when you have a IAuthorizationStrategy installed; the latter should do the whole job for you.
ctrl+F5 应该做什么?
您有一些键绑定问题吗?
你不能做重定向吗? 你的问题到底是什么?
what is ctrl+F5 supposed to do?
do you have some keybinding issues?
You can't do a redirect? What's your problem exactly?
WiaSession.isAuthenticated() 的逻辑是什么?
(不是忽略Eelco的评论,只是寻找根本原因)
What is the logic for WiaSession.isAuthenticated() ?
(not ignoring Eelco's comment, just looking for the root cause)