Search in sources :

Example 1 with PageExpiredException

use of org.apache.wicket.protocol.http.PageExpiredException in project wicket by apache.

the class CryptoMapper method decryptEntireUrl.

/**
 * Decrypts an entire URL, which was previously encrypted by {@link #encryptEntireUrl(org.apache.wicket.request.Url)}.
 * This method should return {@code null} if the URL is not decryptable.
 *
 * @param request
 *		The request that was made.
 * @param encryptedUrl
 *		The encrypted URL.
 *
 * @return A decrypted form of the URL, or {@code null} if the URL is not decryptable.
 */
protected Url decryptEntireUrl(final Request request, final Url encryptedUrl) {
    Url url = new Url(request.getCharset());
    List<String> encryptedSegments = encryptedUrl.getSegments();
    if (encryptedSegments.isEmpty()) {
        return null;
    }
    /*
		 * The first encrypted segment contains an encrypted version of the entire plain text url.
		 */
    String encryptedUrlString = encryptedSegments.get(0);
    if (Strings.isEmpty(encryptedUrlString)) {
        return null;
    }
    if (getMarkEncryptedUrls()) {
        if (encryptedUrlString.startsWith(ENCRYPTED_URL_MARKER_PREFIX)) {
            encryptedUrlString = encryptedUrlString.substring(ENCRYPTED_URL_MARKER_PREFIX.length());
        } else {
            return null;
        }
    }
    String decryptedUrl;
    try {
        decryptedUrl = getCrypt().decryptUrlSafe(encryptedUrlString);
    } catch (Exception e) {
        log.error("Error decrypting URL", e);
        return null;
    }
    if (decryptedUrl == null) {
        if (getMarkEncryptedUrls()) {
            throw new PageExpiredException("Encrypted URL is no longer decryptable");
        } else {
            return null;
        }
    }
    Url originalUrl = Url.parse(decryptedUrl, request.getCharset());
    int originalNumberOfSegments = originalUrl.getSegments().size();
    int encryptedNumberOfSegments = encryptedUrl.getSegments().size();
    if (originalNumberOfSegments > 0) {
        /*
			 * This should always be true. Home page URLs are the only ones without
			 * segments, and we don't encrypt those with this method.
			 * 
			 * We always add the first segment of the URL, because we encrypt a URL like:
			 *	/path/to/something
			 * to:
			 *	/encrypted_full/hash/hash
			 * 
			 * Notice the consistent number of segments. If we applied the following relative URL:
			 *	../../something
			 * then the resultant URL would be:
			 *	/something
			 * 
			 * Hence, the mere existence of the first, encrypted version of complete URL, segment
			 * tells us that the first segment of the original URL is still to be used.
			 */
        url.getSegments().add(originalUrl.getSegments().get(0));
    }
    HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString);
    int segNo = 1;
    for (; segNo < encryptedNumberOfSegments; segNo++) {
        if (segNo >= originalNumberOfSegments) {
            break;
        }
        String next = generator.next();
        String encryptedSegment = encryptedSegments.get(segNo);
        if (!next.equals(encryptedSegment)) {
            /*
				 * This segment received from the browser is not the same as the expected segment generated
				 * by the HashSegmentGenerator. Hence it, and all subsequent segments are considered plain
				 * text siblings of the original encrypted url.
				 */
            break;
        }
        /*
			 * This segments matches the expected checksum, so we add the corresponding segment from the
			 * original URL.
			 */
        url.getSegments().add(originalUrl.getSegments().get(segNo));
    }
    /*
		 * Add all remaining segments from the encrypted url as plain text segments.
		 */
    for (; segNo < encryptedNumberOfSegments; segNo++) {
        // modified or additional segment
        url.getSegments().add(encryptedUrl.getSegments().get(segNo));
    }
    url.getQueryParameters().addAll(originalUrl.getQueryParameters());
    // WICKET-4923 additional parameters
    url.getQueryParameters().addAll(encryptedUrl.getQueryParameters());
    return url;
}
Also used : PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) Url(org.apache.wicket.request.Url) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException)

Example 2 with PageExpiredException

use of org.apache.wicket.protocol.http.PageExpiredException in project projectforge by micromata.

the class WicketApplication method init.

