views:

699

answers:

3

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?

A: 

what is ctrl+F5 supposed to do?

do you have some keybinding issues?

You can't do a redirect? What's your problem exactly?

when I refresh my page or do something which needs to contact to server page is redirected to Login Page
JGC
+2  A: 

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

Eelco
Good to see you on here Eelco, really liked Wicket in Action!
Tim
A: 

What is the logic for WiaSession.isAuthenticated() ?

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

ireddick