Search in sources :

Example 41 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class WebPageRendererTest method before.

/**
 * Common setup
 */
@Before
public void before() {
    provider = mock(IPageProvider.class);
    page = mock(IRequestablePage.class);
    when(provider.getPageInstance()).thenReturn(page);
    handler = new RenderPageRequestHandler(provider);
    requestCycle = mock(RequestCycle.class);
    urlRenderer = mock(UrlRenderer.class);
    when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
    request = mock(WebRequest.class);
    when(requestCycle.getRequest()).thenReturn(request);
    response = mock(WebResponse.class);
    when(requestCycle.getResponse()).thenReturn(response);
}
Also used : BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) WebResponse(org.apache.wicket.request.http.WebResponse) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) WebRequest(org.apache.wicket.request.http.WebRequest) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) UrlRenderer(org.apache.wicket.request.UrlRenderer) Before(org.junit.Before)

Example 42 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket-orientdb by OrienteerBAP.

the class OrientDefaultExceptionsHandlingListener method onException.

@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
    Throwable th = null;
    if ((th = Exceptions.findCause(ex, OSecurityException.class)) != null || (th = Exceptions.findCause(ex, OValidationException.class)) != null || (th = Exceptions.findCause(ex, OSchemaException.class)) != null || (th = Exceptions.findCause(ex, IllegalStateException.class)) != null && Exceptions.findCause(ex, WicketRuntimeException.class) == null) {
        Page page = extractCurrentPage(false);
        if (page == null) {
            return th instanceof OSecurityException ? new UnauthorizedInstantiationHandler(extractCurrentPage(true)) : null;
        }
        OrientDbWebSession.get().error(th.getMessage());
        return new RenderPageRequestHandler(new PageProvider(page), RenderPageRequestHandler.RedirectPolicy.ALWAYS_REDIRECT);
    } else if ((th = Exceptions.findCause(ex, UnauthorizedActionException.class)) != null) {
        final UnauthorizedActionException unauthorizedActionException = (UnauthorizedActionException) th;
        return new UnauthorizedInstantiationHandler(unauthorizedActionException.getComponent());
    } else {
        return null;
    }
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Page(org.apache.wicket.Page) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) UnauthorizedActionException(org.apache.wicket.authorization.UnauthorizedActionException)

Example 43 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class PageInstanceMapper method mapRequest.

/**
 * @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
 */
@Override
public IRequestHandler mapRequest(Request request) {
    if (matches(request)) {
        Url url = request.getUrl();
        PageComponentInfo info = getPageComponentInfo(url);
        if (info != null && info.getPageInfo().getPageId() != null) {
            Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
            if (info.getComponentInfo() == null) {
                PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
                provider.setPageSource(getContext());
                // render page
                return new RenderPageRequestHandler(provider);
            } else {
                ComponentInfo componentInfo = info.getComponentInfo();
                PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
                provider.setPageSource(getContext());
                return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
            }
        }
    }
    return null;
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 44 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project hale by halestudio.

the class BaseWebApplication method init.

@Override
public void init() {
    super.init();
    BootstrapSettings settings = new BootstrapSettings();
    final ThemeProvider themeProvider = new BootswatchThemeProvider() {

        {
            add(new MetroTheme());
            add(new GoogleTheme());
            add(new WicketTheme());
            add(new Bootstrap3Theme());
            defaultTheme("bootstrap-responsive");
        // defaultTheme("bootstrap");
        }
    };
    settings.setThemeProvider(themeProvider);
    Bootstrap.install(this, settings);
    BootstrapLess.install(this);
    configureResourceBundles();
    IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
    if (packageResourceGuard instanceof SecurePackageResourceGuard) {
        SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard;
        guard.addPattern("+org/apache/wicket/resource/jquery/*.map");
    }
    // enforce mounts so security interceptors based on URLs can't be fooled
    getSecuritySettings().setEnforceMounts(true);
    getSecuritySettings().setAuthorizationStrategy(new SimplePageAuthorizationStrategy(SecuredPage.class, getLoginPageClass()) {

        @Override
        protected boolean isAuthorized() {
            SecurityContext securityContext = SecurityContextHolder.getContext();
            if (securityContext != null) {
                Authentication authentication = securityContext.getAuthentication();
                if (authentication != null && authentication.isAuthenticated()) {
                    for (GrantedAuthority authority : authentication.getAuthorities()) {
                        if (authority.getAuthority().equals(UserConstants.ROLE_USER) || authority.getAuthority().equals(UserConstants.ROLE_ADMIN)) {
                            // allow access only for users/admins
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    });
    getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        @Override
        public IRequestHandler onException(RequestCycle cycle, Exception ex) {
            return new RenderPageRequestHandler(new PageProvider(new ExceptionPage(ex)));
        }
    });
    // add login page to every application based on this one (if enabled)
    Class<? extends BasePage> loginClass = getLoginPageClass();
    if (loginClass != null) {
        // login page
        mountPage("/login", loginClass);
        // user settings
        mountPage("/settings", UserSettingsPage.class);
        // about
        mountPage("/about", AboutPage.class);
        // contact
        mountPage("/contact", ContactPage.class);
        if (OpenIdLoginPage.class.equals(loginClass)) {
            // for OpenID auth also add page for new users
            mountPage("/new", NewUserPage.class);
        }
    }
}
Also used : WicketTheme(de.agilecoders.wicket.themes.markup.html.wicket.WicketTheme) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) GoogleTheme(de.agilecoders.wicket.themes.markup.html.google.GoogleTheme) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimplePageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy) MetroTheme(de.agilecoders.wicket.themes.markup.html.metro.MetroTheme) Bootstrap3Theme(de.agilecoders.wicket.themes.markup.html.bootstrap3.Bootstrap3Theme) BootstrapSettings(de.agilecoders.wicket.core.settings.BootstrapSettings) IPackageResourceGuard(org.apache.wicket.markup.html.IPackageResourceGuard) SecurePackageResourceGuard(org.apache.wicket.markup.html.SecurePackageResourceGuard) Authentication(org.springframework.security.core.Authentication) PageProvider(org.apache.wicket.core.request.handler.PageProvider) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener) SecurityContext(org.springframework.security.core.context.SecurityContext) ExceptionPage(eu.esdihumboldt.hale.server.webapp.pages.ExceptionPage) SecuredPage(eu.esdihumboldt.hale.server.webapp.pages.SecuredPage) BootswatchThemeProvider(de.agilecoders.wicket.themes.settings.BootswatchThemeProvider) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector) BootswatchThemeProvider(de.agilecoders.wicket.themes.settings.BootswatchThemeProvider) ThemeProvider(de.agilecoders.wicket.core.settings.ThemeProvider)

