List of usage examples for org.apache.wicket.resource.loader IStringResourceLoader IStringResourceLoader
IStringResourceLoader
From source file:gr.abiss.calipso.wicket.CalipsoApplication.java
License:Open Source License
@Override public void init() { super.init(); // DEVELOPMENT or DEPLOYMENT RuntimeConfigurationType configurationType = this.getConfigurationType(); if (RuntimeConfigurationType.DEVELOPMENT.equals(configurationType)) { logger.info("You are in DEVELOPMENT mode"); // getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND); // getDebugSettings().setComponentUseCheck(true); getResourceSettings().setResourcePollFrequency(null); getDebugSettings().setComponentUseCheck(false); // getDebugSettings().setSerializeSessionAttributes(true); // getMarkupSettings().setStripWicketTags(false); // getExceptionSettings().setUnexpectedExceptionDisplay( // UnexpectedExceptionDisplay.SHOW_EXCEPTION_PAGE); // getAjaxSettings().setAjaxDebugModeEnabled(true); } else if (RuntimeConfigurationType.DEPLOYMENT.equals(configurationType)) { getResourceSettings().setResourcePollFrequency(null); getDebugSettings().setComponentUseCheck(false); // getDebugSettings().setSerializeSessionAttributes(false); // getMarkupSettings().setStripWicketTags(true); // getExceptionSettings().setUnexpectedExceptionDisplay( // UnexpectedExceptionDisplay.SHOW_INTERNAL_ERROR_PAGE); // getAjaxSettings().setAjaxDebugModeEnabled(false); }//w w w . j av a2 s .c o m // initialize velocity try { Velocity.init(); if (logger.isInfoEnabled()) { logger.info("Initialized Velocity engine"); } } catch (Exception e) { // TODO Auto-generated catch block logger.error("Failed to initialize velocity engine", e); } // Set custom page for internal errors getApplicationSettings().setInternalErrorPage(CalipsoErrorPage.class); // don't break down on missing resources getResourceSettings().setThrowExceptionOnMissingResource(false); // Redirect to PageExpiredError Page if current page is expired getApplicationSettings().setPageExpiredErrorPage(CalipsoPageExpiredErrorPage.class); // get hold of spring managed service layer (see BasePage, BasePanel etc // for how it is used) ServletContext sc = getServletContext(); applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); calipsoService = (CalipsoService) applicationContext.getBean("calipsoService"); calipsoPropertiesEditor = new CalipsoPropertiesEditor(); // check if acegi-cas authentication is being used, get reference to // object to be used // by wicket authentication to redirect to right pages for login / // logout try { calipsoCasProxyTicketValidator = (CalipsoCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info("casProxyTicketValidator retrieved from application context: " + calipsoCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.info( "casProxyTicketValidator not found in application context, CAS single-sign-on is not being used"); } // delegate wicket i18n support to spring i18n getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { return applicationContext.getMessage(key, null, null, locale); } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { return applicationContext.getMessage(key, null, null, locale); } }); // add DB i18n resources getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { if (StringUtils.isNotBlank(locale.getVariant())) { // always ignore the variant locale = new Locale(locale.getLanguage(), locale.getCountry()); } String lang = locale.getLanguage(); I18nStringResource resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, lang)); if (resource == null && !lang.equalsIgnoreCase("en")) { resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, "en")); } return resource != null ? resource.getValue() : null; } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { locale = component == null ? Session.get().getLocale() : component.getLocale(); if (StringUtils.isNotBlank(locale.getVariant())) { // always ignore the variant locale = new Locale(locale.getLanguage(), locale.getCountry()); } String lang = locale.getLanguage(); I18nStringResource resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, lang)); if (resource == null && !lang.equalsIgnoreCase("en")) { resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, "en")); } return resource != null ? resource.getValue() : null; } }); // cache resources. resource cache is cleared when creating/updating a space getResourceSettings().getLocalizer().setEnableCache(true); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { @Override public boolean isActionAuthorized(Component c, Action a) { return true; } @Override public boolean isInstantiationAuthorized(Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (((CalipsoSession) Session.get()).isAuthenticated()) { return true; } if (calipsoCasProxyTicketValidator != null) { // attempt CAS authentication // ========================== // logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { // logger.debug("security context contains CAS authentication, initializing session"); ((CalipsoSession) Session.get()).setUser((User) authentication.getPrincipal()); return true; } } // attempt remember-me auto login // ========================== if (attemptRememberMeAutoLogin()) { return true; } // attempt *anonymous* guest access if there are // spaces that allow it if (((CalipsoSession) Session.get()).getUser() == null) { List<Space> anonymousSpaces = getCalipso().findSpacesWhereAnonymousAllowed(); if (anonymousSpaces.size() > 0) { // logger.debug("Found "+anonymousSpaces.size() // + // " anonymousSpaces allowing ANONYMOUS access, initializing anonymous user"); User guestUser = new User();//getCalipso().loadUser(2); guestUser.setLoginName("guest"); guestUser.setName("Anonymous"); guestUser.setLastname("Guest"); guestUser.setLocale(Session.get().getLocale().getLanguage()); getCalipso().initImplicitRoles(guestUser, anonymousSpaces, RoleType.ANONYMOUS); // store user in session ((CalipsoSession) Session.get()).setUser(guestUser); return true; } else { if (logger.isDebugEnabled()) { // logger.debug("Found no public spaces."); } } } // allow registration if (clazz.equals(RegisterUserFormPage.class)) { return true; } // not authenticated, go to login page // logger.debug("not authenticated, forcing login, page requested was " // + clazz.getName()); if (calipsoCasProxyTicketValidator != null) { String serviceUrl = calipsoCasProxyTicketValidator.getLoginUrl(); // .getServiceProperties().getService(); String loginUrl = calipsoCasProxyTicketValidator.getLoginUrl(); // logger.debug("cas authentication: service URL: " // + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; // logger.debug("attempting to redirect to: " + // redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); // TODO: create friendly URLs for all created pages // friendly URLs for selected pages if (calipsoCasProxyTicketValidator != null) { mountPage("/login", CasLoginPage.class); } else { mountPage("/login", LoginPage.class); } mountPage("/register", RegisterAnonymousUserFormPage.class); mountPage("/logout", LogoutPage.class); mountPage("/svn", SvnStatsPage.class); mountPage("/test", TestPage.class); mountPage("/casError", CasLoginErrorPage.class); mountPage("/item/", ItemViewPage.class); mountPage("/item/${itemId}", ItemViewPage.class); mountPage("/itemreport/", ItemTemplateViewPage.class); mountPage("/newItem/${spaceCode}", NewItemPage.class); // MixedParamUrlCodingStrategy newItemUrls = new MixedParamUrlCodingStrategy( // "/newItem", // NewItemPage.class, // new String[]{"spaceCode"} // ); // mount(newItemUrls); //fix for tinyMCE bug, see https://github.com/wicketstuff/core/issues/113 SecurePackageResourceGuard guard = (SecurePackageResourceGuard) getResourceSettings() .getPackageResourceGuard(); guard.addPattern("+*.htm"); this.getRequestCycleSettings().setTimeout(Duration.minutes(6)); this.getPageSettings().setVersionPagesByDefault(true); this.getExceptionSettings().setThreadDumpStrategy(ThreadDumpStrategy.THREAD_HOLDING_LOCK); }
From source file:info.jtrac.wicket.JtracApplication.java
License:Apache License
@Override public void init() { super.init(); /*// ww w. j av a 2 s . c om * Get hold of spring managed service layer (see BasePage, BasePanel, * etc. for how it is used). */ ServletContext sc = getServletContext(); applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); jtrac = (Jtrac) applicationContext.getBean("jtrac"); /* * Check if acegi-cas authentication is being used, get reference to * object to be used by Wicket authentication to redirect to right * pages for login/logout. */ try { jtracCasProxyTicketValidator = (JtracCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info("casProxyTicketValidator retrieved from application " + "context: " + jtracCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.debug(nsbde.getMessage()); logger.info("casProxyTicketValidator not found in application " + "context, CAS single-sign-on is not being used"); } /* * Delegate Wicket i18n support to spring i18n */ getResourceSettings().addStringResourceLoader(new IStringResourceLoader() { /* (non-Javadoc) * @see org.apache.wicket.resource.loader.IStringResourceLoader#loadStringResource(java.lang.Class, java.lang.String, java.util.Locale, java.lang.String) */ @Override public String loadStringResource(@SuppressWarnings("rawtypes") Class clazz, String key, Locale locale, String style) { try { return applicationContext.getMessage(key, null, locale == null ? Session.get().getLocale() : locale); } catch (Exception e) { /* * For performance, Wicket expects null instead of * throwing an exception and Wicket may try to * re-resolve using prefixed variants of the key. */ return null; } } /* (non-Javadoc) * @see org.apache.wicket.resource.loader.IStringResourceLoader#loadStringResource(org.apache.wicket.Component, java.lang.String) */ @Override public String loadStringResource(Component component, String key) { String value = loadStringResource(null, key, component == null ? null : component.getLocale(), null); if (logger.isDebugEnabled() && value == null) { logger.debug("i18n failed for key: '" + key + "', component: " + component); } return value; } }); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { /* (non-Javadoc) * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component, org.apache.wicket.authorization.Action) */ @Override public boolean isActionAuthorized(Component c, Action a) { return true; } /* (non-Javadoc) * @see org.apache.wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class) */ @Override public boolean isInstantiationAuthorized(@SuppressWarnings("rawtypes") Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (JtracSession.get().isAuthenticated()) { return true; } if (jtracCasProxyTicketValidator != null) { /* * ============================================ * Attempt CAS authentication * ============================================ */ logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { logger.debug("security context contains CAS authentication, initializing session"); JtracSession.get().setUser((User) authentication.getPrincipal()); return true; } } /* * ================================================ * Attempt remember-me auto login * ================================================ */ if (attemptRememberMeAutoLogin()) { return true; } /* * ================================================= * Attempt guest access if there are "public" spaces * ================================================= */ List<Space> spaces = getJtrac().findSpacesWhereGuestAllowed(); if (spaces.size() > 0) { logger.debug(spaces.size() + " public space(s) available, initializing guest user"); User guestUser = new User(); guestUser.setLoginName("guest"); guestUser.setName("Guest"); for (Space space : spaces) { guestUser.addSpaceWithRole(space, Role.ROLE_GUEST); } JtracSession.get().setUser(guestUser); // and proceed return true; } /* * Not authenticated, go to login page. */ logger.debug("not authenticated, forcing login, " + "page requested was " + clazz.getName()); if (jtracCasProxyTicketValidator != null) { String serviceUrl = jtracCasProxyTicketValidator.getServiceProperties().getService(); String loginUrl = jtracCasProxyTicketValidator.getLoginUrl(); logger.debug("cas authentication: service URL: " + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; logger.debug("attempting to redirect to: " + redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); /* * Friendly URLs for selected pages */ if (jtracCasProxyTicketValidator != null) { mountBookmarkablePage("/login", CasLoginPage.class); /* * This matches the value set in: * WEB-INF/applicationContext-acegi-cas.xml */ mountBookmarkablePage("/cas/error", CasLoginErrorPage.class); } else { mountBookmarkablePage("/login", LoginPage.class); } mountBookmarkablePage("/logout", LogoutPage.class); mountBookmarkablePage("/svn", SvnStatsPage.class); mountBookmarkablePage("/options", OptionsPage.class); mountBookmarkablePage("/item/form", ItemFormPage.class); /* * Bookmarkable URL for search and search results */ mount(new QueryStringUrlCodingStrategy("/item/search", ItemSearchFormPage.class)); mount(new QueryStringUrlCodingStrategy("/item/list", ItemListPage.class)); /* * Bookmarkable URL for viewing items */ mount(new IndexedParamUrlCodingStrategy("/item", ItemViewPage.class)); }
From source file:main.java.info.jtrac.wicket.JtracApplication.java
License:Apache License
@Override public void init() { super.init(); // get hold of spring managed service layer (see BasePage, BasePanel etc for how it is used) ServletContext sc = getServletContext(); // applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); jtrac = (Jtrac) applicationContext.getBean("jtrac"); // check if acegi-cas authentication is being used, get reference to object to be used // by wicket authentication to redirect to right pages for login / logout try {//from w ww . j a va 2 s.c o m jtracCasProxyTicketValidator = (JtracCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info( "casProxyTicketValidator retrieved from application context: " + jtracCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.info( "casProxyTicketValidator not found in application context, CAS single-sign-on is not being used"); } // delegate wicket i18n support to spring i18n getResourceSettings().addStringResourceLoader(new IStringResourceLoader() { public String loadStringResource(Class clazz, String key, Locale locale, String style) { try { return applicationContext.getMessage(key, null, locale); } catch (Exception e) { // have to return null so that wicket can try to resolve again // e.g. without prefixing component id etc. if (logger.isDebugEnabled()) { logger.debug("i18n failed for key: '" + key + "', Class: " + clazz + ", Style: " + style + ", Exception: " + e); } return null; } } public String loadStringResource(Component component, String key) { Class clazz = component == null ? null : component.getClass(); Locale locale = component == null ? Session.get().getLocale() : component.getLocale(); return loadStringResource(clazz, key, locale, null); } }); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { public boolean isActionAuthorized(Component c, Action a) { return true; } public boolean isInstantiationAuthorized(Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (((JtracSession) Session.get()).isAuthenticated()) { return true; } if (jtracCasProxyTicketValidator != null) { // attempt CAS authentication ========================== logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { logger.debug("security context contains CAS authentication, initializing session"); ((JtracSession) Session.get()).setUser((User) authentication.getPrincipal()); return true; } } // attempt remember-me auto login ========================== if (attemptRememberMeAutoLogin()) { return true; } // attempt guest access if there are "public" spaces ======= List<Space> spaces = getJtrac().findSpacesWhereGuestAllowed(); if (spaces.size() > 0) { logger.debug(spaces.size() + " public space(s) available, initializing guest user"); User guestUser = new User(); guestUser.setLoginName("guest"); guestUser.setName("Guest"); guestUser.addSpaceWithRole(null, "ROLE_GUEST"); for (Space space : spaces) { guestUser.addSpaceWithRole(space, "ROLE_GUEST"); } ((JtracSession) Session.get()).setUser(guestUser); // and proceed return true; } // not authenticated, go to login page logger.debug("not authenticated, forcing login, page requested was " + clazz.getName()); if (jtracCasProxyTicketValidator != null) { String serviceUrl = jtracCasProxyTicketValidator.getServiceProperties().getService(); String loginUrl = jtracCasProxyTicketValidator.getLoginUrl(); logger.debug("cas authentication: service URL: " + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; logger.debug("attempting to redirect to: " + redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); // friendly urls for selected pages if (jtracCasProxyTicketValidator != null) { mountBookmarkablePage("/login", CasLoginPage.class); } else { mountBookmarkablePage("/login", LoginPage.class); } mountBookmarkablePage("/logout", LogoutPage.class); mountBookmarkablePage("/svn", SvnStatsPage.class); mountBookmarkablePage("/test", TestPage.class); mountBookmarkablePage("/casError", CasLoginErrorPage.class); // bookmarkable url for viewing items mount(new IndexedParamUrlCodingStrategy("/item", ItemViewPage.class)); }
From source file:net.rrm.ehour.ui.common.BaseSpringWebAppTester.java
License:Open Source License
protected final void bypassStringResourceLoading() { webApp.getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override// www . j ava2 s .c o m public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { return key; } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { return key; } }); }
From source file:org.hippoecm.frontend.Main.java
License:Apache License
@Override protected void init() { super.init(); addRequestCycleListeners();//from www.j a v a 2 s. c om registerSessionListeners(); getPageSettings().setVersionPagesByDefault(false); // getPageSettings().setAutomaticMultiWindowSupport(false); // getSessionSettings().setPageMapEvictionStrategy(new LeastRecentlyAccessedEvictionStrategy(1)); getApplicationSettings().setPageExpiredErrorPage(PageExpiredErrorPage.class); try { String cfgParam = getConfigurationParameter(MAXUPLOAD_PARAM, null); if (cfgParam != null && cfgParam.trim().length() > 0) { getApplicationSettings().setDefaultMaximumUploadSize(Bytes.valueOf(cfgParam)); } } catch (StringValueConversionException ex) { log.warn("Unable to parse number as specified by " + MAXUPLOAD_PARAM, ex); } final IClassResolver originalResolver = getApplicationSettings().getClassResolver(); getApplicationSettings().setClassResolver(new IClassResolver() { @Override public Class resolveClass(String name) throws ClassNotFoundException { if (Session.exists()) { UserSession session = UserSession.get(); ClassLoader loader = session.getClassLoader(); if (loader != null) { return session.getClassLoader().loadClass(name); } } return originalResolver.resolveClass(name); } @Override public Iterator<URL> getResources(String name) { List<URL> resources = new LinkedList<>(); for (Iterator<URL> iter = originalResolver.getResources(name); iter.hasNext();) { resources.add(iter.next()); } if (Session.exists()) { UserSession session = UserSession.get(); ClassLoader loader = session.getClassLoader(); if (loader != null) { try { for (Enumeration<URL> resourceEnum = session.getClassLoader() .getResources(name); resourceEnum.hasMoreElements();) { resources.add(resourceEnum.nextElement()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return resources.iterator(); } @Override public ClassLoader getClassLoader() { return Main.class.getClassLoader(); } }); final IResourceSettings resourceSettings = getResourceSettings(); // replace current loaders with own list, starting with component-specific List<IStringResourceLoader> loaders = resourceSettings.getStringResourceLoaders(); loaders.add(new ClassFromKeyStringResourceLoader()); loaders.add(new IStringResourceLoader() { @Override public String loadStringResource(final Class<?> clazz, final String key, final Locale locale, final String style, final String variation) { return null; } @Override public String loadStringResource(final Component component, String key, final Locale locale, final String style, final String variation) { if (key.contains(",")) { key = key.substring(0, key.lastIndexOf(',')); return resourceSettings.getLocalizer().getStringIgnoreSettings(key, component, null, locale, style, variation); } return null; } }); if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) { resourceSettings.setCachingStrategy(new NoOpResourceCachingStrategy()); } else { resourceSettings.setCachingStrategy( new FilenameWithVersionResourceCachingStrategy(new LastModifiedResourceVersion())); } mount(new MountMapper("binaries", new IMountedRequestMapper() { @Override public IRequestHandler mapRequest(final Request request, final MountParameters mountParams) { String path = Strings.join("/", request.getUrl().getSegments()); try { javax.jcr.Session subSession = UserSession.get().getJcrSession(); Node node = ((HippoWorkspace) subSession.getWorkspace()).getHierarchyResolver() .getNode(subSession.getRootNode(), path); // YUCK: no exception! if (node == null) { log.info("no binary found at " + path); } else { if (node.isNodeType(HippoNodeType.NT_DOCUMENT)) { node = (Node) JcrHelper.getPrimaryItem(node); } return new JcrResourceRequestHandler(node); } } catch (PathNotFoundException e) { log.info("binary not found " + e.getMessage()); } catch (javax.jcr.LoginException ex) { log.warn(ex.getMessage()); } catch (RepositoryException ex) { log.error(ex.getMessage()); } return null; } @Override public int getCompatibilityScore(final Request request) { return 1; } @Override public Mount mapHandler(final IRequestHandler requestHandler) { return null; } })); String applicationName = getPluginApplicationName(); if (PLUGIN_APPLICATION_VALUE_CMS.equals(applicationName)) { // the following is only applicable and needed for the CMS application, not the Console /* * HST SAML kind of authentication handler needed for Template Composer integration * */ cmsContextService = (CmsInternalCmsContextService) HippoServiceRegistry .getService(CmsContextService.class); if (cmsContextService == null) { cmsContextServiceImpl = new CmsContextServiceImpl(); cmsContextService = cmsContextServiceImpl; HippoServiceRegistry.registerService(cmsContextServiceImpl, new Class[] { CmsContextService.class, CmsInternalCmsContextService.class }); } mount(new MountMapper("auth", new IMountedRequestMapper() { @Override public IRequestHandler mapRequest(final Request request, final MountParameters mountParams) { IRequestHandler requestTarget = new RenderPageRequestHandler( new PageProvider(getHomePage(), null), RedirectPolicy.AUTO_REDIRECT); IRequestParameters requestParameters = request.getRequestParameters(); final List<StringValue> cmsCSIDParams = requestParameters.getParameterValues("cmsCSID"); final List<StringValue> destinationPathParams = requestParameters .getParameterValues("destinationPath"); final String destinationPath = destinationPathParams != null && !destinationPathParams.isEmpty() ? destinationPathParams.get(0).toString() : null; PluginUserSession userSession = (PluginUserSession) Session.get(); final UserCredentials userCredentials = userSession.getUserCredentials(); HttpSession httpSession = ((ServletWebRequest) request).getContainerRequest().getSession(); final CmsSessionContext cmsSessionContext = CmsSessionContext.getContext(httpSession); if (destinationPath != null && destinationPath.startsWith("/") && (cmsSessionContext != null || userCredentials != null)) { requestTarget = new IRequestHandler() { @Override public void respond(IRequestCycle requestCycle) { String destinationUrl = RequestUtils.getFarthestUrlPrefix(request) + destinationPath; WebResponse response = (WebResponse) RequestCycle.get().getResponse(); String cmsCSID = cmsCSIDParams == null ? null : cmsCSIDParams.get(0) == null ? null : cmsCSIDParams.get(0).toString(); if (!cmsContextService.getId().equals(cmsCSID)) { // redirect to destinationURL and include marker that it is a retry. This way // the destination can choose to not redirect for SSO handshake again if it still does not // have a key if (destinationUrl.contains("?")) { response.sendRedirect(destinationUrl + "&retry"); } else { response.sendRedirect(destinationUrl + "?retry"); } return; } String cmsSessionContextId = cmsSessionContext != null ? cmsSessionContext.getId() : null; if (cmsSessionContextId == null) { CmsSessionContext newCmsSessionContext = cmsContextService.create(httpSession); CmsSessionUtil.populateCmsSessionContext(cmsContextService, newCmsSessionContext, userSession); cmsSessionContextId = newCmsSessionContext.getId(); } if (destinationUrl.contains("?")) { response.sendRedirect(destinationUrl + "&cmsCSID=" + cmsContextService.getId() + "&cmsSCID=" + cmsSessionContextId); } else { response.sendRedirect(destinationUrl + "?cmsCSID=" + cmsContextService.getId() + "&cmsSCID=" + cmsSessionContextId); } } @Override public void detach(IRequestCycle requestCycle) { //Nothing to detach. } }; } return requestTarget; } @Override public int getCompatibilityScore(final Request request) { return 0; } @Override public Mount mapHandler(final IRequestHandler requestHandler) { return null; } })); } // caching resource stream locator implementation that allows the class argument to be null. final IResourceStreamLocator resourceStreamLocator = resourceSettings.getResourceStreamLocator(); resourceSettings.setResourceStreamLocator(new IResourceStreamLocator() { @Override public IResourceStream locate(Class<?> clazz, final String path) { if (clazz == null) { clazz = CACHING_RESOURCE_STREAM_LOCATOR_CLASS; } return resourceStreamLocator.locate(clazz, path); } @Override public IResourceStream locate(Class<?> clazz, final String path, final String style, final String variation, final Locale locale, final String extension, final boolean strict) { if (clazz == null) { clazz = CACHING_RESOURCE_STREAM_LOCATOR_CLASS; } return resourceStreamLocator.locate(clazz, path, style, variation, locale, extension, strict); } @Override public IResourceNameIterator newResourceNameIterator(final String path, final Locale locale, final String style, final String variation, final String extension, final boolean strict) { return resourceStreamLocator.newResourceNameIterator(path, locale, style, variation, extension, strict); } }); if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) { // disable cache resourceSettings.getLocalizer().setEnableCache(false); final long timeout = NumberUtils.toLong( getConfigurationParameter(DEVELOPMENT_REQUEST_TIMEOUT_PARAM, null), DEFAULT_DEVELOPMENT_REQUEST_TIMEOUT_MS); if (timeout > 0L) { log.info("Setting wicket request timeout to {} ms.", timeout); getRequestCycleSettings().setTimeout(Duration.milliseconds(timeout)); } // render comments with component class names getDebugSettings().setOutputMarkupContainerClassName(true); // do not render Wicket-specific markup since it can break CSS getMarkupSettings().setStripWicketTags(true); } else { // don't serialize pages for performance setPageManagerProvider(new DefaultPageManagerProvider(this) { @Override protected IPageStore newPageStore(final IDataStore dataStore) { return new AmnesicPageStore(); } }); // don't throw on missing resource resourceSettings.setThrowExceptionOnMissingResource(false); // don't show exception page getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_NO_EXCEPTION_PAGE); final long timeout = NumberUtils .toLong(getConfigurationParameter(DEPLOYMENT_REQUEST_TIMEOUT_PARAM, null)); if (timeout > 0L) { log.info("Setting wicket request timeout to {} ms.", timeout); getRequestCycleSettings().setTimeout(Duration.milliseconds(timeout)); } } String outputWicketpaths = obtainOutputWicketPathsParameter(); if (outputWicketpaths != null && "true".equalsIgnoreCase(outputWicketpaths)) { getDebugSettings().setOutputComponentPath(true); } final IContextProvider<AjaxRequestTarget, Page> ajaxRequestTargetProvider = getAjaxRequestTargetProvider(); setAjaxRequestTargetProvider(context -> new PluginRequestTarget(ajaxRequestTargetProvider.get(context))); setPageRendererProvider(new IPageRendererProvider() { @Override public PageRenderer get(final RenderPageRequestHandler context) { return new WebPageRenderer(context) { @Override protected BufferedWebResponse renderPage(final Url targetUrl, final RequestCycle requestCycle) { IRequestHandler scheduled = requestCycle.getRequestHandlerScheduledAfterCurrent(); if (scheduled == null) { IRequestablePage page = getPage(); if (page instanceof Home) { Home home = (Home) page; home.processEvents(); home.render(null); } } return super.renderPage(targetUrl, requestCycle); } }; } }); // don't allow public access to any package resource (empty whitelist) by default resourceSettings.setPackageResourceGuard(new WhitelistedClassesResourceGuard()); if (log.isInfoEnabled()) { log.info("Hippo CMS application " + applicationName + " has started"); } }