List of usage examples for org.springframework.web.context WebApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.sakaiproject.tool.gradebook.ui.EntryServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) { WebApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); Authn authnService = (Authn) appContext.getBean("org_sakaiproject_tool_gradebook_facades_Authn"); Authz authzService = (Authz) appContext.getBean("org_sakaiproject_tool_gradebook_facades_Authz"); ContextManagement contextMgm = (ContextManagement) appContext .getBean("org_sakaiproject_tool_gradebook_facades_ContextManagement"); authnService.setAuthnContext(request); String gradebookUid = contextMgm.getGradebookUid(request); try {/*from w ww .j a va 2 s .c o m*/ if (gradebookUid != null) { StringBuilder path = new StringBuilder(request.getContextPath()); if (authzService.isUserAbleToGrade(gradebookUid)) { if (logger.isDebugEnabled()) logger.debug("Sending user to the overview page"); path.append("/overview.jsf"); } else if (authzService.isUserAbleToViewOwnGrades(gradebookUid)) { if (logger.isDebugEnabled()) logger.debug("Sending user to the student view page"); path.append("/studentView.jsf"); } else { // The role filter has not been invoked yet, so this could happen here // throw new RuntimeException("User " + authnService.getUserUid() + " attempted to access gradebook " + gradebookUid + " without any role"); path.append("/noRole.jsp"); } String queryString = request.getQueryString(); if (queryString != null) { path.append("?").append(queryString); } response.sendRedirect(path.toString()); } } catch (IOException ioe) { logger.fatal("Could not redirect user: " + ioe); } }
From source file:org.sipfoundry.sipxconfig.cmcprov.ProvisioningServlet.java
@Override public void init() { if (s_context == null) { ServletContext ctx = getServletContext(); ServletContext sipxconfigCtx = ctx.getContext(SIPXCONFIG_SERVLET_PATH); WebApplicationContext webContext = WebApplicationContextUtils .getRequiredWebApplicationContext(sipxconfigCtx); CoreContext sipxCoreContext = ((CoreContext) (webContext.getBean(CORE_CONTEXT_BEAN_NAME))); PhoneContext sipxPhoneContext = ((PhoneContext) (webContext.getBean(PHONE_CONTEXT_BEAN_NAME))); Upload sipxUpload = ((Upload) (webContext.getBean(UPLOAD_BEAN_NAME))); s_context = new ProvisioningContextImpl(); s_context.setSipxCoreContext(sipxCoreContext); s_context.setSipxPhoneContext(sipxPhoneContext); s_context.setSipxUpload(sipxUpload); }// w w w . j a va 2 s. co m }
From source file:org.springframework.extensions.webscripts.jsf.UIWebScript.java
/** * Default constructor/*from w w w . j a va 2s . com*/ */ public UIWebScript() { WebApplicationContext ctx = FacesContextUtils .getRequiredWebApplicationContext(FacesContext.getCurrentInstance()); // TODO: refer to appropriate container this.container = (RuntimeContainer) ctx.getBean("webscripts.container"); }
From source file:org.springframework.extensions.webscripts.portlet.WebScriptPortlet.java
public void init(PortletConfig config) throws PortletException { initScriptUrl = config.getInitParameter("scriptUrl"); PortletContext portletCtx = config.getPortletContext(); WebApplicationContext context = (WebApplicationContext) portletCtx .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); container = (RuntimeContainer) context.getBean("webscripts.container"); // retrieve authenticator factory via servlet initialisation parameter String authenticatorId = config.getInitParameter("authenticator"); if (authenticatorId != null && authenticatorId.length() > 0) { Object bean = context.getBean(authenticatorId); if (bean == null || !(bean instanceof PortletAuthenticatorFactory)) { throw new PortletException( "Initialisation parameter 'authenticator' does not refer to a portlet authenticator factory (" + authenticatorId + ")"); }/*from w ww . j a v a 2s .c o m*/ authenticatorFactory = (PortletAuthenticatorFactory) bean; } }
From source file:org.springframework.web.jsf.el.WebApplicationContextFacesELResolver.java
@Override @Nullable/* w w w .j ava 2 s .c om*/ public Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext) { WebApplicationContext wac = (WebApplicationContext) base; String beanName = property.toString(); if (logger.isTraceEnabled()) { logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext"); } if (wac.containsBean(beanName)) { if (logger.isDebugEnabled()) { logger.debug( "Successfully resolved property '" + beanName + "' in root WebApplicationContext"); } elContext.setPropertyResolved(true); try { return wac.getBean(beanName); } catch (BeansException ex) { throw new ELException(ex); } } else { // Mimic standard JSF/JSP behavior when base is a Map by returning null. return null; } } } else { if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) { elContext.setPropertyResolved(true); return getWebApplicationContext(elContext); } } return null; }
From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java
private static RequestMappingInfoHandlerMapping getRequestMappingInfoHandlerMapping() { WebApplicationContext wac = getWebApplicationContext(); Assert.notNull(wac, "Cannot lookup handler method mappings without WebApplicationContext"); try {/*w w w . j a v a 2 s. c om*/ return wac.getBean(RequestMappingInfoHandlerMapping.class); } catch (NoUniqueBeanDefinitionException ex) { throw new IllegalStateException("More than one RequestMappingInfoHandlerMapping beans found", ex); } catch (NoSuchBeanDefinitionException ex) { throw new IllegalStateException("No RequestMappingInfoHandlerMapping bean", ex); } }
From source file:org.unitime.timetable.api.ApiServlet.java
protected ApiConnector getConnector(HttpServletRequest request) { WebApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(getServletContext()); return (ApiConnector) applicationContext.getBean(getReference(request)); }
From source file:org.unitime.timetable.export.ExportServlet.java
protected Exporter getExporter(String reference) { WebApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(getServletContext()); return (Exporter) applicationContext.getBean("org.unitime.timetable.export.Exporter:" + reference); }
From source file:org.unitime.timetable.gwt.command.server.GwtRpcServlet.java
protected PermissionCheck getPermissionCheck() { WebApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(getServletContext()); return (PermissionCheck) applicationContext.getBean("unitimePermissionCheck"); }
From source file:org.webcurator.auth.WCTAuthenticationProcessingFilter.java
/** @see org.acegisecurity.ui.AbstractProcessingFilter#onSuccessfulAuthentication(HttpServletRequest,HttpServletResponse, Authentication) . */ protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException { log.debug("calling onSuccessfulAuthentication for WCT"); String userName = authResult.getName(); User wctUser = authDAO.getUserByName(userName); if (wctUser != null) { log.debug("loaded WCT User object " + wctUser.getUsername() + " from database"); UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) SecurityContextHolder .getContext().getAuthentication(); auth.setDetails(wctUser);//from w ww.j a v a 2s . com log.debug("pushing back upat into SecurityContext with populated WCT User"); SecurityContextHolder.getContext().setAuthentication(auth); //audit successful login event auditor.audit(User.class.getName(), wctUser.getOid(), Auditor.ACTION_LOGIN_SUCCESS, "Successful Login for username: " + wctUser.getUsername()); // Get the Spring Application Context. WebApplicationContext ctx = ApplicationContextFactory.getWebApplicationContext(); // set or re-set the page size cookie.. // ..first get the value of the page size cookie String currentPageSize = CookieUtils.getPageSize(request); // ..then refresh the page size cookie, to expire in a year CookieUtils.setPageSize(response, currentPageSize); // set login for duration String sessionId = request.getSession().getId(); LogonDurationDAO logonDurationDAO = (LogonDurationDAO) ctx.getBean(Constants.BEAN_LOGON_DURATION_DAO); logonDurationDAO.setLoggedIn(sessionId, new Date(), wctUser.getOid(), wctUser.getUsername(), wctUser.getNiceName()); // Check previous records of duration logonDurationDAO.setProperLoggedoutForCurrentUser(wctUser.getOid(), sessionId); } else { //audit successful login but unsucessful load of WCT User event auditor.audit(User.class.getName(), Auditor.ACTION_LOGIN_FAILURE_NO_USER, "Un-successful login for username: " + userName + " as user doesn't exist in the WCT System."); } }