Search in sources :

Example 1 with UserAuthPublicKeyFactory

use of org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory in project jPOS by jpos.

the class SshService method startService.

@Override
protected void startService() throws Exception {
    String username = cfg.get("auth-username", "admin");
    String authorizedKeysFilename = cfg.get("authorized-keys-file", "cfg/authorized_keys");
    String hostKeys = cfg.get("hostkeys-file", "cfg/hostkeys.ser");
    int port = cfg.getInt("port", 2222);
    checkAuthorizedKeys(authorizedKeysFilename);
    String[] prefixes = getPrefixes();
    sshd = SshServer.setUpDefaultServer();
    sshd.setPort(port);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(hostKeys).toPath()));
    CliShellFactory csf = new CliShellFactory(getServer(), prefixes);
    sshd.setShellFactory(csf);
    sshd.setCommandFactory(csf);
    sshd.setUserAuthFactories(Collections.singletonList(new UserAuthPublicKeyFactory()));
    sshd.setPublickeyAuthenticator(new AuthorizedKeysFileBasedPKA(username, authorizedKeysFilename));
    sshd.start();
    log.info("Started SSHD @ port " + port);
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) UserAuthPublicKeyFactory(org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory) File(java.io.File)

Example 2 with UserAuthPublicKeyFactory

use of org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory 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

UserAuthPublicKeyFactory (org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory)2 File (java.io.File)1 UserAuthKeyboardInteractiveFactory (org.apache.sshd.server.auth.keyboard.UserAuthKeyboardInteractiveFactory)1 UserAuthPasswordFactory (org.apache.sshd.server.auth.password.UserAuthPasswordFactory)1 SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)1