Java Code Examples for org.springframework.web.context.support.WebApplicationContextUtils

The following are top voted examples for showing how to use org.springframework.web.context.support.WebApplicationContextUtils. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lams   File: TwoFactorAuthenticationAction.java   View source code 7 votes vote down vote up
@Override
   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

WebApplicationContext ctx = WebApplicationContextUtils
	.getWebApplicationContext(getServlet().getServletContext());
UserManagementService userManagementService = (UserManagementService) ctx.getBean("userManagementService");

// check if user needs to get his shared two-factor authorization secret
User loggedInUser = userManagementService.getUserByLogin(request.getRemoteUser());
if (loggedInUser.isTwoFactorAuthenticationEnabled() && loggedInUser.getTwoFactorAuthenticationSecret() == null) {
    
    GoogleAuthenticator gAuth = new GoogleAuthenticator();
    final GoogleAuthenticatorKey key = gAuth.createCredentials();
    String sharedSecret = key.getKey();
    
    loggedInUser.setTwoFactorAuthenticationSecret(sharedSecret);
    userManagementService.saveUser(loggedInUser);
    
    request.setAttribute("sharedSecret", sharedSecret);
    String QRCode = GoogleAuthenticatorQRGenerator.getOtpAuthURL(null, "LAMS account: " + loggedInUser.getLogin(), key);
    request.setAttribute("QRCode", QRCode);
}

return mapping.findForward("secret");
   }
 
Example 2
Project: parabuild-ci   File: SpringCreator.java   View source code 6 votes vote down vote up
/**
 * @return A found BeanFactory configuration
 */
private BeanFactory getBeanFactory()
{
    // If someone has set a resource name then we need to load that.
    if (configLocation != null && configLocation.length > 0)
    {
        log.info("Spring BeanFactory via ClassPathXmlApplicationContext using " + configLocation.length + "configLocations.");
        return new ClassPathXmlApplicationContext(configLocation);
    }

    ServletContext srvCtx = WebContextFactory.get().getServletContext();
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();

    if (request != null)
    {
        return RequestContextUtils.getWebApplicationContext(request, srvCtx);
    }
    else
    {
        return WebApplicationContextUtils.getWebApplicationContext(srvCtx);
    }
}
 
Example 3
Project: hevelian-activemq   File: WebXBeanBrokerFactory.java   View source code 6 votes vote down vote up
@Override
protected ApplicationContext createApplicationContext(String uri) throws MalformedURLException {
	Resource resource = Utils.resourceFromString(uri);
	LOG.debug("Using " + resource + " from " + uri);
	try {
		return new ResourceXmlApplicationContext(resource) {
			@Override
			protected ConfigurableEnvironment createEnvironment() {
				return new ReversePropertySourcesStandardServletEnvironment();
			}

			@Override
			protected void initPropertySources() {
				WebApplicationContextUtils.initServletPropertySources(getEnvironment().getPropertySources(),
						ServletContextHolder.getServletContext());
			}
		};
	} catch (FatalBeanException errorToLog) {
		LOG.error("Failed to load: " + resource + ", reason: " + errorToLog.getLocalizedMessage(), errorToLog);
		throw errorToLog;
	}
}
 
Example 4
Project: azeroth   File: ContextLoaderListener.java   View source code 5 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent event) {
    String serviceName = event.getServletContext().getInitParameter("appName");
    System.setProperty("serviceName", serviceName == null ? "undefined" : serviceName);
    super.contextInitialized(event);
    WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
    SpringInstanceProvider provider = new SpringInstanceProvider(applicationContext);
    InstanceFactory.setInstanceProvider(provider);
}
 
Example 5
Project: lams   File: EmailUserAction.java   View source code 5 votes vote down vote up
private IUserManagementService getUserManagementService() {
if (EmailUserAction.userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    EmailUserAction.userManagementService = (IUserManagementService) ctx.getBean("userManagementService");
}
return EmailUserAction.userManagementService;
   }
 
