@RolesAllowed(SecurityRoles.CONFIGURATION_EDITOR)
  @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
  @ResponseBody
  public HttpEntity<byte[]> downloadConfigurationFile(@PathVariable("tenant") final String tenant) {

    final TenantContext context = _contextFactory.getContext(tenant);
    final RepositoryFile configurationFile = context.getConfigurationFile();

    if (configurationFile == null) {
      throw new IllegalStateException("Configuration file not found!");
    }

    final byte[] documentBody =
        configurationFile.readFile(
            new Func<InputStream, byte[]>() {
              @Override
              public byte[] eval(InputStream in) {
                return FileHelper.readAsBytes(in);
              }
            });

    final HttpHeaders header = new HttpHeaders();
    header.setContentType(MediaType.APPLICATION_XML);
    header.setContentLength(documentBody.length);
    return new HttpEntity<byte[]>(documentBody, header);
  }
  @RolesAllowed(SecurityRoles.CONFIGURATION_EDITOR)
  @RequestMapping(
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  @ResponseBody
  public Map<String, String> uploadConfigurationFileJson(
      @PathVariable("tenant") final String tenant, @RequestParam("file") final MultipartFile file)
      throws Exception {
    if (file == null) {
      logger.warn("No upload file provided, throwing IllegalArgumentException");
      throw new IllegalArgumentException(
          "No file upload provided. Please provide a multipart file using the 'file' HTTP parameter.");
    }

    logger.info("Upload of new configuration file beginning");

    try {
      final TenantContext context = _contextFactory.getContext(tenant);
      final RepositoryFile configurationFile = context.getConfigurationFile();

      final InputStream inputStream = file.getInputStream();
      final WriteUpdatedConfigurationFileAction writeAction =
          new WriteUpdatedConfigurationFileAction(inputStream, configurationFile);

      try {
        configurationFile.writeFile(writeAction);
      } finally {
        FileHelper.safeClose(inputStream);
      }

      final Map<String, String> result = new HashMap<String, String>();
      result.put("status", "Success");
      result.put("file_type", configurationFile.getType().toString());
      result.put("filename", configurationFile.getName());
      result.put("repository_path", configurationFile.getQualifiedPath());

      return result;
    } catch (Exception e) {
      logger.warn(
          "An error occurred while uploading new configuration file for tenant " + tenant, e);
      throw e;
    }
  }