public boolean isValid(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    String vsName = request.getParameter("name");

    // Added by Behnaz
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");

    if (vsName == null || vsName.trim().length() == 0) {
      response.sendError(WebConstants.MISSING_VSNAME_ERROR, "The virtual sensor name is missing");
      return false;
    }
    VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
    if (sensorConfig == null) {
      response.sendError(
          WebConstants.ERROR_INVALID_VSNAME, "The specified virtual sensor doesn't exist.");
      return false;
    }

    // Added by Behnaz.
    if (user != null) // meaning, that a login session is active, otherwise we couldn't get there
    if (Main.getContainerConfig().isAcEnabled() == true) {
        if (user.hasReadAccessRight(vsName) == false && user.isAdmin() == false) // ACCESS_DENIED
        {
          response.sendError(
              WebConstants.ACCESS_DENIED, "Access denied to the specified virtual sensor .");
          return false;
        }
      }

    return true;
  }
  /*
   * Returns list of sensors currently loaded in the system
   * */
  public static String getListOfSensors() {
    StringBuilder s = new StringBuilder();
    Iterator iter = Mappings.getAllVSensorConfigs();
    while (iter.hasNext()) {
      VSensorConfig sensorConfig = (VSensorConfig) iter.next();
      Double longitude = sensorConfig.getLongitude();
      Double latitude = sensorConfig.getLatitude();
      String sensor = sensorConfig.getName();

      if ((latitude != null) && (longitude != null)) {
        Point point =
            geometryFactory.createPoint(
                new Coordinate(longitude.doubleValue(), latitude.doubleValue()));
        coordinates.add(point);
        sensors.add(sensor);
        s.append(sensor)
            .append(" => ")
            .append(longitude)
            .append(" : ")
            .append(latitude)
            .append(NEWLINE);
      }
    }
    return s.toString();
  }
 public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
   response.setStatus(HttpServletResponse.SC_OK);
   String vsName = request.getParameter("name");
   VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
   if (logger.isInfoEnabled())
     logger.info(
         new StringBuilder()
             .append("Structure request for *")
             .append(vsName)
             .append("* received.")
             .toString());
   StringBuilder sb = new StringBuilder("<virtual-sensor name=\"").append(vsName).append("\">\n");
   for (DataField df : sensorConfig.getOutputStructure())
     sb.append("<field name=\"")
         .append(df.getName())
         .append("\" ")
         .append("type=\"")
         .append(df.getType())
         .append("\" ")
         .append("description=\"")
         .append(StringEscapeUtils.escapeXml(df.getDescription()))
         .append("\" />\n");
   sb.append(
       "<field name=\"timed\" type=\"string\" description=\"The timestamp associated with the stream element\" />\n");
   sb.append("</virtual-sensor>");
   response.setHeader("Cache-Control", "no-store");
   response.setDateHeader("Expires", 0);
   response.setHeader("Pragma", "no-cache");
   response.getWriter().write(sb.toString());
 }
 public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
   response.setStatus(HttpServletResponse.SC_OK);
   String vsName = request.getParameter("name");
   VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
   if (logger.isInfoEnabled())
     logger.info(
         new StringBuilder()
             .append("Structure request for *")
             .append(vsName)
             .append("* received.")
             .toString());
   StringBuilder sb =
       new StringBuilder("<virtual-sensor name=\"")
           .append(vsName)
           .append("\" last-modified=\"")
           .append(new File(sensorConfig.getFileName()).lastModified())
           .append("\">\n");
   for (KeyValue df : sensorConfig.getAddressing())
     sb.append("<predicate key=\"")
         .append(StringEscapeUtils.escapeXml(df.getKey().toString()))
         .append("\">")
         .append(StringEscapeUtils.escapeXml(df.getValue().toString()))
         .append("</predicate>\n");
   sb.append("</virtual-sensor>");
   response.setHeader("Cache-Control", "no-store");
   response.setDateHeader("Expires", 0);
   response.setHeader("Pragma", "no-cache");
   response.getWriter().write(sb.toString());
 }
Exemple #5
0
 /**
  * Case insensitive matching.
  *
  * @param vsName
  * @return
  */
 public static VSensorConfig getConfig(String vsName) {
   Iterator<VSensorConfig> configs = Mappings.getAllVSensorConfigs();
   while (configs.hasNext()) {
     VSensorConfig config = configs.next();
     if (config.getName().equalsIgnoreCase(vsName)) return config;
   }
   return null;
 }