Example 6
Project: lams   File: PortraitBatchUploadAction.java   View source code 5 votes vote down vote up
private IUserManagementService getUserManagementService() {
if (userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    userManagementService = (IUserManagementService) ctx.getBean("userManagementService");
}
return userManagementService;
   }
 
Example 7
Project: lams   File: AuthoringAction.java   View source code 5 votes vote down vote up
private IMonitoringService getMonitoringService() {
if (AuthoringAction.monitoringService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    AuthoringAction.monitoringService = (IMonitoringService) ctx.getBean("monitoringService");
}
return AuthoringAction.monitoringService;
   }
 
Example 8
Project: alfresco-remote-api   File: PublicApiWebScriptServlet.java   View source code 5 votes vote down vote up
@Override
public void init() throws ServletException
{
	super.init();
	
    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    container = (RuntimeContainer)context.getBean("publicapi.container");
    apiAssistant = (ApiAssistant) context.getBean("apiAssistant");
}
 
Example 9
Project: lams   File: HomeAction.java   View source code 5 votes vote down vote up
private IGroupUserDAO getGroupUserDAO() {
if (HomeAction.groupUserDAO == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.groupUserDAO = (IGroupUserDAO) ctx.getBean("groupUserDAO");
}
return HomeAction.groupUserDAO;
   }
 
Example 10
Project: lams   File: AuthoringAction.java   View source code 5 votes vote down vote up
public ILamsToolService getToolService() {
if (AuthoringAction.toolService == null) {
    WebApplicationContext wac = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    AuthoringAction.toolService = (ILamsToolService) wac.getBean(AuthoringConstants.TOOL_SERVICE_BEAN_NAME);
}
return AuthoringAction.toolService;
   }
 
Example 11
Project: lams   File: LessonConditionsAction.java   View source code 5 votes vote down vote up
private ISecurityService getSecurityService() {
if (LessonConditionsAction.securityService == null) {
    WebApplicationContext webContext = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    LessonConditionsAction.securityService = (ISecurityService) webContext.getBean("securityService");
}

return LessonConditionsAction.securityService;
   }
 
Example 12
Project: nixmash-blog   File: SecurityRequestPostProcessors.java   View source code 5 votes vote down vote up
private UsernamePasswordAuthenticationToken authentication(ServletContext servletContext) {
    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    UserDetailsService userDetailsService = userDetailsService(context);
    UserDetails userDetails = userDetailsService.loadUserByUsername(this.username);
    return new UsernamePasswordAuthenticationToken(
            userDetails, userDetails.getPassword(), userDetails.getAuthorities());
}
 
Example 13
Project: lams   File: HomeAction.java   View source code 5 votes vote down vote up
private ILearningDesignService getLearningDesignService() {
if (HomeAction.learningDesignService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.learningDesignService = (ILearningDesignService) ctx.getBean("learningDesignService");
}
return HomeAction.learningDesignService;
   }
 
Example 14
Project: lams   File: LearningAction.java   View source code 5 votes vote down vote up
@Override
   public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
long toolSessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);

WebApplicationContext wac = WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServlet().getServletContext());
ILearnerService learnerService = (ILearnerService) wac.getBean("learnerService");
String finishURL = learnerService.completeToolSession(toolSessionId, user.getUserID().longValue());
return new RedirectingActionForward(finishURL);
   }
 
Example 15
Project: cas-server-4.2.1   File: CasEnvironmentContextListener.java   View source code 5 votes vote down vote up
@Override
public void contextInitialized(final ServletContextEvent event) {
    final ServletContext servletContext = event.getServletContext();
    final ApplicationContext ctx =
        WebApplicationContextUtils.getWebApplicationContext(servletContext);

    LOGGER.info("[{}] has loaded the CAS servlet application context: {}",
        servletContext.getServerInfo(), ctx);
}
 
Example 16
Project: sdudoc   File: AutoLoginFilter.java   View source code 5 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
	log.info("AutoLoginFilter Init");
	//使用以下方式来完成userService的注入
	ServletContext context = filterConfig.getServletContext();
	ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
	userService = (UserService) ctx.getBean("userService");
}
 
