How to use setUser method of com.consol.citrus.ssh.server.SshServer class

Best Citrus code snippet using com.consol.citrus.ssh.server.SshServer.setUser

Source:SshServer.java Github

copy

Full Screen

...110 } catch (IOException e) {111 throw new CitrusRuntimeException("Failed to setup user home dir", e);112 }113 }114 fileSystemFactory.setUserHomeDir(user, userHomeDir);115 sshd.setFileSystemFactory(fileSystemFactory);116 if (hostKeyPath != null) {117 Resource hostKey = FileUtils.getFileResource(hostKeyPath);118 if (hostKey instanceof ClassPathResource) {119 ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList(((ClassPathResource) hostKey).getPath()));120 sshd.setKeyPairProvider(resourceKeyPairProvider);121 } else {122 try {123 FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(Collections.singletonList(hostKey.getFile().toPath()));124 sshd.setKeyPairProvider(fileKeyPairProvider);125 } catch (IOException e) {126 throw new CitrusRuntimeException("Failed to read host key path", e);127 }128 }129 } else {130 ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList("com/consol/citrus/ssh/citrus.pem"));131 sshd.setKeyPairProvider(resourceKeyPairProvider);132 }133 // Authentication134 boolean authFound = false;135 if (password != null) {136 sshd.setPasswordAuthenticator(new SimplePasswordAuthenticator(user, password));137 authFound = true;138 }139 if (allowedKeyPath != null) {140 sshd.setPublickeyAuthenticator(new SinglePublicKeyAuthenticator(user, allowedKeyPath));141 authFound = true;142 }143 if (!authFound) {144 throw new CitrusRuntimeException("Neither 'password' nor 'allowed-key-path' is set. Please provide at least one");145 }146 // Setup endpoint adapter147 ScpCommandFactory commandFactory = new ScpCommandFactory.Builder()148 .withDelegate(command -> new SshCommand(command, getEndpointAdapter(), endpointConfiguration))149 .build();150 commandFactory.addEventListener(getScpTransferEventListener());151 sshd.setCommandFactory(commandFactory);152 ArrayList<NamedFactory<Command>> subsystemFactories = new ArrayList<>();153 SftpSubsystemFactory sftpSubsystemFactory = new SftpSubsystemFactory.Builder().build();154 sftpSubsystemFactory.addSftpEventListener(getSftpEventListener());155 subsystemFactories.add(sftpSubsystemFactory);156 sshd.setSubsystemFactories(subsystemFactories);157 try {158 sshd.start();159 } catch (IOException e) {160 throw new CitrusRuntimeException("Failed to start SSH server - " + e.getMessage(), e);161 }162 }163 /**164 * Gets Scp trsanfer event listener. By default uses abstract implementation that use trace level logging of all operations.165 * @return166 */167 protected ScpTransferEventListener getScpTransferEventListener() {168 return new AbstractScpTransferEventListenerAdapter() {};169 }170 /**171 * Gets Sftp event listener. By default uses abstract implementation that use trace level logging of all operations.172 * @return173 */174 protected SftpEventListener getSftpEventListener() {175 return new AbstractSftpEventListenerAdapter(){};176 }177 @Override178 protected void shutdown() {179 try {180 sshd.stop();181 } catch (IOException e) {182 throw new CitrusRuntimeException("Failed to stop SSH server - " + e.getMessage(), e);183 }184 }185 @Override186 public AbstractPollableEndpointConfiguration getEndpointConfiguration() {187 return endpointConfiguration;188 }189 /**190 * Gets the server port.191 * @return192 */193 public int getPort() {194 return port;195 }196 /**197 * Sets the port.198 * @param port the port to set199 */200 public void setPort(int port) {201 this.port = port;202 this.endpointConfiguration.setPort(port);203 }204 /**205 * Gets the username.206 * @return207 */208 public String getUser() {209 return user;210 }211 /**212 * Sets the user.213 * @param user the user to set214 */215 public void setUser(String user) {216 this.user = user;217 this.endpointConfiguration.setUser(user);218 }219 /**220 * Gets the user password.221 * @return222 */223 public String getPassword() {224 return password;225 }226 /**227 * Sets the password.228 * @param password the password to set229 */230 public void setPassword(String password) {231 this.password = password;232 this.endpointConfiguration.setPassword(password);233 }234 /**235 * Gets the allowed key path.236 * @return237 */238 public String getAllowedKeyPath() {239 return allowedKeyPath;240 }241 /**242 * Sets the allowedKeyPath.243 * @param allowedKeyPath the allowedKeyPath to set244 */245 public void setAllowedKeyPath(String allowedKeyPath) {246 this.allowedKeyPath = allowedKeyPath;247 }248 /**249 * Gets the host key path.250 * @return251 */252 public String getHostKeyPath() {253 return hostKeyPath;254 }255 /**256 * Sets the hostKeyPath.257 * @param hostKeyPath the hostKeyPath to set258 */259 public void setHostKeyPath(String hostKeyPath) {260 this.hostKeyPath = hostKeyPath;261 }262 /**263 * Gets the userHomePath.264 *265 * @return266 */267 public String getUserHomePath() {268 return userHomePath;269 }270 /**271 * Sets the userHomePath.272 *273 * @param userHomePath274 */275 public void setUserHomePath(String userHomePath) {276 this.userHomePath = userHomePath;277 }278 /**279 * Gets the message converter.280 * @return281 */282 public SshMessageConverter getMessageConverter() {283 return messageConverter;284 }285 /**286 * Sets the message converter.287 * @param messageConverter288 */289 public void setMessageConverter(SshMessageConverter messageConverter) {...