@Override
protected void init() {
    super.init();
    getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext));
    // Wicket workaround for not be able to proxy Kotlin base SpringBeans:
    WicketSupport.register(applicationContext);
    WebRegistry.getInstance().init();
    pluginAdminService.initializeActivePlugins();
    setDefaultPage(TeamCalCalendarPage.class);
    addResourceBundle(RESOURCE_BUNDLE_NAME);
    addPluginResources();
    getResourceSettings().getStringResourceLoaders().add(new ExternalResourceLoader());
    // Own error page for deployment mode and UserException and AccessException.
    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        /**
         * Log only non ProjectForge exceptions.
         *
         * @see org.apache.wicket.request.cycle.AbstractRequestCycleListener#onException(org.apache.wicket.request.cycle.RequestCycle,
         *      java.lang.Exception)
         */
        @Override
        public IRequestHandler onException(final RequestCycle cycle, final Exception ex) {
            // in case of expired session, please redirect to home page
            if (ex instanceof PageExpiredException) {
                return super.onException(cycle, ex);
            }
            // log StalePageException but do not redirect to error page
            if (ex instanceof StalePageException) {
                log.warn(ex.toString());
                return super.onException(cycle, ex);
            }
            final Throwable rootCause = ExceptionHelper.getRootCause(ex);
            // log.error(rootCause.getMessage(), ex);
            // if (rootCause instanceof ProjectForgeException == false) {
            // return super.onException(cycle, ex);
            // }
            // return null;
            log.error(ex.getMessage(), ex);
            if (isDevelopmentSystem() == true) {
                if (rootCause instanceof SQLException) {
                    SQLException next = (SQLException) rootCause;
                    while ((next = next.getNextException()) != null) {
                        log.error(next.getMessage(), next);
                    }
                }
                return super.onException(cycle, ex);
            } else {
                // Show always this error page in production mode:
                return new RenderPageRequestHandler(new PageProvider(new ErrorPage(ex)));
            }
        }
    });
    getApplicationSettings().setDefaultMaximumUploadSize(Bytes.megabytes(100));
    getMarkupSettings().setDefaultMarkupEncoding("utf-8");
    final MyAuthorizationStrategy authStrategy = new MyAuthorizationStrategy();
    getSecuritySettings().setAuthorizationStrategy(authStrategy);
    getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);
    if (isDevelopmentSystem() == false) {
        // Don't throw MissingResourceException for
        getResourceSettings().setThrowExceptionOnMissingResource(false);
    // missing i18n keys in production mode.
    }
    // Don't show expired page.
    getApplicationSettings().setPageExpiredErrorPage(PageExpiredPage.class);
    // getSessionSettings().setMaxPageMaps(20); // Map up to 20 pages per session (default is 5).
    getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    getApplicationSettings().setInternalErrorPage(ErrorPage.class);
    getRequestCycleSettings().setTimeout(Duration.minutes(Const.WICKET_REQUEST_TIMEOUT_MINUTES));
    // getRequestCycleSettings().setGatherExtendedBrowserInfo(true); // For getting browser width and height.
    // Select2:
    // final ApplicationSettings select2Settings = ApplicationSettings.get();
    // select2Settings.setIncludeJavascript(false);
    // if ("true".equals(System.getProperty(SYSTEM_PROPERTY_HSQLDB_18_UPDATE)) == true) {
    // try {
    // log.info("Send SHUTDOWN COMPACT to upgrade data-base version:");
    // final DataSource dataSource = (DataSource)beanFactory.getBean("dataSource");
    // dataSource.getConnection().createStatement().execute("SHUTDOWN COMPACT");
    // log.fatal("************ PLEASE RESTART APPLICATION NOW FOR PROPER INSTALLATION !!!!!!!!!!!!!! ************");
    // return;
    // } catch (final SQLException ex) {
    // log.fatal("Data-base SHUTDOWN COMPACT failed: " + ex.getMessage());
    // }
    // }
    // Javascript Resource settings
    getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(WicketApplication.class, "scripts/jquery.js"));
    final String configContextPath = domainService.getContextPath();
    WicketUtils.setContextPath(configContextPath);
    for (final Map.Entry<String, Class<? extends WebPage>> mountPage : WebRegistry.getInstance().getMountPages().entrySet()) {
        final String path = mountPage.getKey();
        final Class<? extends WebPage> pageClass = mountPage.getValue();
        mountPageWithPageParameterAwareness(path, pageClass);
        mountedPages.put(pageClass, path);
    }
    if (isDevelopmentSystem() == true) {
        if (isStripWicketTags() == true) {
            log.info("Strip Wicket tags also in development mode at default (see context.xml).");
            Application.get().getMarkupSettings().setStripWicketTags(true);
        }
        getDebugSettings().setOutputMarkupContainerClassName(true);
    }
    try {
        final UserContext internalSystemAdminUserContext = UserContext.__internalCreateWithSpecialUser(DatabaseService.__internalGetSystemAdminPseudoUser());
        // Logon admin user.
        ThreadLocalUserContext.setUserContext(internalSystemAdminUserContext);
        if (databaseService.getSystemUpdater().isUpdated() == false) {
            // Force redirection to update page:
            UserFilter.setUpdateRequiredFirst(true);
        }
    } finally {
        ThreadLocalUserContext.clear();
    }
    // initialize styles compiler
    try {
        final LessWicketApplicationInstantiator lessInstantiator = new LessWicketApplicationInstantiator(this, "styles", "projectforge.less", "projectforge.css", this.baseDir, configurationService.getCompileCss());
        lessInstantiator.instantiate();
    } catch (final Exception e) {
        log.error("Unable to instantiate wicket less compiler", e);
    }
    getPageSettings().setRecreateBookmarkablePagesAfterExpiry(false);
    initPageStore();
}
Also used : WebPage(org.apache.wicket.markup.html.WebPage) SQLException(java.sql.SQLException) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener) StalePageException(org.apache.wicket.core.request.mapper.StalePageException) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) ThreadLocalUserContext(org.projectforge.framework.persistence.user.api.ThreadLocalUserContext) UserContext(org.projectforge.framework.persistence.user.api.UserContext) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) LessWicketApplicationInstantiator(de.micromata.less.LessWicketApplicationInstantiator) StalePageException(org.apache.wicket.core.request.mapper.StalePageException) SQLException(java.sql.SQLException) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) PageProvider(org.apache.wicket.core.request.handler.PageProvider) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PageExpiredException

