Search in sources :

Example 1 with UserAuthPasswordFactory

use of org.apache.sshd.server.auth.password.UserAuthPasswordFactory in project scheduling by ow2-proactive.

the class TestSSHInfrastructureV2 method startSSHServer.

@BeforeClass
public static void startSSHServer() throws Exception {
    // Disable bouncy castle to avoid versions conflict
    System.setProperty("org.apache.sshd.registerBouncyCastle", "false");
    sshd = SshServer.setUpDefaultServer();
    SimpleGeneratorHostKeyProvider keyProvider = new SimpleGeneratorHostKeyProvider();
    keyProvider.setAlgorithm("RSA");
    sshd.setKeyPairProvider(keyProvider);
    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>(1);
    userAuthFactories.add(new UserAuthPasswordFactory());
    sshd.setUserAuthFactories(userAuthFactories);
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            return username != null && username.equals(password);
        }
    });
    CommandFactory cf = new CommandFactory() {

        @Override
        public Command createCommand(String command) {
            String[] splitCommand;
            if (OsUtils.isUNIX()) {
                splitCommand = SSHInfrastructureHelper.splitCommand(command);
            } else if (OsUtils.isWin32()) {
                splitCommand = SSHInfrastructureHelper.splitCommandWithoutRemovingQuotes(command);
            } else {
                throw new IllegalStateException("Operating system is not recognized");
            }
            StringBuilder rebuiltCommand = new StringBuilder();
            for (String commandPiece : splitCommand) {
                rebuiltCommand.append(commandPiece).append(" ");
            }
            rebuiltCommand.trimToSize();
            if (OsUtils.isUNIX()) {
                return new ProcessShellFactory(new String[] { "/bin/sh", "-c", rebuiltCommand.toString() }).create();
            } else {
                return new ProcessShellFactory(new String[] { "cmd.exe", "/C", rebuiltCommand.toString() }).create();
            }
        }
    };
    sshd.setCommandFactory(cf);
    sshd.start();
    port = sshd.getPort();
    javaExePath = System.getProperty("java.home") + File.separator + "bin" + File.separator + (OsUtils.isWin32() ? "java.exe" : "java");
    javaExePath = "\"" + javaExePath + "\"";
    infraParams = new Object[] { // hosts
    ("localhost " + NB_NODES + "\n").getBytes(), // timeout
    60000, // attempts
    0, // wait between failures
    10, // ssh server port
    port, // ssh username
    "toto", // ssh password
    "toto", // optional ssh private key
    new byte[0], // optional ssh options file
    new byte[0], // java path on the remote machines
    javaExePath, // Scheduling path on remote machines
    PAResourceManagerProperties.RM_HOME.getValueAsString(), OperatingSystem.getOperatingSystem(), "", "", "", "", // extra java options and startup script parameters
    "" };
    policyParameters = new Object[] { AccessType.ALL.toString(), AccessType.ALL.toString(), "20000" };
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) UserAuthPasswordFactory(org.apache.sshd.server.auth.password.UserAuthPasswordFactory) ServerSession(org.apache.sshd.server.session.ServerSession) ArrayList(java.util.ArrayList) CommandFactory(org.apache.sshd.server.CommandFactory) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) PasswordAuthenticator(org.apache.sshd.server.auth.password.PasswordAuthenticator) NamedFactory(org.apache.sshd.common.NamedFactory) ProcessShellFactory(org.apache.sshd.server.shell.ProcessShellFactory) BeforeClass(org.junit.BeforeClass)

Example 2 with UserAuthPasswordFactory

use of org.apache.sshd.server.auth.password.UserAuthPasswordFactory in project karaf by apache.

the class UserAuthFactoriesFactory method setAuthMethods.

public void setAuthMethods(String[] methods) {
    this.methodSet = new HashSet<>();
    this.factories = new ArrayList<>();
    for (String am : methods) {
        if (PASSWORD_METHOD.equals(am)) {
            this.factories.add(new UserAuthPasswordFactory());
        } else if (KEYBOARD_INTERACTIVE_METHOD.equals(am)) {
            this.factories.add(new UserAuthKeyboardInteractiveFactory());
        } else if (PUBLICKEY_METHOD.equals(am)) {
            this.factories.add(new UserAuthPublicKeyFactory());
        } else {
            throw new IllegalArgumentException("Invalid authentication method " + am + " specified");
        }
        this.methodSet.add(am);
    }
}
Also used : UserAuthPasswordFactory(org.apache.sshd.server.auth.password.UserAuthPasswordFactory) UserAuthPublicKeyFactory(org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory) UserAuthKeyboardInteractiveFactory(org.apache.sshd.server.auth.keyboard.UserAuthKeyboardInteractiveFactory)

Aggregations

UserAuthPasswordFactory (org.apache.sshd.server.auth.password.UserAuthPasswordFactory)2 ArrayList (java.util.ArrayList)1 NamedFactory (org.apache.sshd.common.NamedFactory)1 CommandFactory (org.apache.sshd.server.CommandFactory)1 UserAuthKeyboardInteractiveFactory (org.apache.sshd.server.auth.keyboard.UserAuthKeyboardInteractiveFactory)1 PasswordAuthenticator (org.apache.sshd.server.auth.password.PasswordAuthenticator)1 UserAuthPublicKeyFactory (org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory)1 SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)1 ScpCommandFactory (org.apache.sshd.server.scp.ScpCommandFactory)1 ServerSession (org.apache.sshd.server.session.ServerSession)1 ProcessShellFactory (org.apache.sshd.server.shell.ProcessShellFactory)1 BeforeClass (org.junit.BeforeClass)1