@Test public void getAuthMethods () { final List<AuthMethod> authMethods = sshCredentials.getAuthMethods(); assertThat(authMethods, IsIterableWithSize.iterableWithSize(2)); for (int i = 0; i < authMethods.size() - 1; i++) { assertThat(authMethods.get(i), not(IsInstanceOf.instanceOf(AuthPassword.class))); } }
@Override public List<AuthMethod> getAuthMethods () { List<AuthMethod> authMethods = sshKeys.entrySet() .stream() .filter(e -> e.getKey() != null && e.getValue() != null) .map(e -> new KeyPairWrapper(e.getKey(), e.getValue())) .map(AuthPublickey::new) .collect(Collectors.toList()); if (passwordGenerator != null) { try { authMethods.add(new AuthPassword(new PasswordFinder() { @Override public char[] reqPassword (Resource<?> resource) { try { return passwordGenerator.call().toCharArray(); } catch (Exception e) { throw new ChaosException(SSH_CREDENTIAL_PASSWORD_CALL_FAILURE, e); } } @Override public boolean shouldRetry (Resource<?> resource) { return false; } })); } catch (ChaosException e) { log.error("Could not create password-based authentication token", e); } } return authMethods; }
ChaosSSHCredentials implements SSHCredentials { @Override public List<AuthMethod> getAuthMethods () { List<AuthMethod> authMethods = sshKeys.entrySet() .stream() .filter(e -> e.getKey() != null && e.getValue() != null) .map(e -> new KeyPairWrapper(e.getKey(), e.getValue())) .map(AuthPublickey::new) .collect(Collectors.toList()); if (passwordGenerator != null) { try { authMethods.add(new AuthPassword(new PasswordFinder() { @Override public char[] reqPassword (Resource<?> resource) { try { return passwordGenerator.call().toCharArray(); } catch (Exception e) { throw new ChaosException(SSH_CREDENTIAL_PASSWORD_CALL_FAILURE, e); } } @Override public boolean shouldRetry (Resource<?> resource) { return false; } })); } catch (ChaosException e) { log.error("Could not create password-based authentication token", e); } } return authMethods; } }
ChaosSSHCredentials implements SSHCredentials { @Override public List<AuthMethod> getAuthMethods () { List<AuthMethod> authMethods = sshKeys.entrySet() .stream() .filter(e -> e.getKey() != null && e.getValue() != null) .map(e -> new KeyPairWrapper(e.getKey(), e.getValue())) .map(AuthPublickey::new) .collect(Collectors.toList()); if (passwordGenerator != null) { try { authMethods.add(new AuthPassword(new PasswordFinder() { @Override public char[] reqPassword (Resource<?> resource) { try { return passwordGenerator.call().toCharArray(); } catch (Exception e) { throw new ChaosException(SSH_CREDENTIAL_PASSWORD_CALL_FAILURE, e); } } @Override public boolean shouldRetry (Resource<?> resource) { return false; } })); } catch (ChaosException e) { log.error("Could not create password-based authentication token", e); } } return authMethods; }  }
ChaosSSHCredentials implements SSHCredentials { @Override public List<AuthMethod> getAuthMethods () { List<AuthMethod> authMethods = sshKeys.entrySet() .stream() .filter(e -> e.getKey() != null && e.getValue() != null) .map(e -> new KeyPairWrapper(e.getKey(), e.getValue())) .map(AuthPublickey::new) .collect(Collectors.toList()); if (passwordGenerator != null) { try { authMethods.add(new AuthPassword(new PasswordFinder() { @Override public char[] reqPassword (Resource<?> resource) { try { return passwordGenerator.call().toCharArray(); } catch (Exception e) { throw new ChaosException(SSH_CREDENTIAL_PASSWORD_CALL_FAILURE, e); } } @Override public boolean shouldRetry (Resource<?> resource) { return false; } })); } catch (ChaosException e) { log.error("Could not create password-based authentication token", e); } } return authMethods; }  @Override String getUsername(); @Override Callable<String> getPasswordGenerator(); @Override Map<PublicKey, PrivateKey> getSSHKeys(); @Override boolean isSupportSudo(); @Override SSHCredentials withUsername(String username); @Override SSHCredentials withPasswordGenerator(Callable<String> passwordGenerator); @Override SSHCredentials withKeyPair(String privateKey, String publicKey); @Override SSHCredentials withKeyPair(PrivateKey privateKey, PublicKey publicKey); @Override SSHCredentials withSupportSudo(boolean supportSudo); @Override List<AuthMethod> getAuthMethods(); }
ChaosSSHCredentials implements SSHCredentials { @Override public List<AuthMethod> getAuthMethods () { List<AuthMethod> authMethods = sshKeys.entrySet() .stream() .filter(e -> e.getKey() != null && e.getValue() != null) .map(e -> new KeyPairWrapper(e.getKey(), e.getValue())) .map(AuthPublickey::new) .collect(Collectors.toList()); if (passwordGenerator != null) { try { authMethods.add(new AuthPassword(new PasswordFinder() { @Override public char[] reqPassword (Resource<?> resource) { try { return passwordGenerator.call().toCharArray(); } catch (Exception e) { throw new ChaosException(SSH_CREDENTIAL_PASSWORD_CALL_FAILURE, e); } } @Override public boolean shouldRetry (Resource<?> resource) { return false; } })); } catch (ChaosException e) { log.error("Could not create password-based authentication token", e); } } return authMethods; }  @Override String getUsername(); @Override Callable<String> getPasswordGenerator(); @Override Map<PublicKey, PrivateKey> getSSHKeys(); @Override boolean isSupportSudo(); @Override SSHCredentials withUsername(String username); @Override SSHCredentials withPasswordGenerator(Callable<String> passwordGenerator); @Override SSHCredentials withKeyPair(String privateKey, String publicKey); @Override SSHCredentials withKeyPair(PrivateKey privateKey, PublicKey publicKey); @Override SSHCredentials withSupportSudo(boolean supportSudo); @Override List<AuthMethod> getAuthMethods();  }