use of org.apache.wicket.protocol.http.PageExpiredException in project servoy-client by Servoy.

the class WebClientsApplication method newRequestCycleProcessor.

@Override
protected IRequestCycleProcessor newRequestCycleProcessor() {
    return new UrlCompressingWebRequestProcessor() {

        @Override
        public void respond(RequestCycle requestCycle) {
            // execute events from WebClient.invokeLater() before the respond (render) is started
            Session session = Session.get();
            if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) {
                ((WebClientSession) session).getWebClient().executeEvents();
            }
            super.respond(requestCycle);
        }

        /**
         * @see wicket.protocol.http.WebRequestCycleProcessor#newRequestCodingStrategy()
         */
        @Override
        protected IRequestCodingStrategy newRequestCodingStrategy() {
            Settings settings = Settings.getInstance();
            if (// $NON-NLS-1$ //$NON-NLS-2$
            Utils.getAsBoolean(settings.getProperty("servoy.webclient.crypt-urls", "true"))) {
                return new ServoyCryptedUrlWebRequestCodingStrategy(new UrlCompressingWebCodingStrategy());
            } else {
                return new UrlCompressingWebCodingStrategy();
            }
        }

        @Override
        protected IRequestTarget resolveListenerInterfaceTarget(RequestCycle requestCycle, Page page, String componentPath, String interfaceName, RequestParameters requestParameters) {
            try {
                IRequestTarget requestTarget = super.resolveListenerInterfaceTarget(requestCycle, page, componentPath, interfaceName, requestParameters);
                if (requestTarget instanceof BehaviorRequestTarget) {
                    Component target = ((BehaviorRequestTarget) requestTarget).getTarget();
                    if (!(target instanceof Page)) {
                        boolean invalidPage = false;
                        Page page2 = null;
                        try {
                            // test if it has a page.
                            page2 = target.findParent(Page.class);
                        } catch (Exception e) {
                            Debug.trace(e);
                            invalidPage = true;
                        }
                        if (page2 == null || !page2.getId().equals(page.getId())) {
                            invalidPage = true;
                        }
                        if (invalidPage) {
                            // $NON-NLS-1$
                            Debug.log("Couldn't resolve the page of the component, component already gone from page? returning empty");
                            return EmptyRequestTarget.getInstance();
                        }
                    }
                }
                return requestTarget;
            } catch (Exception e) {
                // $NON-NLS-1$
                Debug.log("couldnt resolve interface, component page already gone from page? returning empty");
            }
            return EmptyRequestTarget.getInstance();
        }

        @Override
        public IRequestTarget resolve(final RequestCycle requestCycle, final RequestParameters requestParameters) {
            try {
                return super.resolve(requestCycle, requestParameters);
            } catch (PageExpiredException e) {
                // if there is a page expired exception
                // then ignore it if there is a current form.
                // $NON-NLS-1$
                Debug.trace("Page expired, checking for a current form");
                Request request = requestCycle.getRequest();
                if (request instanceof WebRequest && ((WebRequest) request).isAjax() && requestParameters.isOnlyProcessIfPathActive()) {
                    // $NON-NLS-1$
                    Debug.trace("Page expired, it is an ajan/process only if active request");
                    Session session = Session.get();
                    if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) {
                        WebClient webClient = ((WebClientSession) session).getWebClient();
                        if (webClient.getFormManager().getCurrentForm() != null) {
                            // $NON-NLS-1$
                            Debug.trace("Page expired, there is a current form, ignore this ajax request");
                            return EmptyAjaxRequestTarget.getInstance();
                        }
                    }
                }
                throw e;
            }
        }
    };
}
Also used : RequestCycle(org.apache.wicket.RequestCycle) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) WebRequest(org.apache.wicket.protocol.http.WebRequest) Request(org.apache.wicket.Request) Page(org.apache.wicket.Page) RestartResponseException(org.apache.wicket.RestartResponseException) AbstractRestartResponseException(org.apache.wicket.AbstractRestartResponseException) IOException(java.io.IOException) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) RequestParameters(org.apache.wicket.request.RequestParameters) UrlCompressingWebCodingStrategy(org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebCodingStrategy) BehaviorRequestTarget(org.apache.wicket.request.target.component.listener.BehaviorRequestTarget) WebRequest(org.apache.wicket.protocol.http.WebRequest) IRequestTarget(org.apache.wicket.IRequestTarget) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) Settings(com.servoy.j2db.util.Settings) IWiQuerySettings(org.odlabs.wiquery.core.commons.IWiQuerySettings) IRequestCycleSettings(org.apache.wicket.settings.IRequestCycleSettings) WiQuerySettings(org.odlabs.wiquery.core.commons.WiQuerySettings) UrlCompressingWebRequestProcessor(org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor) Session(org.apache.wicket.Session)

