Java中的重定向问题(Wicket)

发布于 2024-07-29 13:44:13 字数 2838 浏览 6 评论 0原文

我有一个从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

星星的轨迹 2024-08-05 13:44:13

当你安装了 IAuthorizationStrategy 时,不要使用 verifyAccess 之类的东西; 后者应该为您完成全部工作。

Don't use something like verifyAccess when you have a IAuthorizationStrategy installed; the latter should do the whole job for you.

暮光沉寂 2024-08-05 13:44:13

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?

溺孤伤于心 2024-08-05 13:44:13

WiaSession.isAuthenticated() 的逻辑是什么?

(不是忽略Eelco的评论,只是寻找根本原因)

What is the logic for WiaSession.isAuthenticated() ?

(not ignoring Eelco's comment, just looking for the root cause)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文