Example 17
Project: lams   File: CleanupPreviewLessonsAction.java   View source code 5 votes vote down vote up
private IMonitoringService getMonitoringService() {
if (monitoringService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    monitoringService = (IMonitoringService) ctx.getBean("monitoringService");
}
return monitoringService;
   }
 
Example 18
Project: lams   File: GradebookServlet.java   View source code 5 votes vote down vote up
private IntegrationService getIntegrationService() {
if (integrationService == null) {
    integrationService = (IntegrationService) WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServletContext()).getBean("integrationService");
}
return integrationService;
   }
 
Example 19
Project: lams   File: EmailUserAction.java   View source code 5 votes vote down vote up
private MessageService getMessageService() {
if (EmailUserAction.messageService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    EmailUserAction.messageService = (MessageService) ctx
	    .getBean(CentralConstants.CENTRAL_MESSAGE_SERVICE_BEAN_NAME);

}
return EmailUserAction.messageService;
   }
 
Example 20
Project: lams   File: TutorialAction.java   View source code 5 votes vote down vote up
private IUserManagementService getService() {
if (TutorialAction.service == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    TutorialAction.service = (IUserManagementService) ctx.getBean("userManagementService");
}
return TutorialAction.service;
   }
 
Example 21
Project: lams   File: GradebookLearningAction.java   View source code 5 votes vote down vote up
private ISecurityService getSecurityService() {
if (GradebookLearningAction.securityService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookLearningAction.securityService = (ISecurityService) ctx.getBean("securityService");
}
return GradebookLearningAction.securityService;
   }
 
Example 22
Project: lams   File: GradebookMonitoringAction.java   View source code 5 votes vote down vote up
private IUserManagementService getUserService() {
if (GradebookMonitoringAction.userService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookMonitoringAction.userService = (IUserManagementService) ctx.getBean("userManagementService");
}
return GradebookMonitoringAction.userService;
   }
 
