List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException
From source file:org.josso.alfresco.agent.AlfrescoSSOAgentFilter.java
public void init(FilterConfig filterConfig) throws ServletException { // Validate and update our current component state _ctx = filterConfig.getServletContext(); WebApplicationContext webCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(_ctx); _ctx.setAttribute(KEY_SESSION_MAP, new HashMap()); if (_agent == null) { try {/*w w w. j a v a 2s . c o m*/ Lookup lookup = Lookup.getInstance(); lookup.init("josso-agent-config.xml"); // For spring compatibility ... // We need at least an abstract SSO Agent _agent = (HttpSSOAgent) lookup.lookupSSOAgent(); if (logger.isDebugEnabled()) _agent.setDebug(1); _agent.start(); // Publish agent in servlet context filterConfig.getServletContext().setAttribute("org.josso.agent", _agent); } catch (Exception e) { throw new ServletException("Error starting SSO Agent : " + e.getMessage(), e); } } try { this.serviceRegistry = (ServiceRegistry) webCtx.getBean(ServiceRegistry.SERVICE_REGISTRY); this.authenticationService = serviceRegistry.getAuthenticationService(); this.personService = serviceRegistry.getPersonService(); this.permissionService = (PermissionService) webCtx.getBean("PermissionService"); this.authComponent = (AuthenticationComponent) webCtx.getBean("AuthenticationComponent"); this.ticketComponent = (TicketComponent) webCtx.getBean("ticketComponent"); } catch (BeansException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:org.jsecurity.spring.SpringIniWebConfiguration.java
@Override protected SecurityManager createSecurityManager(Map<String, Map<String, String>> sections) { ServletContext servletContext = getFilterConfig().getServletContext(); ApplicationContext appCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); return getOrCreateSecurityManager(appCtx, sections); }
From source file:org.jtalks.jcommune.web.controller.JetmHttpConsoleServlet.java
/** * Invoke servlet initialization only when Spring performance profile is set, otherwise skip it. This skipping is * needed because without it {@code ServletException} will be thrown and servlet container return * HTTP 500 Internal Server Error.//from ww w . j a v a 2 s . c om * * @param aServletConfig the servlet configuration * @throws ServletException */ @Override public void init(ServletConfig aServletConfig) throws ServletException { if (profileIsActive()) { super.init(aServletConfig); WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(servletConfig.getServletContext()); componentService = (ComponentService) ctx.getBean("componentService"); } }
From source file:org.mifos.framework.ApplicationInitializer.java
public void init(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); try {/*from www . ja v a2 s. c o m*/ // prevent ehcache "phone home" System.setProperty("net.sf.ehcache.skipUpdateCheck", "true"); // prevent quartz "phone home" System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true"); synchronized (ApplicationInitializer.class) { ApplicationContext applicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); if (servletContext != null) { dbUpgrade(applicationContext); } initJNDIforPentaho(applicationContext); setAttributesOnContext(servletContext); copyResources(servletContext); } } catch (Exception e) { String errMsgStart = "unable to start Mifos web application"; if (null == logger) { System.err.println(errMsgStart + " and logger is not available!"); e.printStackTrace(); } else { logger.error(errMsgStart, e); } throw new Error(e); } logger.info("Mifos is ready."); }
From source file:org.openehealth.ipf.platform.camel.ihe.xds.iti17.Iti17Servlet.java
private CamelContext getCamelContext() { ServletContext servletContext = getServletContext(); ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); Map<?, ?> camelContextBeans = appContext.getBeansOfType(CamelContext.class); Validate.isTrue(camelContextBeans.size() == 1, "A single camelContext bean is required in the application context"); CamelContext camelContext = (CamelContext) camelContextBeans.values().iterator().next(); Validate.notNull(camelContext, "A single camelContext bean is required in the application context"); return camelContext; }
From source file:org.openhie.openempi.webapp.listener.StartupListener.java
@SuppressWarnings({ "unchecked" }) public void contextInitialized(ServletContextEvent event) { log.debug("Initializing context..."); ServletContext context = event.getServletContext(); // Orion starts Servlets before Listeners, so check if the config // object already exists Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG); if (config == null) { config = new HashMap<String, Object>(); }/*from w w w . j a v a 2s. co m*/ if (context.getInitParameter(Constants.CSS_THEME) != null) { config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME)); } ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); /*String[] beans = ctx.getBeanDefinitionNames(); for (String bean : beans) { log.debug(bean); }*/ PasswordEncoder passwordEncoder = null; try { ProviderManager provider = (ProviderManager) ctx.getBean("_authenticationManager"); for (Object o : provider.getProviders()) { AuthenticationProvider p = (AuthenticationProvider) o; if (p instanceof RememberMeAuthenticationProvider) { config.put("rememberMeEnabled", Boolean.TRUE); } else if (ctx.getBean("passwordEncoder") != null) { passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder"); } } } catch (NoSuchBeanDefinitionException n) { log.debug("authenticationManager bean not found, assuming test and ignoring..."); // ignore, should only happen when testing } context.setAttribute(Constants.CONFIG, config); // output the retrieved values for the Init and Context Parameters if (log.isDebugEnabled()) { log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled")); if (passwordEncoder != null) { log.debug("Password Encoder: " + passwordEncoder.getClass().getName()); } log.debug("Populating drop-downs..."); } setupContext(context); }
From source file:org.openlegacy.web.tiles.OpenLegacyTilesConfigurer.java
private String[] extractDefinitionsFromPlugin() { if (servletContext == null) { return null; }//from w w w .j av a 2s . co m WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); PluginsRegistry pluginsRegistry = wac.getBean(PluginsRegistry.class); if (pluginsRegistry.isEmpty()) { return null; } List<String> viewResources = pluginsRegistry.getViewDeclarations(); return viewResources.toArray(new String[] {}); }
From source file:org.openvpms.web.echo.servlet.DownloadServlet.java
/** * Initialises the servlet./*from w w w. j a v a 2 s. c om*/ * * @throws ServletException for any error */ @Override public void init() throws ServletException { super.init(); ApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); handlers = (DocumentHandlers) context.getBean("documentHandlers"); }
From source file:org.osaf.cosmo.db.DbListener.java
/** * Resolves dependencies using the Spring * <code>WebApplicationContext</code> and performs startup * maintenance tasks.//from w w w. j av a 2s . com */ public void contextInitialized(ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); DbInitializer initializer = (DbInitializer) wac.getBean(BEAN_DB_INITIALIZER, DbInitializer.class); initializer.initialize(); }
From source file:org.osaf.cosmo.filters.UsernameRequestIntegrationFilter.java
public void init(FilterConfig config) throws ServletException { WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); this.securityManager = (CosmoSecurityManager) wac.getBean(BEAN_SECURITY_MANAGER, CosmoSecurityManager.class); if (this.securityManager == null) { throw new ServletException( "Could not initialize HttpLoggingFilter: " + "Could not find security manager."); }/*from w w w . jav a 2 s .c o m*/ }