@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"); }
/** * @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); } }
@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; } }
@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); }
private IUserManagementService getUserManagementService() { if (EmailUserAction.userManagementService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); EmailUserAction.userManagementService = (IUserManagementService) ctx.getBean("userManagementService"); } return EmailUserAction.userManagementService; }
private IUserManagementService getUserManagementService() { if (userManagementService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); userManagementService = (IUserManagementService) ctx.getBean("userManagementService"); } return userManagementService; }
private IMonitoringService getMonitoringService() { if (AuthoringAction.monitoringService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); AuthoringAction.monitoringService = (IMonitoringService) ctx.getBean("monitoringService"); } return AuthoringAction.monitoringService; }
@Override public void init() throws ServletException { super.init(); ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); container = (RuntimeContainer)context.getBean("publicapi.container"); apiAssistant = (ApiAssistant) context.getBean("apiAssistant"); }
private IGroupUserDAO getGroupUserDAO() { if (HomeAction.groupUserDAO == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); HomeAction.groupUserDAO = (IGroupUserDAO) ctx.getBean("groupUserDAO"); } return HomeAction.groupUserDAO; }
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; }
private ISecurityService getSecurityService() { if (LessonConditionsAction.securityService == null) { WebApplicationContext webContext = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); LessonConditionsAction.securityService = (ISecurityService) webContext.getBean("securityService"); } return LessonConditionsAction.securityService; }
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()); }
private ILearningDesignService getLearningDesignService() { if (HomeAction.learningDesignService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); HomeAction.learningDesignService = (ILearningDesignService) ctx.getBean("learningDesignService"); } return HomeAction.learningDesignService; }
@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); }
@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); }
@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"); }
private IMonitoringService getMonitoringService() { if (monitoringService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); monitoringService = (IMonitoringService) ctx.getBean("monitoringService"); } return monitoringService; }
private IntegrationService getIntegrationService() { if (integrationService == null) { integrationService = (IntegrationService) WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()).getBean("integrationService"); } return integrationService; }
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; }
private IUserManagementService getService() { if (TutorialAction.service == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); TutorialAction.service = (IUserManagementService) ctx.getBean("userManagementService"); } return TutorialAction.service; }
private ISecurityService getSecurityService() { if (GradebookLearningAction.securityService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); GradebookLearningAction.securityService = (ISecurityService) ctx.getBean("securityService"); } return GradebookLearningAction.securityService; }
private IUserManagementService getUserService() { if (GradebookMonitoringAction.userService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); GradebookMonitoringAction.userService = (IUserManagementService) ctx.getBean("userManagementService"); } return GradebookMonitoringAction.userService; }
private ILessonService getLessonService() { if (HomeAction.lessonService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); HomeAction.lessonService = (ILessonService) ctx.getBean("lessonService"); } return HomeAction.lessonService; }
private ISecurityService getSecurityService() { if (GradebookMonitoringAction.securityService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); GradebookMonitoringAction.securityService = (ISecurityService) ctx.getBean("securityService"); } return GradebookMonitoringAction.securityService; }
private IUserManagementService getUserService() { if (GradebookAction.userService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); GradebookAction.userService = (IUserManagementService) ctx.getBean("userManagementService"); } return GradebookAction.userService; }
private ILessonService getLessonService() { if (GradebookAction.lessonService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); GradebookAction.lessonService = (ILessonService) ctx.getBean("lessonService"); } return GradebookAction.lessonService; }
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"); } }
private IntegrationService getIntegrationService() { if (CompleteActivityAction.integrationService == null) { CompleteActivityAction.integrationService = (IntegrationService) WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()).getBean("integrationService"); } return CompleteActivityAction.integrationService; }
/** * Get AuditService bean */ private IAuditService getAuditService() { if (auditService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); auditService = (IAuditService) ctx.getBean("auditService"); } return auditService; }
/** * 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"); }
private ILessonService getLessonService() { if (lessonService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); lessonService = (ILessonService) ctx.getBean("lessonService"); } return lessonService; }
private IEventNotificationService getEventNotificationService() { if (eventNotificationService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); eventNotificationService = (IEventNotificationService) ctx.getBean("eventNotificationService"); } return eventNotificationService; }
private IAuditService getAuditService() { if (auditService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); auditService = (IAuditService) ctx.getBean("auditService"); } return auditService; }
private IUserManagementService getUserManagementService() { if (OrganisationGroupAction.userManagementService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); OrganisationGroupAction.userManagementService = (IUserManagementService) ctx .getBean("userManagementService"); } return OrganisationGroupAction.userManagementService; }
/** * 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); }
private IAuditService getAuditService() { if (UserManagementService.auditService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getWebApplicationContext(SessionManager.getServletContext()); UserManagementService.auditService = (IAuditService) ctx.getBean("auditService"); } return UserManagementService.auditService; }
private ILessonService getLessonService() { if (MonitoringAction.lessonService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); MonitoringAction.lessonService = (ILessonService) ctx.getBean("lessonService"); } return MonitoringAction.lessonService; }
private static IPresenceChatService getPresenceChatService() { if (PresenceWebsocketServer.presenceChatService == null) { WebApplicationContext ctx = WebApplicationContextUtils .getWebApplicationContext(SessionManager.getServletContext()); PresenceWebsocketServer.presenceChatService = (IPresenceChatService) ctx.getBean("presenceChatService"); } return PresenceWebsocketServer.presenceChatService; }
private DataSource getDataSource() { if (ToolContentListAction.dataSource == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); ToolContentListAction.dataSource = (DataSource) ctx.getBean("dataSource"); } return ToolContentListAction.dataSource; }