コード例 #1
0
  /**
   * Display page for choosing tenant.
   *
   * @param redirect
   * @param servletRequest
   * @return
   */
  @RequestMapping("/tenant")
  public ModelAndView showTenantChoices(
      @RequestParam(required = false) String redirect, HttpServletRequest servletRequest) {
    Tracer.start(TracerCategory.AdminUserInterface, "showTenantChoices", LOGGER);
    try {
      if ((SecurityContextHolder.getContext() == null)
          || (SecurityContextHolder.getContext().getAuthentication() == null)) {
        return login();
      }

      // Find tenants the logged in user is able to view.
      IUser user = LoginManager.getCurrentlyLoggedInUser();
      List<ITenant> matches = SiteWhere.getServer().getAuthorizedTenants(user.getUsername());
      if (matches.size() == 0) {
        return showError("User is not authorized to access any of the available tenants.");
      } else if (matches.size() == 1) {
        // If no redirect specified, show server info page.
        if (redirect == null) {
          redirect = "server.html";
        }
        setChosenTenant(matches.get(0), servletRequest);
        return new ModelAndView("redirect:" + redirect);
      }

      Map<String, Object> data = new HashMap<String, Object>();
      data.put(DATA_VERSION, VersionHelper.getVersion());
      data.put(DATA_CURRENT_USER, LoginManager.getCurrentlyLoggedInUser());
      data.put(DATA_REDIRECT, redirect);
      return new ModelAndView("tenant", data);
    } catch (SiteWhereException e) {
      return showError(e);
    } finally {
      Tracer.stop(LOGGER);
    }
  }
コード例 #2
0
  /**
   * Create the server.
   *
   * @throws SiteWhereException
   */
  public void create() throws SiteWhereException {
    LOGGER.info("Initializing SiteWhere server components.");
    File sitewhereConf = getSiteWhereConfigFolder();

    // Load server configuration.
    LOGGER.info("Loading Spring configuration ...");
    File serverConfigFile = new File(sitewhereConf, SERVER_CONFIG_FILE_NAME);
    if (!serverConfigFile.exists()) {
      throw new SiteWhereException(
          "SiteWhere server configuration not found: " + serverConfigFile.getAbsolutePath());
    }
    SERVER_SPRING_CONTEXT = loadServerApplicationContext(serverConfigFile);

    // Load device management and wrap it for metrics.
    IDeviceManagement deviceManagementImpl =
        (IDeviceManagement)
            SERVER_SPRING_CONTEXT.getBean(SiteWhereServerBeans.BEAN_DEVICE_MANAGEMENT);
    if (deviceManagementImpl == null) {
      throw new SiteWhereException("No device management implementation configured.");
    }
    DeviceManagementMetricsFacade facade = new DeviceManagementMetricsFacade();
    facade.setDelegate(deviceManagementImpl);
    deviceManagement = facade;
    deviceManagement.start();

    // Load user management.
    userManagement =
        (IUserManagement) SERVER_SPRING_CONTEXT.getBean(SiteWhereServerBeans.BEAN_USER_MANAGEMENT);
    if (userManagement == null) {
      throw new SiteWhereException("No user management implementation configured.");
    }
    userManagement.start();

    // Load the asset module manager.
    assetModuleManager =
        (IAssetModuleManager)
            SERVER_SPRING_CONTEXT.getBean(SiteWhereServerBeans.BEAN_ASSET_MODULE_MANAGER);
    if (assetModuleManager == null) {
      throw new SiteWhereException("No asset module manager implementation configured.");
    }

    // Print version information.
    IVersion version = VersionHelper.getVersion();
    List<String> messages = new ArrayList<String>();
    messages.add("SiteWhere Server");
    messages.add("");
    messages.add("Version: " + version.getVersionIdentifier() + "." + version.getBuildTimestamp());
    messages.add("");
    messages.add("Copyright (c) 2013 Reveal Technologies, LLC");
    String message = StringMessageUtils.getBoilerPlate(messages, '*', 60);
    LOGGER.info("\n" + message + "\n");

    verifyUserModel();
    verifyDeviceModel();
  }
コード例 #3
0
 /**
  * Display the "login" page after failed login.
  *
  * @return
  */
 @RequestMapping("/loginFailed")
 public ModelAndView loginFailed() {
   Tracer.start(TracerCategory.AdminUserInterface, "loginFailed", LOGGER);
   try {
     Map<String, Object> data = new HashMap<String, Object>();
     data.put(DATA_VERSION, VersionHelper.getVersion());
     data.put("loginFailed", true);
     return new ModelAndView("login", data);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #4
0
 /**
  * Display the "login" page.
  *
  * @return
  */
 @RequestMapping("/")
 public ModelAndView login() {
   Tracer.start(TracerCategory.AdminUserInterface, "login", LOGGER);
   try {
     Map<String, Object> data = new HashMap<String, Object>();
     data.put(DATA_VERSION, VersionHelper.getVersion());
     if (SiteWhere.getServer().getLifecycleStatus() == LifecycleStatus.Started) {
       return new ModelAndView("login", data);
     } else {
       ServerStartupException failure = SiteWhere.getServer().getServerStartupError();
       data.put("subsystem", failure.getDescription());
       data.put("component", failure.getComponent().getLifecycleError().getMessage());
       return new ModelAndView("noserver", data);
     }
   } finally {
     Tracer.stop(LOGGER);
   }
 }