Exemplo n.º 1
0
  private void printRequestOutcome(TReturnStatus status, RmdirInputData inputData) {

    if (inputData != null) {
      if (inputData.getSurl() != null) {
        CommandHelper.printRequestOutcome(
            SRM_COMMAND, log, status, inputData, Arrays.asList(inputData.getSurl().toString()));
      } else {
        CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, inputData);
      }

    } else {
      CommandHelper.printRequestOutcome(SRM_COMMAND, log, status);
    }
  }
Exemplo n.º 2
0
  /**
   * Method that provide SrmRmdir functionality.
   *
   * @param inputData Contains information about input data for Rmdir request.
   * @return TReturnStatus Contains output data
   */
  public OutputData execute(InputData data) {

    log.debug("srmRmdir: Start execution.");
    TReturnStatus returnStatus = null;

    RmdirInputData inputData = (RmdirInputData) data;
    RmdirOutputData outData = null;

    /**
     * Validate RmdirInputData. The check is done at this level to separate internal StoRM logic
     * from xmlrpc specific operation.
     */
    if ((inputData == null) || ((inputData != null) && (inputData.getSurl() == null))) {
      returnStatus =
          CommandHelper.buildStatus(TStatusCode.SRM_FAILURE, "Invalid parameter specified.");
      printRequestOutcome(returnStatus, inputData);
      outData = new RmdirOutputData(returnStatus);
      return outData;
    }

    TSURL surl = inputData.getSurl();
    StoRI stori = null;
    if (!surl.isEmpty()) {
      try {
        if (inputData instanceof IdentityInputData) {
          try {
            stori = namespace.resolveStoRIbySURL(surl, ((IdentityInputData) inputData).getUser());
          } catch (UnapprochableSurlException e) {
            log.info(
                "Unable to build a stori for surl {} for user {}: {}",
                surl,
                DataHelper.getRequestor(inputData),
                e.getMessage());

            returnStatus =
                CommandHelper.buildStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
            printRequestOutcome(returnStatus, inputData);
            return new RmdirOutputData(returnStatus);
          } catch (NamespaceException e) {
            log.info(
                "Unable to build a stori for surl {} for user {}: {}",
                surl,
                DataHelper.getRequestor(inputData),
                e.getMessage());
            returnStatus =
                CommandHelper.buildStatus(TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
            printRequestOutcome(returnStatus, inputData);
            return new RmdirOutputData(returnStatus);
          } catch (InvalidSURLException e) {
            log.info(
                "Unable to build a stori for surl {} for user {}: {}",
                surl,
                DataHelper.getRequestor(inputData),
                e.getMessage());
            returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
            printRequestOutcome(returnStatus, inputData);
            return new RmdirOutputData(returnStatus);
          }
        } else {
          try {
            stori = namespace.resolveStoRIbySURL(surl);
          } catch (UnapprochableSurlException e) {
            log.info("Unable to build a stori for surl {}: {}", surl, e.getMessage());
            returnStatus =
                CommandHelper.buildStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
            printRequestOutcome(returnStatus, inputData);
            return new RmdirOutputData(returnStatus);
          } catch (NamespaceException e) {
            log.info("Unable to build a stori for surl {}: {}", surl, e.getMessage());
            returnStatus =
                CommandHelper.buildStatus(TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
            printRequestOutcome(returnStatus, inputData);
            return new RmdirOutputData(returnStatus);
          } catch (InvalidSURLException e) {
            log.info("Unable to build a stori for surl {}: {}", surl, e.getMessage());
            returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
            printRequestOutcome(returnStatus, inputData);
            return new RmdirOutputData(returnStatus);
          }
        }
      } catch (IllegalArgumentException e) {
        log.error("StoRI from surl build error: {}", e.getMessage(), e);
        returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
        printRequestOutcome(returnStatus, inputData);
        outData = new RmdirOutputData(returnStatus);
        return outData;
      }
    } else {
      returnStatus =
          CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, "Invalid SURL specified");
      printRequestOutcome(returnStatus, inputData);
      outData = new RmdirOutputData(returnStatus);
      return outData;
    }

    // Check here if recursive flag is not specifed
    // in input parameter.Use default value
    Boolean recursive = inputData.getRecursive();
    if (recursive == null) {
      recursive = new Boolean(SRMConstants.recursiveFlag);
    }

    /**
     * From version 1.4 Add the control for Storage Area using the new authz for space component.
     */
    TSpaceToken token = new SpaceHelper().getTokenFromStoRI(log, stori);
    SpaceAuthzInterface spaceAuth = AuthzDirector.getSpaceAuthz(token);
    boolean isSpaceAuthorized;
    if (inputData instanceof IdentityInputData) {
      isSpaceAuthorized =
          spaceAuth.authorize(((IdentityInputData) inputData).getUser(), SRMSpaceRequest.RMD);
    } else {
      isSpaceAuthorized = spaceAuth.authorizeAnonymous(SRMSpaceRequest.RMD);
    }
    if (!isSpaceAuthorized) {
      log.debug("User not authorized to perform srmRmdir on SA: {}", token);
      returnStatus =
          CommandHelper.buildStatus(
              TStatusCode.SRM_AUTHORIZATION_FAILURE,
              "User not authorized to perform srmRmdir on storage area");
      printRequestOutcome(returnStatus, inputData);
      outData = new RmdirOutputData(returnStatus);
      return outData;
    }

    AuthzDecision decision;
    if (inputData instanceof IdentityInputData) {
      decision =
          AuthzDirector.getPathAuthz()
              .authorize(((IdentityInputData) inputData).getUser(), SRMFileRequest.RMD, stori);
    } else {
      decision =
          AuthzDirector.getPathAuthz().authorizeAnonymous(SRMFileRequest.RMD, stori.getStFN());
    }
    if (decision.equals(AuthzDecision.PERMIT)) {
      log.debug(
          "srmRmDir authorized for {}. Dir={}. Recursive={}",
          DataHelper.getRequestor(inputData),
          stori.getPFN(),
          recursive);
      returnStatus = manageAuthorizedRMDIR(stori.getLocalFile(), recursive.booleanValue());
    } else {
      returnStatus =
          CommandHelper.buildStatus(
              TStatusCode.SRM_AUTHORIZATION_FAILURE,
              "User is not authorized to delete the directory");
    }
    printRequestOutcome(returnStatus, inputData);
    outData = new RmdirOutputData(returnStatus);
    return outData;
  }