Example 45 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project syncope by apache.

the class SyncopeConsoleRequestCycleListener method onException.

@Override
public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
    LOG.error("Exception found", e);
    PageParameters errorParameters = new PageParameters();
    IRequestablePage errorPage = null;
    if (instanceOf(e, UnauthorizedInstantiationException.class) != null) {
        errorParameters.add("errorMessage", MISSING_AUTHORIZATION);
        errorPage = new Login(errorParameters);
    } else if (instanceOf(e, AccessControlException.class) != null) {
        if (instanceOf(e, AccessControlException.class).getMessage().contains("expired")) {
            errorParameters.add("errorMessage", PAGE_EXPIRED);
        } else {
            errorParameters.add("errorMessage", MISSING_AUTHORIZATION_CORE);
        }
        errorPage = new Login(errorParameters);
    } else if (instanceOf(e, PageExpiredException.class) != null || !SyncopeConsoleSession.get().isSignedIn()) {
        errorParameters.add("errorMessage", PAGE_EXPIRED);
        errorPage = new Login(errorParameters);
    } else if (instanceOf(e, BadRequestException.class) != null || instanceOf(e, WebServiceException.class) != null || instanceOf(e, SyncopeClientException.class) != null) {
        errorParameters.add("errorMessage", REST);
        errorPage = new Login(errorParameters);
    } else {
        Throwable cause = instanceOf(e, ForbiddenException.class);
        if (cause == null) {
            // redirect to default Wicket error page
            errorPage = new ExceptionErrorPage(e, null);
        } else {
            errorParameters.add("errorMessage", cause.getMessage());
            errorPage = new Login(errorParameters);
        }
    }
    if (errorPage instanceof Login) {
        try {
            SyncopeConsoleSession.get().cleanup();
            SyncopeConsoleSession.get().invalidateNow();
        } catch (Throwable t) {
            // ignore
            LOG.debug("Unexpected error while forcing logout after error", t);
        }
    }
    return new RenderPageRequestHandler(new PageProvider(errorPage));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AccessControlException(java.security.AccessControlException) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Login(org.apache.syncope.client.console.pages.Login) UnauthorizedInstantiationException(org.apache.wicket.authorization.UnauthorizedInstantiationException)

Aggregations

RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)75 IRequestHandler (org.apache.wicket.request.IRequestHandler)64 Test (org.junit.Test)61 Url (org.apache.wicket.request.Url)50 PageProvider (org.apache.wicket.core.request.handler.PageProvider)36 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)32 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)19 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)16 MockPage (org.apache.wicket.MockPage)13 Request (org.apache.wicket.request.Request)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)5 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)3 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)3 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)2 WebResponse (org.apache.wicket.request.http.WebResponse)2