public Collection<KeyPair> loadKeyPairs(String resourceKey, byte[] pubData, byte[] prvData)
     throws IOException, GeneralSecurityException {
   ValidateUtils.checkNotNullAndNotEmpty(pubData, "No public key data in %s", resourceKey);
   ValidateUtils.checkNotNullAndNotEmpty(prvData, "No private key data in %s", resourceKey);
   try (InputStream pubStream = new ByteArrayInputStream(pubData);
       InputStream prvStream = new ByteArrayInputStream(prvData)) {
     return loadKeyPairs(resourceKey, pubStream, prvStream);
   }
 }
  static SecurityProviderChoice toSecurityProviderChoice(String name) {
    ValidateUtils.checkNotNullAndNotEmpty(name, "No name provided");
    return new SecurityProviderChoice() {
      private final String s = SecurityProviderChoice.class.getSimpleName() + "[" + name + "]";

      @Override
      public String getName() {
        return name;
      }

      @Override
      public boolean isNamedProviderUsed() {
        return true;
      }

      @Override
      public Provider getSecurityProvider() {
        return null;
      }

      @Override
      public String toString() {
        return s;
      }
    };
  }
 protected AbstractSftpClientExtension(
     String name, SftpClient client, RawSftpClient raw, boolean supported) {
   this.name = ValidateUtils.checkNotNullAndNotEmpty(name, "No extension name");
   this.client = ValidateUtils.checkNotNull(client, "No client instance");
   this.raw = ValidateUtils.checkNotNull(raw, "No raw access");
   this.supported = supported;
 }
Esempio n. 4
0
  @Override
  public void download(String[] remote, String local, Collection<Option> options)
      throws IOException {
    local = ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local);
    remote =
        ValidateUtils.checkNotNullAndNotEmpty(
            remote, "Invalid argument remote: %s", (Object) remote);

    if (remote.length > 1) {
      options = addTargetIsDirectory(options);
    }

    for (String r : remote) {
      download(r, local, options);
    }
  }
Esempio n. 5
0
  @Override
  public void download(String remote, Path local, Collection<Option> options) throws IOException {
    local = ValidateUtils.checkNotNull(local, "Invalid argument local: %s", local);
    remote = ValidateUtils.checkNotNullAndNotEmpty(remote, "Invalid argument remote: %s", remote);

    LinkOption[] opts = IoUtils.getLinkOptions(false);
    if (Files.isDirectory(local, opts)) {
      options = addTargetIsDirectory(options);
    }

    if (options.contains(Option.TargetIsDirectory)) {
      Boolean status = IoUtils.checkFileExists(local, opts);
      if (status == null) {
        throw new SshException("Target directory " + local.toString() + " is probaly inaccesible");
      }

      if (!status.booleanValue()) {
        throw new SshException("Target directory " + local.toString() + " does not exist");
      }

      if (!Files.isDirectory(local, opts)) {
        throw new SshException("Target directory " + local.toString() + " is not a directory");
      }
    }

    download(remote, local.getFileSystem(), local, options);
  }
Esempio n. 6
0
 @Override
 public void upload(String local, String remote, Collection<Option> options) throws IOException {
   upload(
       new String[] {
         ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local)
       },
       remote,
       options);
 }
  protected void checkConfig() {
    ValidateUtils.checkNotNullAndNotEmpty(
        getKeyExchangeFactories(), "KeyExchangeFactories not set");

    if (getScheduledExecutorService() == null) {
      setScheduledExecutorService(
          ThreadUtils.newSingleThreadScheduledExecutor(this.toString() + "-timer"), true);
    }

    ValidateUtils.checkNotNullAndNotEmpty(getCipherFactories(), "CipherFactories not set");
    ValidateUtils.checkNotNullAndNotEmpty(
        getCompressionFactories(), "CompressionFactories not set");
    ValidateUtils.checkNotNullAndNotEmpty(getMacFactories(), "MacFactories not set");

    ValidateUtils.checkNotNull(getRandomFactory(), "RandomFactory not set");

    if (getIoServiceFactoryFactory() == null) {
      setIoServiceFactoryFactory(new DefaultIoServiceFactoryFactory());
    }
  }
Esempio n. 8
0
  public static String createReceiveCommand(String remote, Collection<Option> options) {
    ValidateUtils.checkNotNullAndNotEmpty(remote, "No remote location specified");
    StringBuilder sb =
        new StringBuilder(remote.length() + Long.SIZE).append(ScpHelper.SCP_COMMAND_PREFIX);
    if (options.contains(Option.Recursive)) {
      sb.append(" -r");
    }
    if (options.contains(Option.PreserveAttributes)) {
      sb.append(" -p");
    }

    sb.append(" -f").append(" --").append(' ').append(remote);
    return sb.toString();
  }
Esempio n. 9
0
  @Override
  public void download(String remote, String local, Collection<Option> options) throws IOException {
    local = ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local);

    ClientSession session = getClientSession();
    FactoryManager manager = session.getFactoryManager();
    FileSystemFactory factory = manager.getFileSystemFactory();
    FileSystem fs = factory.createFileSystem(session);
    try {
      download(remote, fs, fs.getPath(local), options);
    } finally {
      try {
        fs.close();
      } catch (UnsupportedOperationException e) {
        // Ignore
      }
    }
  }
Esempio n. 10
0
 @Override
 public void upload(Path[] local, String remote, Collection<Option> options) throws IOException {
   final Collection<Path> paths =
       Arrays.asList(
           ValidateUtils.checkNotNullAndNotEmpty(
               local, "Invalid argument local: %s", (Object) local));
   runUpload(
       remote,
       options,
       paths,
       new ScpOperationExecutor<Path>() {
         @Override
         public void execute(
             ScpHelper helper, Collection<Path> local, Collection<Option> sendOptions)
             throws IOException {
           helper.sendPaths(
               local,
               sendOptions.contains(Option.Recursive),
               sendOptions.contains(Option.PreserveAttributes),
               ScpHelper.DEFAULT_SEND_BUFFER_SIZE);
         }
       });
 }