Ejemplo n.º 1
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    boolean download = getOptionalParameter(request, "download") != null;
    boolean playback = getOptionalParameter(request, "playback") != null;

    User user = getUser(request);
    Authorizations authorizations = getAuthorizations(request, user);

    String graphVertexId = UrlUtils.urlDecode(getAttributeString(request, "graphVertexId"));

    Vertex artifactVertex = graph.getVertex(graphVertexId, authorizations);
    if (artifactVertex == null) {
      respondWithNotFound(response);
      return;
    }

    String fileName = LumifyProperties.FILE_NAME.getPropertyValue(artifactVertex);
    if (fileName == null) {
      fileName = LumifyProperties.TITLE.getPropertyValue(artifactVertex);
    }

    if (playback) {
      handlePartialPlayback(request, response, artifactVertex, fileName, user);
    } else {
      String mimeType = getMimeType(artifactVertex);
      response.setContentType(mimeType);
      setMaxAge(response, EXPIRES_1_HOUR);
      if (download) {
        response.addHeader("Content-Disposition", "attachment; filename=" + fileName);
      } else {
        response.addHeader("Content-Disposition", "inline; filename=" + fileName);
      }

      StreamingPropertyValue rawValue = LumifyProperties.RAW.getPropertyValue(artifactVertex);
      if (rawValue == null) {
        LOGGER.warn("Could not find raw on artifact: %s", artifactVertex.getId().toString());
        respondWithNotFound(response);
        return;
      }
      InputStream in = rawValue.getInputStream();
      try {
        IOUtils.copy(in, response.getOutputStream());
      } finally {
        in.close();
      }
    }

    chain.next(request, response);
  }
Ejemplo n.º 2
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String username = UrlUtils.urlDecode(request.getParameter("username"));

    User user = getUserRepository().findByUsername(username);
    if (user == null) {
      // For form based authentication, username and displayName will be the same
      String randomPassword = UserRepository.createRandomPassword();
      user = getUserRepository().addUser(username, username, null, randomPassword, new String[0]);
    }
    getUserRepository().recordLogin(user, AuthenticationHandler.getRemoteAddr(request));

    CurrentUser.set(request, user.getUserId(), user.getUsername());
    JSONObject json = new JSONObject();
    json.put("status", "OK");
    respondWithJson(response, json);
  }