Search in sources :

Example 1 with RestartResponseAtInterceptPageException

use of org.apache.wicket.RestartResponseAtInterceptPageException in project wicket by apache.

the class SignInApplication method init.

@Override
protected void init() {
    super.init();
    // Register the authorization strategy
    getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {

        @Override
        public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) {
            // Check if the new Page requires authentication (implements the marker interface)
            if (AuthenticatedWebPage.class.isAssignableFrom(componentClass)) {
                // Is user signed in?
                if (((SignInSession) Session.get()).isSignedIn()) {
                    // okay to proceed
                    return true;
                }
                throw new RestartResponseAtInterceptPageException(SignIn.class);
            }
            // okay to proceed
            return true;
        }
    });
}
Also used : RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy)

Example 2 with RestartResponseAtInterceptPageException

use of org.apache.wicket.RestartResponseAtInterceptPageException in project wicket by apache.

the class InterceptTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {

                private boolean block = true;

                @Override
                public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) {
                    if (block && (componentClass == TargetPage.class || componentClass == HomePage.class)) {
                        block = false;
                        throw new RestartResponseAtInterceptPageException(InterceptPage.class);
                    }
                    return true;
                }
            });
            super.init();
        }

        @Override
        public Class<? extends Page> getHomePage() {
            return HomePage.class;
        }
    };
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy)

Example 3 with RestartResponseAtInterceptPageException

use of org.apache.wicket.RestartResponseAtInterceptPageException in project wicket by apache.

the class WebSession method getClientInfo.

/**
 * {@inheritDoc}
 *
 * <p>
 * To gather the client information this implementation redirects temporarily to a special page
 * ({@link BrowserInfoPage}).
 * <p>
 * Note: Do <strong>not</strong> call this method from your custom {@link Session} constructor
 * because the temporary page needs a constructed {@link Session} to be able to work.
 * <p>
 * If you need to set a default client info property then better use
 * {@link #setClientInfo(org.apache.wicket.core.request.ClientInfo)} directly.
 */
@Override
public WebClientInfo getClientInfo() {
    if (clientInfo == null) {
        RequestCycle requestCycle = RequestCycle.get();
        clientInfo = new WebClientInfo(requestCycle);
        if (getApplication().getRequestCycleSettings().getGatherExtendedBrowserInfo()) {
            WebPage browserInfoPage = newBrowserInfoPage();
            throw new RestartResponseAtInterceptPageException(browserInfoPage);
        }
    }
    return (WebClientInfo) clientInfo;
}
Also used : WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) WebPage(org.apache.wicket.markup.html.WebPage) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException)

Example 4 with RestartResponseAtInterceptPageException

use of org.apache.wicket.RestartResponseAtInterceptPageException in project wicket by apache.

the class AbstractBookmarkableMapperTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            getSecuritySettings().setAuthorizationStrategy(new AbstractPageAuthorizationStrategy() {

                @Override
                protected <T extends Page> boolean isPageAuthorized(Class<T> pageClass) {
                    if (pageClass == EmptyPage.class) {
                        throw new RestartResponseAtInterceptPageException(getHomePage());
                    }
                    return true;
                }
            });
        }
    };
}
Also used : EmptyPage(org.apache.wicket.util.tester.WicketTesterLazyIsPageStatelessRedirectToBufferTest.EmptyPage) MockApplication(org.apache.wicket.mock.MockApplication) AbstractPageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy) RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException)

Example 5 with RestartResponseAtInterceptPageException

use of org.apache.wicket.RestartResponseAtInterceptPageException in project wicket by apache.

the class SignIn2Application method init.

@Override
protected void init() {
    super.init();
    // Register the authorization strategy
    getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {

        public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) {
            // Check if the new Page requires authentication (implements the marker interface)
            if (AuthenticatedWebPage.class.isAssignableFrom(componentClass)) {
                // Is user signed in?
                if (((SignIn2Session) Session.get()).isSignedIn()) {
                    // okay to proceed
                    return true;
                }
                // continue with the target remembered.
                throw new RestartResponseAtInterceptPageException(SignIn2.class);
            }
            // okay to proceed
            return true;
        }
    });
}
Also used : RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy)

Aggregations

RestartResponseAtInterceptPageException (org.apache.wicket.RestartResponseAtInterceptPageException)5 IAuthorizationStrategy (org.apache.wicket.authorization.IAuthorizationStrategy)3 MockApplication (org.apache.wicket.mock.MockApplication)2 AbstractPageAuthorizationStrategy (org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy)1 WebPage (org.apache.wicket.markup.html.WebPage)1 WebClientInfo (org.apache.wicket.protocol.http.request.WebClientInfo)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 EmptyPage (org.apache.wicket.util.tester.WicketTesterLazyIsPageStatelessRedirectToBufferTest.EmptyPage)1