Exemplo n.º 1
0
  @Override
  public Set<String> getResourcePaths(String path) {
    // Try to get regular resource paths
    Set<String> paths = super.getResourcePaths(path);

    // If no paths are returned check for virtual paths /WEB-INF/classes and /WEB-INF/lib
    if (paths.isEmpty() && path != null) {
      path = URIUtil.canonicalPath(path);
      if (path.startsWith(WEB_INF_LIB_PREFIX)) {
        paths = new TreeSet<String>();
        for (String fileName : webInfJarMap.keySet()) {
          // Return all jar files from class path
          paths.add(WEB_INF_LIB_PREFIX + "/" + fileName);
        }
      } else if (path.startsWith(WEB_INF_CLASSES_PREFIX)) {
        int i = 0;

        while (paths.isEmpty() && (i < webInfClasses.size())) {
          String newPath = path.replace(WEB_INF_CLASSES_PREFIX, webInfClasses.get(i).getPath());
          paths = super.getResourcePaths(newPath);
          i++;
        }
      }
    }
    return paths;
  }
Exemplo n.º 2
0
  /**
   * This method is provided as a conveniance for jetty maven plugin configuration
   *
   * @param resourceBases Array of resources strings to set as a {@link ResourceCollection}. Each
   *     resource string may be a comma separated list of resources
   * @see Resource
   */
  public void setResourceBases(String[] resourceBases) {
    List<String> resources = new ArrayList<String>();
    for (String rl : resourceBases) {
      String[] rs = rl.split(" *, *");
      for (String r : rs) resources.add(r);
    }

    setBaseResource(new ResourceCollection(resources.toArray(new String[resources.size()])));
  }
Exemplo n.º 3
0
  private void handleSignupPost(Request request, HttpServletResponse httpServletResponse)
      throws Exception {
    String userId = request.getParameter(PARAM_USER_ID);
    String userName = request.getParameter(PARAM_USER_NAME);
    String email = request.getParameter(PARAM_EMAIL);
    String stringPassword = request.getParameter(PARAM_PASSWORD);
    String stringPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM);

    if (!stringPassword.equals(stringPasswordConfirm)) {
      WebUtils.redirectToError(
          "Mismatch between password and password confirmation", request, httpServletResponse);
      return;
    }

    SecureRandom secureRandom = new SecureRandom();
    String salt = "" + secureRandom.nextLong();
    byte[] password = User.computeHashedPassword(stringPassword, salt);
    User user = userDb.get(userId);
    if (user != null) {
      WebUtils.redirectToError(
          "There already exists a user with the ID " + userId, request, httpServletResponse);
      return;
    }

    user =
        new User(
            userId,
            userName,
            password,
            salt,
            email,
            new ArrayList<String>(),
            Config.getConfig().activateAccountsAtCreation,
            false);
    // ttt2 add confirmation by email, captcha, ...
    List<String> fieldErrors = user.checkFields();
    if (!fieldErrors.isEmpty()) {
      StringBuilder bld =
          new StringBuilder("Invalid values when trying to create user with ID ")
              .append(userId)
              .append("<br/>");
      for (String s : fieldErrors) {
        bld.append(s).append("<br/>");
      }
      WebUtils.redirectToError(bld.toString(), request, httpServletResponse);
      return;
    }

    // ttt2 2 clients can add the same userId simultaneously
    userDb.add(user);

    httpServletResponse.sendRedirect("/");
  }
Exemplo n.º 4
0
  @Override
  public Resource getResource(String uriInContext) throws MalformedURLException {
    Resource resource = null;
    // Try to get regular resource
    //        replacer.getAutoconfigTempDirectory().getAbsolutePath()
    try {
      resource = getAutoconfigResource(uriInContext);
      if (resource == null) {
        //                resource = super.getResource(uriInContext);
        resource = getResourceFromMavenOrSuper(uriInContext);
      }
    } catch (Exception e) {
      logger.warn("find autoconfig resource error! " + uriInContext, e);
    }
    // If no regular resource exists check for access to /WEB-INF/lib or /WEB-INF/classes
    if ((resource == null || !resource.exists()) && uriInContext != null && webInfClasses != null) {
      String uri = URIUtil.canonicalPath(uriInContext);

      try {
        // Replace /WEB-INF/classes with real classes directory
        if (uri.startsWith(WEB_INF_CLASSES_PREFIX)) {
          Resource res = null;
          int i = 0;
          while (res == null && (i < webInfClasses.size())) {
            String newPath = uri.replace(WEB_INF_CLASSES_PREFIX, webInfClasses.get(i).getPath());
            res = Resource.newResource(newPath);
            if (!res.exists()) {
              res = null;
              i++;
            }
          }
          return res;
        }
        // Return the real jar file for all accesses to
        // /WEB-INF/lib/*.jar
        else if (uri.startsWith(WEB_INF_LIB_PREFIX)) {
          String jarName = uri.replace(WEB_INF_LIB_PREFIX, "");
          if (jarName.startsWith("/") || jarName.startsWith("\\")) jarName = jarName.substring(1);
          if (jarName.length() == 0) return null;
          File jarFile = webInfJarMap.get(jarName);
          if (jarFile != null) return Resource.newResource(jarFile.getPath());

          return null;
        }
      } catch (MalformedURLException e) {
        throw e;
      } catch (IOException e) {
        Log.ignore(e);
      }
    }
    return resource;
  }
Exemplo n.º 5
0
 public void setWebInfLib(List<File> jars) {
   webInfJars.addAll(jars);
 }
Exemplo n.º 6
0
 public void setWebInfClasses(List<File> dirs) {
   webInfClasses.addAll(dirs);
 }