Example 4 with PageExpiredException

use of org.apache.wicket.protocol.http.PageExpiredException in project projectforge by micromata.

the class PageParameterAwareMountedMapper method processHybrid.

@Override
protected IRequestHandler processHybrid(PageInfo pageInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount) {
    IRequestHandler handler = null;
    try {
        handler = super.processHybrid(pageInfo, pageClass, pageParameters, renderCount);
    } catch (PageExpiredException e) {
        // in case of pageExpiredException at this point, we just redirect to previous bookmarkable resource
        return processBookmarkable(pageClass, pageParameters);
    }
    if (handler != null && handler instanceof RenderPageRequestHandler) {
        // in the current implementation (wicket 1.5.6) super.processHybrid
        // returns a RenderPageRequestHandler
        RenderPageRequestHandler renderPageHandler = (RenderPageRequestHandler) handler;
        if (renderPageHandler.getPageProvider() instanceof PageProvider) {
            PageProvider provider = (PageProvider) renderPageHandler.getPageProvider();
            // This check is necessary to prevent a RestartResponseAtInterceptPageException at the wrong time in request cycle
            if (provider.hasPageInstance()) {
                // get page classes
                Class<? extends IRequestablePage> oldPageClass = renderPageHandler.getPageClass();
                Class<? extends IRequestablePage> newPageClass = renderPageHandler.getPageProvider().getPageClass();
                // get page parameters
                PageParameters newPageParameters = renderPageHandler.getPageParameters();
                PageParameters oldPageParameters = renderPageHandler.getPageProvider().getPageInstance().getPageParameters();
                if (oldPageClass != null && oldPageClass.equals(newPageClass) == false) {
                    return processBookmarkable(newPageClass, newPageParameters);
                }
                // to a fresh bookmarkable instance of that page.
                if (!PageParameters.equals(oldPageParameters, newPageParameters)) {
                    return processBookmarkable(newPageClass, newPageParameters);
                }
            }
        }
    }
    return handler;
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters)

Example 5 with PageExpiredException

use of org.apache.wicket.protocol.http.PageExpiredException in project core by wicketstuff.

the class MapperDelegate 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);
    Application application = Application.get();
    provider.setPageSource(application.getMapperContext());
    if (!provider.hasPageInstance() && !application.getPageSettings().getRecreateBookmarkablePagesAfterExpiry()) {
        throw new PageExpiredException(String.format("Bookmarkable page id '%d' class '%s' has expired.", pageInfo.getPageId(), pageClass.getName()));
    }
    return new RenderPageRequestHandler(provider);
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) Application(org.apache.wicket.Application)

Aggregations

PageExpiredException (org.apache.wicket.protocol.http.PageExpiredException)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)3 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)3 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 Settings (com.servoy.j2db.util.Settings)1 LessWicketApplicationInstantiator (de.micromata.less.LessWicketApplicationInstantiator)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractRestartResponseException (org.apache.wicket.AbstractRestartResponseException)1 Application (org.apache.wicket.Application)1 Component (org.apache.wicket.Component)1 IRequestTarget (org.apache.wicket.IRequestTarget)1 Page (org.apache.wicket.Page)1 Request (org.apache.wicket.Request)1 RequestCycle (org.apache.wicket.RequestCycle)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 Session (org.apache.wicket.Session)1