Search in sources :

Example 46 with PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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)

Example 47 with PageProvider

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

the class AbstractBookmarkableMapper method processHybrid.

/**
 * Creates a {@code IRequestHandler} that processes a hybrid request. When the page identified
 * by {@code pageInfo} was not available, the request should be treated as a bookmarkable
 * request.
 *
 * @param pageInfo
 * @param pageClass
 * @param pageParameters
 * @param renderCount
 * @return a {@code IRequestHandler} capable of processing the hybrid request.
 */
protected IRequestHandler processHybrid(PageInfo pageInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount) {
    PageProvider provider = new PageProvider(pageInfo.getPageId(), pageClass, pageParameters, renderCount);
    provider.setPageSource(getContext());
    checkExpiration(provider, pageInfo);
    /**
     * https://issues.apache.org/jira/browse/WICKET-5734
     */
    PageParameters constructionPageParameters = provider.hasPageInstance() ? provider.getPageInstance().getPageParameters() : new PageParameters();
    if (PageParameters.equals(constructionPageParameters, pageParameters) == false) {
        // when the resolved page by id has been created
        return new RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
    }
    return new RenderPageRequestHandler(provider);
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters)

Example 48 with PageProvider

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

the class BookmarkableMapperTest method encode4.

/**
 */
@Test
public void encode4() {
    MockPage page = new MockPage(15);
    page.getPageParameters().set(0, "i1");
    page.getPageParameters().set(1, "i2");
    page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
    page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
    page.setCreatedBookmarkable(true);
    IPageProvider provider = new PageProvider(page);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15&a=b&b=c", url.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 49 with PageProvider

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

the class CryptoMapperTest method pageInstanceEncrypt.

/**
 * Tests that URLs for page instances are encrypted (/wicket/page?5)
 */
@Test
public void pageInstanceEncrypt() {
    MockPage page = new MockPage(5);
    IRequestHandler requestHandler = new RenderPageRequestHandler(new PageProvider(page));
    assertEquals(PLAIN_PAGE_INSTANCE_URL, mapper.getDelegateMapper().mapHandler(requestHandler).toString());
    assertEquals(ENCRYPTED_PAGE_INSTANCE_URL, mapper.mapHandler(requestHandler).toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Test(org.junit.Test)

Example 50 with PageProvider

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

the class MountedMapperTest method placeholderEncode4.

/**
 * WICKET-5247 page instantiated without required parameters won't be mapped
 */
@Test
public void placeholderEncode4() {
    PageProvider provider = new PageProvider(MockPage.class) {

        @Override
        public boolean isNewPageInstance() {
            return false;
        }
    };
    provider.setPageSource(context);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = placeholderEncoder.mapHandler(handler);
    assertNull(url);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

PageProvider (org.apache.wicket.core.request.handler.PageProvider)60 Test (org.junit.Test)49 IRequestHandler (org.apache.wicket.request.IRequestHandler)45 Url (org.apache.wicket.request.Url)38 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)36 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)34 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)23 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)17 MockPage (org.apache.wicket.MockPage)16 Page (org.apache.wicket.Page)5 TestMapperContext (org.apache.wicket.core.request.mapper.TestMapperContext)4 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 WebPage (org.apache.wicket.markup.html.WebPage)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)3 MockPageParametersAware (org.apache.wicket.MockPageParametersAware)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ExceptionErrorPage (org.apache.wicket.markup.html.pages.ExceptionErrorPage)2