@Before public void setPasswordAuthenticator() throws IOException { fixture.getServer().setUserAuthFactories(Collections.<NamedFactory<UserAuth>>singletonList(new NamedFactory<UserAuth>() { @Override public String getName() {
private void configureAuthentication(SshServer sshd) { NamedFactory<UserAuth> auth; if (this.passwordAuthenticator != null) { sshd.setPasswordAuthenticator(this.passwordAuthenticator); auth = new UserAuthPasswordFactory(); } else { auth = new UserAuthNoneFactory(); } sshd.setUserAuthFactories(Collections.singletonList(auth)); }
@Override protected void checkConfig() { super.checkConfig(); ValidateUtils.checkTrue(getPort() >= 0 /* zero means not set yet */, "Bad port number: %d", Integer.valueOf(getPort())); List<NamedFactory<UserAuth>> authFactories = ServerAuthenticationManager.resolveUserAuthFactories(this); setUserAuthFactories(ValidateUtils.checkNotNullAndNotEmpty(authFactories, "UserAuthFactories not set")); ValidateUtils.checkNotNullAndNotEmpty(getChannelFactories(), "ChannelFactories not set"); Objects.requireNonNull(getKeyPairProvider(), "HostKeyProvider not set"); Objects.requireNonNull(getFileSystemFactory(), "FileSystemFactory not set"); if (GenericUtils.isEmpty(getServiceFactories())) { setServiceFactories(DEFAULT_SERVICE_FACTORIES); } }
@Override protected void checkConfig() { super.checkConfig(); ValidateUtils.checkTrue(getPort() >= 0 /* zero means not set yet */, "Bad port number: %d", Integer.valueOf(getPort())); List<NamedFactory<UserAuth>> authFactories = ServerAuthenticationManager.resolveUserAuthFactories(this); setUserAuthFactories(ValidateUtils.checkNotNullAndNotEmpty(authFactories, "UserAuthFactories not set")); ValidateUtils.checkNotNullAndNotEmpty(getChannelFactories(), "ChannelFactories not set"); Objects.requireNonNull(getKeyPairProvider(), "HostKeyProvider not set"); Objects.requireNonNull(getFileSystemFactory(), "FileSystemFactory not set"); if (GenericUtils.isEmpty(getServiceFactories())) { setServiceFactories(DEFAULT_SERVICE_FACTORIES); } }
@Override protected void before() throws Throwable { sshd = SshServer.setUpDefaultServer(); sshd.setPort(findRandomOpenPortOnAllLocalInterfaces()); sshd.setKeyPairProvider( new ClassLoadableResourceKeyPairProvider(getClass().getClassLoader(), "server_key")); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); sshd.setUserAuthFactories(Collections.singletonList(new UserAuthPublicKeyFactory())); sshd.setHost("localhost"); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setHostBasedAuthenticator(new StaticHostBasedAuthenticator(true)); VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(); fileSystemFactory.setDefaultHomeDir(currentFolder.get().toPath()); sshd.setFileSystemFactory(fileSystemFactory); sshd.start(); }
public static SshServer create() { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(SpashConfig.getInstance().spashListenPort()); AbstractGeneratorHostKeyProvider keyProvider = new SimpleGeneratorHostKeyProvider(new File(SpashConfig.getInstance().spashKeyFileName())); keyProvider.setAlgorithm(SpashConfig.getInstance().spashKeyAlgorithm()); keyProvider.setKeySize(SpashConfig.getInstance().spashKeyLength()); sshd.setKeyPairProvider(keyProvider); List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>(); userAuthFactories.add(new UserAuthPasswordFactory()); sshd.setUserAuthFactories(userAuthFactories); sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession serverSession) throws PasswordChangeRequiredException { return username!=null && username.length()>0 && username.equals(password); } }); sshd.setShellFactory(new SpashShellFactory()); List<NamedFactory<Command>> namedFactoryList = new ArrayList<>(); namedFactoryList.add(new SftpSubsystemFactory()); sshd.setSubsystemFactories(namedFactoryList); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setFileSystemFactory(new FileSystemFactory() { @Override public FileSystem createFileSystem(Session session) throws IOException { return SpashFileSystem.get().getFileSystem(); } }); return sshd; }
@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))); 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); }
server.setPasswordAuthenticator(authenticator); server.setPublickeyAuthenticator(authenticator); server.setUserAuthFactories(authFactoriesFactory.getFactories()); server.setAgentFactory(KarafAgentFactory.getInstance()); server.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
server.setPasswordAuthenticator(authenticator); server.setPublickeyAuthenticator(authenticator); server.setUserAuthFactories(authFactoriesFactory.getFactories()); server.setAgentFactory(KarafAgentFactory.getInstance()); server.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( new org.apache.sshd.server.auth.password.UserAuthPasswordFactory() { @Override
sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( new org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory() { @Override
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); sshd.setUserAuthFactories( Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE));
sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( new org.apache.sshd.server.auth.password.UserAuthPasswordFactory() { @Override
sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( new org.apache.sshd.server.auth.password.UserAuthPasswordFactory() { @Override
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); sshd.setUserAuthFactories( Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE));
sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( new org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory() { @Override
sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( new org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory() { @Override
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); sshd.setUserAuthFactories( Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE));