Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   * @see
   * org.fcrepo.server.security.xacml.pep.rest.filters.RESTFilter#handleRequest(javax.servlet
   * .http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  public RequestCtx handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    if (logger.isDebugEnabled()) {
      logger.debug(this.getClass().getName() + "/handleRequest!");
    }

    String path = request.getPathInfo();
    String[] parts = path.split("/");

    String pid = parts[1];
    String dsid = parts[3];
    String startDT = request.getParameter("startDT");
    String endDT = request.getParameter("endDT");

    RequestCtx req = null;
    Map<URI, AttributeValue> actions = new HashMap<URI, AttributeValue>();
    Map<URI, AttributeValue> resAttr = new HashMap<URI, AttributeValue>();
    try {
      if (pid != null && !"".equals(pid)) {
        resAttr.put(Constants.OBJECT.PID.getURI(), new StringAttribute(pid));
      }
      if (pid != null && !"".equals(pid)) {
        resAttr.put(new URI(XACML_RESOURCE_ID), new AnyURIAttribute(new URI(pid)));
      }
      if (dsid != null && !"".equals(dsid)) {
        resAttr.put(Constants.DATASTREAM.ID.getURI(), new StringAttribute(dsid));
      }
      if (startDT != null && !"".equals(startDT)) {
        resAttr.put(
            Constants.DATASTREAM.CREATED_DATETIME.getURI(), DateTimeAttribute.getInstance(startDT));
      }
      if (endDT != null && !"".equals(endDT)) {
        resAttr.put(
            Constants.DATASTREAM.AS_OF_DATETIME.getURI(), DateTimeAttribute.getInstance(endDT));
      }

      actions.put(
          Constants.ACTION.ID.getURI(),
          new StringAttribute(Constants.ACTION.PURGE_DATASTREAM.getURI().toASCIIString()));
      actions.put(
          Constants.ACTION.API.getURI(),
          new StringAttribute(Constants.ACTION.APIM.getURI().toASCIIString()));
      // modifying the FeSL policy datastream requires policy management permissions
      if (dsid != null && dsid.equals(FedoraPolicyStore.FESL_POLICY_DATASTREAM)) {
        actions.put(
            Constants.ACTION.ID.getURI(),
            new StringAttribute(Constants.ACTION.MANAGE_POLICIES.getURI().toASCIIString()));
      }

      req =
          getContextHandler()
              .buildRequest(getSubjects(request), actions, resAttr, getEnvironment(request));

      LogUtil.statLog(
          request.getRemoteUser(),
          Constants.ACTION.PURGE_DATASTREAM.getURI().toASCIIString(),
          pid,
          dsid);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new ServletException(e.getMessage(), e);
    }

    return req;
  }