List of usage examples for org.apache.wicket.request.cycle AbstractRequestCycleListener AbstractRequestCycleListener
AbstractRequestCycleListener
From source file:com.evolveum.midpoint.web.security.MidPointApplication.java
License:Apache License
@Override public void init() { super.init(); getComponentInstantiationListeners().add(new SpringComponentInjector(this)); IResourceSettings resourceSettings = getResourceSettings(); resourceSettings.setHeaderItemComparator(new PriorityFirstComparator(true)); resourceSettings.setThrowExceptionOnMissingResource(false); getMarkupSettings().setStripWicketTags(true); getMarkupSettings().setDefaultBeforeDisabledLink(""); getMarkupSettings().setDefaultAfterDisabledLink(""); if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) { getDebugSettings().setAjaxDebugModeEnabled(true); getDebugSettings().setDevelopmentUtilitiesEnabled(true); }//from w ww . j av a2 s . c o m //pretty url for resources (e.g. images) mountFiles(ImgResources.BASE_PATH, ImgResources.class); //exception handling an error pages IApplicationSettings appSettings = getApplicationSettings(); appSettings.setAccessDeniedPage(PageError401.class); appSettings.setInternalErrorPage(PageError.class); appSettings.setPageExpiredErrorPage(PageError.class); mount(new MountedMapper("/error", PageError.class, MidPointPageParametersEncoder.ENCODER)); mount(new MountedMapper("/error/401", PageError401.class, MidPointPageParametersEncoder.ENCODER)); mount(new MountedMapper("/error/403", PageError403.class, MidPointPageParametersEncoder.ENCODER)); mount(new MountedMapper("/error/404", PageError404.class, MidPointPageParametersEncoder.ENCODER)); getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override public IRequestHandler onException(RequestCycle cycle, Exception ex) { return new RenderPageRequestHandler(new PageProvider(new PageError(ex))); } }); // todo wicket atmosphere was disabled because of form file upload and redirection url problems. // //ajax push (just an experiment) // eventBus = new EventBus(this); // eventBus.getParameters().setLogLevel(AtmosphereLogLevel.DEBUG); // // //enable simple task notifications here // taskManager.registerTaskListener(new TaskListener() { // // @Override // public void onTaskStart(Task task) { // EventBus bus = getEventBus(); // bus.post(new NotifyMessage("Task start", WebMiscUtil.getOrigStringFromPoly(task.getName()) + " started.", // OperationResultStatus.SUCCESS)); // } // // @Override // public void onTaskFinish(Task task, TaskRunResult runResult) { // EventBus bus = getEventBus(); // bus.post(new NotifyMessage("Task finish", WebMiscUtil.getOrigStringFromPoly(task.getName()) + " finished.", // OperationResultStatus.parseStatusType(task.getResultStatus()))); // } // // @Override // public void onTaskThreadStart(Task task, boolean isRecovering) { // // } // // @Override // public void onTaskThreadFinish(Task task) { // // } // }); //descriptor loader, used for customization new DescriptorLoader().loadData(this); }
From source file:com.userweave.application.UserWeaveApplication.java
License:Open Source License
@Override public void init() { super.init(); getComponentInstantiationListeners().add(new SpringComponentInjector(this)); setupAuthorization();//from w w w .jav a 2 s . c om mountPages(); mountResources(); getMarkupSettings().setStripWicketTags(true); setupErrorHandling(); setupProductionSettings(); setDefaultResourceLocale(LocalizationUtils.getDefaultLocale()); getMarkupSettings().setMarkupFactory(new MarkupFactory() { @Override public MarkupParser newMarkupParser(MarkupResourceStream resource) { MarkupParser markupParser = new MarkupParser(resource); markupParser.add(new AbstractMarkupFilter() { // @Override // public MarkupElement nextTag() throws ParseException { // // // Get the next tag. If null, no more tags are available // final ComponentTag tag = (ComponentTag)getParent().nextTag(); // if ( null == tag || null != tag.getId() ) // return tag; // // // Process open <html> tags // if( null != tag.getName() && tag.getName().equals( "html" ) && tag.isOpen()) // { // String language = UserWeaveSession.get().getLocale().getLanguage(); // tag.getAttributes().put("lang", language); // tag.getAttributes().put("xml:lang", language); // tag.setModified( true ); // } // // return tag; // } @Override protected MarkupElement onComponentTag(ComponentTag tag) throws ParseException { if (null == tag || null != tag.getId()) { return tag; } // Process open <html> tags if (null != tag.getName() && tag.getName().equals("html") && tag.isOpen()) { String language = UserWeaveSession.get().getLocale().getLanguage(); tag.getAttributes().put("lang", language); tag.getAttributes().put("xml:lang", language); tag.setModified(true); } return tag; } }); return markupParser; } }); /* * @see: migration guide to wicket 1.5 Request cycle * * Instead of overrride newRequestCycle, we have to create a factory, * that builds our custom RequestCycle. */ setRequestCycleProvider(new IRequestCycleProvider() { @Override public RequestCycle get(RequestCycleContext context) { return new UserWeaveWebRequestCycle(context); } }); /* * @see: https://cwiki.apache.org/WICKET/request-mapping.html * * newRequestCycleProcessor is obsolete, so we replace the * CryptedUrlWebRequestCodingStrategy with a CryptoMapper, */ // if(ENCRYPTION) // { // setRootRequestMapper(new CryptoMapper(getRootRequestMapper(), this)); // } // add custom listener for runtime exceptions. getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override public IRequestHandler onException(RequestCycle cycle, Exception ex) { if (ex instanceof RuntimeException) { ((UserWeaveWebRequestCycle) cycle).handleRuntimeException((RuntimeException) ex); } return null; } }); // disable caching strategy getResourceSettings().setCachingStrategy(NoOpResourceCachingStrategy.INSTANCE); }
From source file:com.vanillasource.jaywire.wicket.WicketModule.java
License:Open Source License
private void registerInfrastructure(Application application) { application.getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override/*from w w w . ja va2 s . co m*/ public void onBeginRequest(RequestCycle requestCycle) { if (requestCycle.getRequest() != null && requestCycle.getRequest() instanceof ServletWebRequest) { ServletRequest request = ((ServletWebRequest) requestCycle.getRequest()).getContainerRequest(); getServletRequestScope().setStorage(request); // Force creation of session if (request instanceof HttpServletRequest) { application.getSessionStore().getSessionId(requestCycle.getRequest(), true); Session session = application.fetchCreateAndSetSession(requestCycle); if (session == null) { throw new WicketRuntimeException( "Could not create session, which is necessary for JayWire session scope."); } getHttpSessionScope().setStorage(((HttpServletRequest) request).getSession()); } } } @Override public void onEndRequest(RequestCycle requestCycle) { getHttpSessionScope().clearStorage(); getServletRequestScope().clearStorage(); } }); application.getApplicationListeners().add(new IApplicationListener() { @Override public void onAfterInitialized(Application application) { } @Override public void onBeforeDestroyed(Application application) { try { close(); } catch (Exception e) { throw new WicketRuntimeException("Could not close JayWire module", e); } } }); }
From source file:de.alpharogroup.wicket.base.application.plugins.SecuritySettingsPlugin.java
License:Apache License
/** * Factory method for that can be used to add additional security configuration to this plugin. * <p>// ww w. j a v a 2 s. com * Overrides should call {@code super.onConfigure()}. * * @param application * the application */ protected void onConfigure(final WebApplication application) { set(application, this); application.getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override public void onBeginRequest(final RequestCycle cycle) { super.onBeginRequest(cycle); final WebResponse response = (WebResponse) cycle.getResponse(); // Category: Framing WicketComponentExtensions.setSecurityFramingHeaders(response); // Category: Transport WicketComponentExtensions.setSecurityTransportHeaders(response); // Category: XSS WicketComponentExtensions.setSecurityXSSHeaders(response); // Category: Caching WicketComponentExtensions.setSecurityCachingHeaders(response); } }); }
From source file:de.inren.frontend.application.InRenApplication.java
License:Apache License
@Override public void init() { super.init(); /* Spring injection. */ this.getComponentInstantiationListeners().add(new SpringComponentInjector(this)); /* Performance measurement */ if (false) {/*w ww. j ava 2 s .c o m*/ getComponentInstantiationListeners().add(new RenderPerformanceListener()); } configureBootstrap(); initializeServices(); getSecuritySettings().setAuthorizationStrategy(new MetaDataRoleAuthorizationStrategy(this)); initializeFailSafeLocalize(); new AnnotatedMountScanner().scanPackage("de.inren").mount(this); mountResource("/" + PictureResource.PICTURE_RESOURCE + "/${" + PictureResource.ID + "}/${" + PictureResource.SIZE + "}", PictureResource.asReference()); // Access to Images by url // mount(createImageURIRequestTargetUrlCodingStrategy()); // mount(createLayoutURIRequestTargetUrlCodingStrategy()); // mount(createThumbnailURIRequestTargetUrlCodingStrategy()); // Render hints in html to navigate from firebug to eclipse // WicketSource.configure(this); // TODO gehrt ins codeflower package. => Init fr Wicket // module/packages machen. final IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard(); if (packageResourceGuard instanceof SecurePackageResourceGuard) { ((SecurePackageResourceGuard) packageResourceGuard).addPattern("+*.json"); ((SecurePackageResourceGuard) packageResourceGuard).addPattern("+**.ttf"); } /** for ajax progressbar on upload */ getApplicationSettings().setUploadProgressUpdatesEnabled(true); // I don't like messy html code. this.getMarkupSettings().setStripWicketTags(true); this.getMarkupSettings().setStripComments(true); // This application can be reached from internet, but you must know the // right port. // So I like to know who else besides me tries to connect. getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override public void onBeginRequest(RequestCycle cycle) { WebClientInfo ci = new WebClientInfo(cycle); log.debug("Request info: " + ci.getProperties().getRemoteAddress() + ", " + ("".equals(DnsUtil.lookup(ci.getProperties().getRemoteAddress())) ? "" : DnsUtil.lookup(ci.getProperties().getRemoteAddress()) + ", ") + (cycle.getRequest().getUrl().getPath() == null || "".equals(cycle.getRequest().getUrl().getPath()) ? "" : cycle.getRequest().getUrl().getPath() + ", ") + ci.getUserAgent()); } }); getSecuritySettings().setAuthorizationStrategy(new InRenAuthorizationStrategy()); // MetaDataRoleAuthorizationStrategy.authorize(AdminOnlyPage.class, // Roles.ADMIN); // mountPage("admin", AdminOnlyPage.class); // TODO das funzzt nur auf Class // LIST<COMPONENTACCESS> COMPONENTACCESS = // COMPONENTACCESSSERVICE.GETCOMPONENTACCESSLIST(); // FOR (COMPONENTACCESS CA : COMPONENTACCESS) { // COLLECTION<ROLE> ROLES = CA.GETGRANTEDROLES(); // STRINGBUFFER ROLESTRING = NEW STRINGBUFFER(); // FOR (ROLE ROLE : ROLES) { // ROLESTRING.APPEND(ROLE); // } // METADATAROLEAUTHORIZATIONSTRATEGY.AUTHORIZE(CA.GETNAME(), // ROLESTRING.TOSTRING()); // } }
From source file:eu.esdihumboldt.hale.server.webapp.BaseWebApplication.java
License:Open Source License
@Override public void init() { super.init(); BootstrapSettings settings = new BootstrapSettings(); final ThemeProvider themeProvider = new BootswatchThemeProvider() { {//from w ww.jav a2 s. c o m 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); } } }
From source file:org.apache.directory.fortress.web.ApplicationContext.java
License:Apache License
@Override public void init() { super.init(); getComponentInstantiationListeners().add(new SpringComponentInjector(this)); // Catch runtime exceptions this way: getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override//from w w w. j a v a 2s . c o m public IRequestHandler onException(RequestCycle cycle, Exception e) { return new RenderPageRequestHandler(new PageProvider(new ErrorPage(e))); } }); getMarkupSettings().setStripWicketTags(true); }
From source file:org.cast.isi.ISIApplication.java
License:Open Source License
protected void init() { log.debug("Starting ISI Application Init"); // TODO heikki find out which component requires this, and replace it with something empty in case this is not enabled getDebugSettings().setDevelopmentUtilitiesEnabled(true); // Set xml content Section and Page based on property file - these have to be set before // the super.init is called sectionElement = configuration.getProperty("isi.sectionElement"); pageElement = configuration.getProperty("isi.pageElement"); super.init(); ISIEmailService.useAsServiceInstance(); responseMetadata = new ResponseMetadata(); getMarkupSettings().setDefaultBeforeDisabledLink(""); getMarkupSettings().setDefaultAfterDisabledLink(""); // Strip tags so that jQuery traversal doesn't break getMarkupSettings().setStripWicketTags(true); // Tells ResourceFinder to look in skin directory before looking in context dir. if (getCustomSkinDir() != null) getResourceSettings().addResourceFolder(getCustomSkinDir()); getResourceSettings().addResourceFolder(getSkinDir()); // Content elements are taggable TagService.get().configureTaggableClass('P', ContentElement.class); String requestedTags = configuration.getProperty("isi.defaultTags"); if (StringUtils.isEmpty(requestedTags)) { requestedTags = ""; }//from w w w . j a va2s .c o m if (!Strings.isEmpty(requestedTags)) TagService.get().setDefaultTags(Arrays.asList(requestedTags.split("\\s*,\\s*"))); configureResponseTypes(); configureResponseSort(); // load the xml documents and xsl transformers loadXmlFiles(); loadXslFiles(); // Tell dialog border to not use it's css List<ResourceReference> noStylesheets = Collections.emptyList(); DialogBorder.setStyleReferences(noStylesheets); // TODO heikki: SecurePackageResourceGuard subclasses cause errors for some resources. For the moment, use PackageResourceGuard. //getResourceSettings().setPackageResourceGuard(new ISIPackageResourceGuard()); //getResourceSettings().setPackageResourceGuard(new CwmPackageResourceGuard()); getResourceSettings().setPackageResourceGuard(new PackageResourceGuard()); this.getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override public IRequestHandler onException(RequestCycle cycle, Exception x) { if (x instanceof StalePageException) return null; // use normal exception processing for these PageParameters pageParameters = requestParameters2PageParameters( cycle.getRequest().getQueryParameters()); return new RenderPageRequestHandler( new PageProvider(new ExceptionPage(pageParameters, new RuntimeException(x)))); } }); if (highlightsPanelOn) registerHighlighters(); // Generally helpful log statement. if (!RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) { log.warn("********************** Wicket is running in Deployment Mode **********************"); } log.debug("Finished ISI Application Init"); }
From source file:org.cyclop.web.webapp.WicketWebApplication.java
License:Apache License
private void setupErrorPage() { getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override/*from w w w . ja v a 2 s . com*/ public IRequestHandler onException(RequestCycle cycle, Exception ex) { return new RenderPageRequestHandler(new PageProvider(new ErrorPage(ex))); } }); }
From source file:org.dcm4chee.wizard.WizardApplication.java
License:LGPL
@Override protected void init() { super.init(); getExceptionSettings().setAjaxErrorHandlingStrategy(AjaxErrorStrategy.INVOKE_FAILURE_HANDLER); getRequestCycleListeners().add(new AbstractRequestCycleListener() { public IRequestHandler onException(RequestCycle cycle, Exception e) { // while (e.getCause() != null) // e = (Exception) e.getCause(); // if (!(e instanceof PageExpiredException)) // cycle.setResponsePage(new InternalErrorPage(e, null)); log.error("Unexpected exception in the wizard application: ", e); return cycle.getRequestHandlerScheduledAfterCurrent(); }/* w ww . java2 s. com*/ }); getDicomConfigurationManager(); getTransferCapabilityProfiles(); }