Example 23
Project: lams   File: HomeAction.java   View source code 5 votes vote down vote up
private ILessonService getLessonService() {
if (HomeAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return HomeAction.lessonService;
   }
 
Example 24
Project: lams   File: GradebookMonitoringAction.java   View source code 5 votes vote down vote up
private ISecurityService getSecurityService() {
if (GradebookMonitoringAction.securityService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookMonitoringAction.securityService = (ISecurityService) ctx.getBean("securityService");
}
return GradebookMonitoringAction.securityService;
   }
 
Example 25
Project: lams   File: GradebookAction.java   View source code 5 votes vote down vote up
private IUserManagementService getUserService() {
if (GradebookAction.userService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookAction.userService = (IUserManagementService) ctx.getBean("userManagementService");
}
return GradebookAction.userService;
   }
 
Example 26
Project: lams   File: GradebookAction.java   View source code 5 votes vote down vote up
private ILessonService getLessonService() {
if (GradebookAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return GradebookAction.lessonService;
   }
 
Example 27
Project: lams   File: LDAPAuthenticator.java   View source code 5 votes vote down vote up
public LDAPAuthenticator(IUserManagementService userManagementService) {
if (LDAPAuthenticator.userManagementService == null) {
    LDAPAuthenticator.userManagementService = userManagementService;
}
if (LDAPAuthenticator.ldapService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getWebApplicationContext(SessionManager.getServletContext());
    LDAPAuthenticator.ldapService = (ILdapService) ctx.getBean("ldapService");
}
   }
 
Example 28
Project: lams   File: CompleteActivityAction.java   View source code 5 votes vote down vote up
private IntegrationService getIntegrationService() {
if (CompleteActivityAction.integrationService == null) {
    CompleteActivityAction.integrationService = (IntegrationService) WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext()).getBean("integrationService");
}
return CompleteActivityAction.integrationService;
   }
 
Example 29
Project: lams   File: LamsAuthoringFinishAction.java   View source code 5 votes vote down vote up
/**
    * Get AuditService bean
    */
   private IAuditService getAuditService() {
if (auditService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    auditService = (IAuditService) ctx.getBean("auditService");
}
return auditService;
   }
 
Example 30
Project: lams   File: LessonManagerServlet.java   View source code 5 votes vote down vote up
/**
    * Initialization of the servlet. <br>
    *
    * @throws ServletException
    *             if an error occured
    */
   @Override
   public void init() throws ServletException {

integrationService = (IntegrationService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("integrationService");

monitoringService = (IMonitoringService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("monitoringService");

lessonService = (ILessonService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("lessonService");

exportService = (IExportToolContentService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("exportToolContentService");

toolService = (ILamsCoreToolService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("lamsCoreToolService");

gradebookService = (IGradebookService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("gradebookService");

userManagementService = (IUserManagementService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("userManagementService");

securityService = (ISecurityService) WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext()).getBean("securityService");
   }
 
Example 31
Project: lams   File: EditLessonIntroAction.java   View source code 5 votes vote down vote up
private ILessonService getLessonService() {
if (lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    lessonService = (ILessonService) ctx.getBean("lessonService");
}
return lessonService;
   }
 
Example 32
Project: lams   File: EmailNotificationsAction.java   View source code 5 votes vote down vote up
private IEventNotificationService getEventNotificationService() {
if (eventNotificationService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    eventNotificationService = (IEventNotificationService) ctx.getBean("eventNotificationService");
}
return eventNotificationService;
   }
 
Example 33
Project: lams   File: EmailNotificationsAction.java   View source code 5 votes vote down vote up
private IUserManagementService getUserManagementService() {
if (userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    userManagementService = (IUserManagementService) ctx.getBean("userManagementService");
}
return userManagementService;
   }
 
Example 34
Project: lams   File: EmailNotificationsAction.java   View source code 5 votes vote down vote up
private IAuditService getAuditService() {
if (auditService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    auditService = (IAuditService) ctx.getBean("auditService");
}
return auditService;
   }
 
Example 35
Project: lams   File: OrganisationGroupAction.java   View source code 5 votes vote down vote up
private IUserManagementService getUserManagementService() {
if (OrganisationGroupAction.userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    OrganisationGroupAction.userManagementService = (IUserManagementService) ctx
	    .getBean("userManagementService");
}
return OrganisationGroupAction.userManagementService;
   }
 
Example 36
Project: lams   File: OpenSessionInViewFilter.java   View source code 5 votes vote down vote up
/**
 * Look up the SessionFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the SessionFactory to use
 * @see #getSessionFactoryBeanName
 */
protected SessionFactory lookupSessionFactory() {
	if (logger.isDebugEnabled()) {
		logger.debug("Using SessionFactory '" + getSessionFactoryBeanName() + "' for OpenSessionInViewFilter");
	}
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	return wac.getBean(getSessionFactoryBeanName(), SessionFactory.class);
}
 
Example 37
Project: lams   File: UserManagementService.java   View source code 5 votes vote down vote up
private IAuditService getAuditService() {
if (UserManagementService.auditService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getWebApplicationContext(SessionManager.getServletContext());
    UserManagementService.auditService = (IAuditService) ctx.getBean("auditService");
}
return UserManagementService.auditService;
   }
 
Example 38
Project: lams   File: MonitoringAction.java   View source code 5 votes vote down vote up
private ILessonService getLessonService() {
if (MonitoringAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    MonitoringAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return MonitoringAction.lessonService;
   }
 
Example 39
Project: lams   File: PresenceWebsocketServer.java   View source code 5 votes vote down vote up
private static IPresenceChatService getPresenceChatService() {
if (PresenceWebsocketServer.presenceChatService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getWebApplicationContext(SessionManager.getServletContext());
    PresenceWebsocketServer.presenceChatService = (IPresenceChatService) ctx.getBean("presenceChatService");
}
return PresenceWebsocketServer.presenceChatService;
   }
 
Example 40
Project: lams   File: ToolContentListAction.java   View source code 5 votes vote down vote up
private DataSource getDataSource() {
if (ToolContentListAction.dataSource == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    ToolContentListAction.dataSource = (DataSource) ctx.getBean("dataSource");
}
return ToolContentListAction.dataSource;
   }