/** * Returns {@code true} if and only if the supplied connection class and user class are supported by at least one * factory. * * @param connectionClass the connection class. * @param userClass the user class. * @param <C> the type of connection. * @param <U> the type of user. * @return {@code true} if and only if the supplied connection class and user class are supported by at least one * factory. */ public static <C, U extends StandardUsernameCredentials> boolean isSupported(@NonNull Class<C> connectionClass, @NonNull Class<U> userClass) { connectionClass.getClass(); // throw NPE if null userClass.getClass(); // throw NPE if null for (SSHAuthenticatorFactory factory : ExtensionList.lookup(SSHAuthenticatorFactory.class)) { if (factory.supports(connectionClass, userClass)) { return true; } } return false; }
/** * Returns an instance of {@link SSHAuthenticator} for the supplied connection and user, or {@code null} if * the factory does not support the connection and user combination. * * @param connection the connection. * @param user the user. * @param username the username or {@code null} to fall back to the username in the user parameter. * @param <C> the type of connection. * @param <U> the type of user. * @return {@code null} if the connection or user is not supported by this factory, or a {@link SSHAuthenticator} * instance bound to the supplied connection and user. * @since 1.4 */ @Nullable protected <C, U extends StandardUsernameCredentials> SSHAuthenticator<C, U> newInstance( @NonNull C connection, @NonNull U user, @CheckForNull String username) { return newInstance(connection, user); }
SSHAuthenticator<C, U> result = factory.newInstance(connection, user, username); if (result != null && result.canAuthenticate()) { return result;