Full Screen

Full Screen

Source:SshServerTest.java Github

copy

Full Screen

...46 server.start();47 }48 @Test(expectedExceptions = CitrusRuntimeException.class,expectedExceptionsMessageRegExp = ".*password.*allowed-key-path.*")49 public void noPasswordOrKey() {50 server.setUser("roland");51 server.start();52 }53 @Test(expectedExceptions = CitrusRuntimeException.class,expectedExceptionsMessageRegExp = ".*/no/such/key\\.pem.*")54 public void invalidAuthKey() {55 server.setUser("roland");56 server.setAllowedKeyPath("classpath:/no/such/key.pem");57 server.start();58 }59 @Test60 public void startupAndShutdownWithPassword() throws IOException {61 prepareServer(true);62 server.start();63 64 try {65 assertTrue(server.isRunning());66 new Socket("127.0.0.1", port); // throws exception if it can't connect67 } finally {68 server.stop();69 assertFalse(server.isRunning());70 }71 }72 73 @Test74 public void startupAndShutdown() throws IOException {75 prepareServer(false);76 server.start();77 78 try {79 assertTrue(server.isRunning());80 new Socket("127.0.0.1", port); // throws exception if it can't connect81 } finally {82 server.stop();83 assertFalse(server.isRunning());84 }85 }86 @Test87 public void wrongHostKey() {88 prepareServer(true);89 server.setHostKeyPath("file:/never/existing/directory");90 server.start();91 try {92 org.apache.sshd.server.SshServer sshd = (org.apache.sshd.server.SshServer) ReflectionTestUtils.getField(server, "sshd");93 KeyPairProvider prov = sshd.getKeyPairProvider();94 assertTrue(prov instanceof FileKeyPairProvider);95 Iterable<KeyPair> keys = prov.loadKeys();96 assertFalse(keys.iterator().hasNext());97 } finally {98 server.stop();99 }100 }101 @Test102 public void sshCommandFactory() {103 prepareServer(true);104 server.start();105 try {106 org.apache.sshd.server.SshServer sshd = (org.apache.sshd.server.SshServer) ReflectionTestUtils.getField(server, "sshd");107 CommandFactory fact = sshd.getCommandFactory();108 Command cmd = fact.createCommand("shutdown now");109 assertTrue(cmd instanceof SshCommand);110 assertEquals(((SshCommand) cmd).getCommand(),"shutdown now");111 } finally {112 server.stop();113 }114 }115 @Test(expectedExceptions = CitrusRuntimeException.class,expectedExceptionsMessageRegExp = ".*Address already in use.*")116 public void doubleStart() throws IOException {117 prepareServer(true);118 ServerSocket s = null;119 try {120 s = new ServerSocket(port);121 server.start();122 } finally {123 if (s != null) s.close();124 }125 }126 /**127 * Prepare server instance.128 */129 private void prepareServer(boolean withPassword) {130 server.setUser("roland");131 if (withPassword) {132 server.setPassword("consol");133 } else {134 server.setAllowedKeyPath("classpath:com/consol/citrus/ssh/allowed_test_key.pem");135 }136 }137 /**138 * Finds a free port in port range.139 */140 private int findFreePort() {141 for (int port=2234; port<3000; port++) {142 try {143 Socket socket = new Socket(InetAddress.getLocalHost(),port);144 socket.close();...

Full Screen

Full Screen

Source:SshServerBuilder.java Github

copy

Full Screen

...42 * @param user43 * @return44 */45 public SshServerBuilder user(String user) {46 endpoint.setUser(user);47 return this;48 }49 /**50 * Sets the client password.51 * @param password52 * @return53 */54 public SshServerBuilder password(String password) {55 endpoint.setPassword(password);56 return this;57 }58 /**59 * Sets the hostKeyPath property.60 * @param hostKeyPath61 * @return62 */63 public SshServerBuilder hostKeyPath(String hostKeyPath) {64 endpoint.setHostKeyPath(hostKeyPath);65 return this;66 }67 /**68 * Sets the userHomePath property.69 * @param userHomePath70 * @return71 */72 public SshServerBuilder userHomePath(String userHomePath) {73 endpoint.setUserHomePath(userHomePath);74 return this;75 }76 /**77 * Sets the allowedKeyPath property.78 * @param allowedKeyPath79 * @return80 */81 public SshServerBuilder allowedKeyPath(String allowedKeyPath) {82 endpoint.setAllowedKeyPath(allowedKeyPath);83 return this;84 }85 /**86 * Sets the message converter.87 * @param messageConverter...

Full Screen

Full Screen

setUser

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;3import com.consol.citrus.ssh.client.SshClient;4import com.consol.citrus.ssh.message.SshMessage;5import com.consol.citrus.ssh.server.SshServer;6import org.testng.annotations.Test;7public class SshServerTest extends TestNGCitrusTestRunner {8 public void sshServerTest() {9 SshServer sshServer = new SshServer();10 sshServer.setPort(2222);11 sshServer.setUser("user");12 sshServer.setPassword("password");13 sshServer.setKeyPath("src/test/resources/ssh/id_rsa");14 sshServer.setKeyPassword("password");15 sshServer.setCommand("ls");16 sshServer.setCommandTimeout(60000);17 sshServer.setCommandResult("result");18 sshServer.setCommandError("error");19 sshServer.setCommandExitCode(0);20 sshServer.setCommandResultCode("0");21 sshServer.setCommandResultCode("1");22 sshServer.setCommandResultCode("2");23 sshServer.setCommandResultCode("3");24 sshServer.setCommandResultCode("4");25 sshServer.setCommandResultCode("5");26 sshServer.setCommandResultCode("6");27 sshServer.setCommandResultCode("7");28 sshServer.setCommandResultCode("8");29 sshServer.setCommandResultCode("9");30 sshServer.setCommandResultCode("10");31 sshServer.setCommandResultCode("11");32 sshServer.setCommandResultCode("12");33 sshServer.setCommandResultCode("13");34 sshServer.setCommandResultCode("14");35 sshServer.setCommandResultCode("15");36 sshServer.setCommandResultCode("16");37 sshServer.setCommandResultCode("17");38 sshServer.setCommandResultCode("18");39 sshServer.setCommandResultCode("19");40 sshServer.setCommandResultCode("20");41 sshServer.setCommandResultCode("21");42 sshServer.setCommandResultCode("22");43 sshServer.setCommandResultCode("23");44 sshServer.setCommandResultCode("24");45 sshServer.setCommandResultCode("25");46 sshServer.setCommandResultCode("26");47 sshServer.setCommandResultCode("27");48 sshServer.setCommandResultCode("28");

Full Screen

Full Screen

setUser

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import java.util.ArrayList;3import java.util.List;4import org.springframework.context.annotation.Bean;5import org.springframework.context.annotation.Configuration;6import com.consol.citrus.ssh.server.SshServer;7public class SshServerConfig {8 public SshServer sshServer() {9 SshServer sshServer = new SshServer();10 sshServer.setPort(2222);11 sshServer.setHost("localhost");12 sshServer.setKeyPath("src/test/resources/ssh/server_rsa");13 sshServer.setKeyPassphrase("citrus:systemProperties('ssh.key.passphrase')");14 sshServer.setShellFactory(new EchoShellFactory());15 sshServer.setCommandFactory(new EchoCommandFactory());16 sshServer.setUsers(createSshUsers());17 return sshServer;18 }19 private List<SshUser> createSshUsers() {20 List<SshUser> users = new ArrayList<>();21 users.add(createSshUser("citrus", "citrus"));22 return users;23 }24 private SshUser createSshUser(String name, String password) {25 SshUser user = new SshUser();26 user.setName(name);27 user.setPassword(password);28 return user;29 }30}31package com.consol.citrus.ssh.server;32import java.util.ArrayList;33import java.util.List;34import org.springframework.context.annotation.Bean;35import org.springframework.context.annotation.Configuration;36import com.consol.citrus.ssh.server.SshServer;37public class SshServerConfig {38 public SshServer sshServer() {39 SshServer sshServer = new SshServer();40 sshServer.setPort(2222);41 sshServer.setHost("localhost");42 sshServer.setKeyPath("src/test/resources/ssh/server_rsa");43 sshServer.setKeyPassphrase("citrus:systemProperties('ssh.key.passphrase')");44 sshServer.setShellFactory(new EchoShellFactory());45 sshServer.setCommandFactory(new EchoCommandFactory());46 sshServer.setUsers(createSshUsers());47 return sshServer;48 }49 private List<SshUser> createSshUsers() {50 List<SshUser> users = new ArrayList<>();51 users.add(createSshUser("citrus

Full Screen

Full Screen

setUser

Using AI Code Generation

copy

Full Screen

1public class 3 {2 public static void main(String[] args) throws Exception {3 SshServer server = new SshServer();4 server.setPort(2222);5 server.setHost("localhost");6 server.setUser("user");7 server.setPassword("password");8 server.setKeyPath("src/test/resources/id_rsa");9 server.afterPropertiesSet();10 server.start();11 System.out.println("Server started");12 }13}

Full Screen

Full Screen

setUser

Using AI Code Generation

copy

Full Screen

1SshServer sshServer = new SshServer();2sshServer.setPort(22);3sshServer.setHost("localhost");4sshServer.setUser("user");5sshServer.setPublicKey("/home/user/.ssh/id_rsa.pub");6sshServer.setPrivateKey("/home/user/.ssh/id_rsa");7sshServer.setKnownHosts("/home/user/.ssh/known_hosts");8sshServer.setCommand("ls");9sshServer.setCommand("ls");10sshServer.setCommand("ls");11sshServer.setCommand("ls");12sshServer.setCommand("ls");13sshServer.setCommand("ls");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful