How to use SinglePublicKeyAuthenticator class of com.consol.citrus.ssh.server package

Best Citrus code snippet using com.consol.citrus.ssh.server.SinglePublicKeyAuthenticator

Source:SinglePublicKeyAuthenticatorTest.java Github

copy

Full Screen

...30/**31 * @author Roland Huss32 * @since 05.09.1233 */34public class SinglePublicKeyAuthenticatorTest {35 /**36 * Default constructor.37 */38 public SinglePublicKeyAuthenticatorTest() {39 assertTrue(SecurityUtils.isBouncyCastleRegistered());40 }41 @Test42 public void withClassPath() throws IOException {43 SinglePublicKeyAuthenticator auth = new SinglePublicKeyAuthenticator("roland","classpath:com/consol/citrus/ssh/allowed_test_key.pem");44 PublicKey pKey = getPublicKey("/com/consol/citrus/ssh/allowed_test_key.pem");45 assertTrue(auth.authenticate("roland", pKey, null));46 assertFalse(auth.authenticate("guenther", pKey, null));47 pKey = getPublicKey("/com/consol/citrus/ssh/forbidden_test_key.pem");48 assertFalse(auth.authenticate("roland", pKey, null));49 pKey = getPublicKey("/com/consol/citrus/ssh/citrus.pem");50 assertFalse(auth.authenticate("citrus", pKey, null));51 }52 @Test53 public void withFile() throws IOException {54 File temp = copyToTempFile("/com/consol/citrus/ssh/allowed_test_key.pem");55 SinglePublicKeyAuthenticator auth = new SinglePublicKeyAuthenticator("roland",temp.getAbsolutePath());56 PublicKey pKey = getPublicKeyFromStream(new FileInputStream(temp));57 assertTrue(auth.authenticate("roland", pKey, null));58 assertFalse(auth.authenticate("guenther",pKey,null));59 temp = copyToTempFile("/com/consol/citrus/ssh/forbidden_test_key.pem");60 pKey = getPublicKeyFromStream(new FileInputStream(temp));61 assertFalse(auth.authenticate("roland", pKey, null));62 }63 @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = ".*com/consol/citrus/ssh/private.key.*")64 public void invalidKeyFormat() {65 new SinglePublicKeyAuthenticator("roland", "classpath:com/consol/citrus/ssh/private.key");66 }67 @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = ".*blubber\\.bla.*")68 public void notInClasspath() {69 new SinglePublicKeyAuthenticator("roland", "classpath:com/consol/citrus/ssh/blubber.bla");70 }71 @Test(expectedExceptions = CitrusRuntimeException.class,expectedExceptionsMessageRegExp = ".*/no/valid/path.*")72 public void invalidFilePath() {73 new SinglePublicKeyAuthenticator("roland","/no/valid/path");74 }75 76 /**77 * Gets public key instance from resource.78 * @param pResource79 * @return80 * @throws IOException81 */82 private PublicKey getPublicKey(String pResource) throws IOException {83 return getPublicKeyFromStream(getClass().getResourceAsStream(pResource));84 }85 /**86 * Creates new temporary file from resource.87 * @param pResource...

Full Screen

Full Screen

Source:SinglePublicKeyAuthenticator.java Github

copy

Full Screen

...33 *34 * @author Roland Huss35 * @since 05.09.1236 */37class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {38 /** Logger */39 private static Logger log = LoggerFactory.getLogger(SinglePublicKeyAuthenticator.class);40 private PublicKey allowedKey;41 private String user;42 private BouncyCastleProvider provider = new BouncyCastleProvider();43 /**44 * Constructor45 *46 * @param username user to verify against47 * @param publicKeyPath path to a single public key PEM, either in the filesystem or, if prefixed48 * with 'classpath:' taken from the classpath.49 */50 public SinglePublicKeyAuthenticator(String username, String publicKeyPath) {51 this.user = username;52 InputStream is = null;53 try {54 is = FileUtils.getFileResource(publicKeyPath).getInputStream();55 allowedKey = readKey(is);56 if (allowedKey == null) {57 throw new CitrusRuntimeException("No public key found at " + publicKeyPath + ", although the file/resource exists. " +58 "It is probably not in a PEM form or contains more than only a public key.");59 }60 } catch (IOException e) {61 throw new CitrusRuntimeException(String.format("Failed to read public key file at %s", publicKeyPath),e);62 } finally {63 IoUtils.closeQuietly(is);64 }...

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ssh.server.SinglePublicKeyAuthenticator;2import com.consol.citrus.ssh.server.SshServer;3import com.consol.citrus.ssh.server.SshServerBuilder;4import com.consol.citrus.ssh.server.SshServerConfiguration;5import org.apache.sshd.common.NamedFactory;6import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;7import org.apache.sshd.common.keyprovider.FileKeyPairProvider;8import org.apache.sshd.common.util.SecurityUtils;9import org.apache.sshd.server.Command;10import org.apache.sshd.server.CommandFactory;11import org.apache.sshd.server.FileSystemAware;12import org.apache.sshd.server.FileSystemFactory;13import org.apache.sshd.server.auth.password.PasswordAuthenticator;14import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator;15import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;16import org.apache.sshd.server.scp.ScpCommandFactory;17import org.apache.sshd.server.sftp.SftpSubsystemFactory;18import org.apache.sshd.server.shell.ProcessShellFactory;19import org.apache.sshd.server.shell.ShellFactory;20import org.apache.sshd.server.shell.UnknownCommandFactory;21import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;22import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory.Builder;23import org.springframework.core.io.ClassPathResource;24import java.io.File;25import java.io.IOException;26import java.util.ArrayList;27import java.util.List;28public class SshServerTest {29 public static void main(String[] args) throws IOException {30 SshServerConfiguration serverConfig = new SshServerConfiguration();31 serverConfig.setPort(2222);32 serverConfig.setHost("localhost");33 serverConfig.setKeyPairProvider(new FileKeyPairProvider(new File[] {new ClassPathResource("server.key").getFile()}));34 serverConfig.setPublickeyAuthenticator(new SinglePublicKeyAuthenticator(new ClassPathResource("server.pub").getFile()));35 serverConfig.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);36 serverConfig.setShellFactory(new ProcessShellFactory(new String[] {"/bin/bash", "-i", "-l"}));37 serverConfig.setSubsystemFactories(new ArrayList<NamedFactory<Command>>() {{38 add(new SftpSubsystemFactory());39 }});40 serverConfig.setFileSystemFactory(new VirtualFileSystemFactory(new File("/tmp")));

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ssh.server.SshServer;2import com.consol.citrus.ssh.server.SshServerBuilder;3import com.consol.citrus.ssh.server.SshServerConfiguration;4import com.consol.citrus.ssh.server.authenticator.SinglePublicKeyAuthenticator;5import com.consol.citrus.ssh.server.command.SshCommand;6import com.consol.citrus.ssh.server.command.SshCommandFactory;7import com.consol.citrus.ssh.server.command.SshCommandResult;8import com.consol.citrus.ssh.server.command.SshCommandResultBuilder;9import com.consol.citrus.ssh.server.command.SshCommandResultStatus;10import com.consol.citrus.ssh.server.command.SshCommandResultStatusBuilder;11import com.consol.citrus.ssh.server.command.SshCommandResultStatusType;12import com.consol.citrus.ssh.server.command.SshCommandResultType;13import com.consol.citrus.ssh.server.command.SshCommandType;14import com.consol.citrus.ssh.server.command.SshCommandTypeBuilder;15import com.consol.citrus.ssh.server.command.SshCommandTypeFactory;16import com.consol.citrus.ssh.server.command.SshCommandTypeFactoryBuilder;17import com.consol.citrus.ssh.server.command.SshCommandTypeFactoryBuilderImpl;18import com.consol.citrus.ssh.server.command.SshCommandTypeFactoryImpl;19import com.consol.citrus.ssh.server.command.SshCommandTypeImpl;20import com.consol.citrus.ssh.server.command.SshCommandTypeImplBuilder;21import com.consol.citrus.ssh.server.command.SshCommandImpl;22import com.consol.citrus.ssh.server.command.SshCommandImplBuilder;23import com.consol.citrus.ssh.server.command.SshCommandFactoryImpl;24import com.consol.citrus.ssh.server.command.SshCommandFactoryImplBuilder;25import com.consol.citrus.ssh.server.command.SshCommandFactoryBuilder;26import com.consol.citrus.ssh.server.command.SshCommandResultBuilderImpl;27import com.consol.citrus.ssh.server.command.SshCommandResultImpl;28import com.consol.citrus.ssh.server.command.SshCommandResultImplBuilder;29import com.consol.citrus.ssh.server.command.SshCommandResultStatusBuilderImpl;30import com.consol.cit

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;3import org.apache.sshd.server.session.ServerSession;4import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;5import org.apache.sshd.server.session.ServerSession;6import org.apache.sshd.common.config.keys.KeyUtils;7import java.security.PublicKey;8import java.io.IOException;9import java.util.Arrays;10import java.util.List;11public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {12 private final PublicKey allowedPublicKey;13 public SinglePublicKeyAuthenticator(PublicKey allowedPublicKey) {14 this.allowedPublicKey = allowedPublicKey;15 }16 public boolean authenticate(String username, PublicKey key, ServerSession session) {17 return KeyUtils.compareKeys(key, allowedPublicKey);18 }19}20package com.consol.citrus.ssh.server;21import org.apache.sshd.server.SshServer;22import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;23import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;24import org.apache.sshd.server.session.ServerSession;25import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;26import org.apache.sshd.server.session.ServerSession;27import org.apache.sshd.common.config.keys.KeyUtils;28import java.security.PublicKey;29import java.io.IOException;30import java.util.Arrays;31import java.util.List;32public class SshServer {33 private final SshServer sshd;34 public SshServer(int port, String hostKeyPath, PublickeyAuthenticator publickeyAuthenticator) {35 sshd = SshServer.setUpDefaultServer();36 sshd.setPort(port);37 sshd.setHost("localhost");38 sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKeyPath));39 sshd.setPublickeyAuthenticator(publickeyAuthenticator);40 }41 public void start() throws IOException {42 sshd.start();43 }44 public void stop() throws IOException {45 sshd.stop();46 }47}48package com.consol.citrus.ssh.server;49import com.consol.citrus.dsl.testng.TestNG

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1{2package com.consol.citrus.ssh.server;3import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;4import org.apache.sshd.server.session.ServerSession;5import java.security.PublicKey;6public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {7 private final PublicKey publicKey;8 public SinglePublicKeyAuthenticator(PublicKey publicKey) {9 this.publicKey = publicKey;10 }11 public boolean authenticate(String username, PublicKey key, ServerSession session) {12 return publicKey.equals(key);13 }14}15}16{17package com.consol.citrus.ssh.server;18import org.apache.sshd.server.SshServer;19import org.apache.sshd.server.auth.UserAuth;20import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;21import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;22import org.apache.sshd.server.session.ServerSession;23import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;24import org.springframework.context.support.ClassPathXmlApplicationContext;25import java.io.IOException;26import java.security.PublicKey;27import java.util.Arrays;28import java.util.Collections;29{30 public static void main(String[] args) throws IOException {31 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");32 SshServer sshd = context.getBean(SshServer.class);33 sshd.setPort(2222);34 sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());35 sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {36 public boolean authenticate(String username, PublicKey key, ServerSession session) {37 return true;38 }39 });40 sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));41 sshd.setShellFactory(new CitrusShellFactory());42 sshd.setCommandFactory(new CitrusCommandFactory());43 sshd.setPublickeyAuthenticator(new SinglePublicKeyAuthenticator(PublicKeyReader.readPublicKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhP3k2Z2aE1kz5hXx5J5zC+5e5G5j3q

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import java.io.File;3import java.io.IOException;4import java.util.ArrayList;5import java.util.List;6import org.apache.sshd.common.NamedFactory;7import org.apache.sshd.common.file.FileSystemFactory;8import org.apache.sshd.common.file.nativefs.NativeFileSystemFactory;9import org.apache.sshd.common.keyprovider.FileKeyPairProvider;10import org.apache.sshd.server.SshServer;11import org.apache.sshd.server.auth.UserAuth;12import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;13import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;14import org.apache.sshd.server.session.ServerSession;15import org.apache.sshd.server.userauth.UserAuthNoneFactory;16import org.apache.sshd.server.userauth.UserAuthPasswordFactory;17import org.apache.sshd.server.userauth.UserAuthPublicKeyFactory;18import org.apache.sshd.server.userauth.UserAuthPublicKey;19import org.apache.sshd.server.userauth.UserAuthPassword;20import org.apache.sshd.server.userauth.UserAuthNone;21import org.apache.sshd.server.userauth.UserAuthKeyboardInteractive;22import org.apache.sshd.server.userauth.UserAuthKeyboardInteractiveFactory;23import org.apache.sshd.server.userauth.UserAuthFactory;24import org.apache.sshd.server.userauth.UserAuthMethod;25public class SinglePublicKeyAuthenticator {26 public static void main(String[] args) throws Exception {27 SshServer sshd = SshServer.setUpDefaultServer();28 sshd.setPort(2222);29 sshd.setKeyPairProvider(new FileKeyPairProvider(new File[] { new File("src/test/resources/id_rsa") }));30 sshd.setHost("localhost");31 sshd.setShellFactory(new SimpleShellFactory());32 sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {33 public boolean authenticate(String username, java.security.PublicKey key, ServerSession session) {34 System.out.println("Public key authentication for user " + username + " with key " + key + " succeeded");35 return true;36 }37 });38 sshd.setPasswordAuthenticator(new PasswordAuthenticator() {39 public boolean authenticate(String username, String password, ServerSession session) {

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import com.consol.citrus.ssh.server.SshServer;3import com.consol.citrus.ssh.server.SshServerBuilder;4import com.consol.citrus.ssh.server.SinglePublicKeyAuthenticator;5import org.apache.sshd.server.auth.password.PasswordAuthenticator;6import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;7import org.apache.sshd.server.session.ServerSession;8import org.springframework.core.io.ClassPathResource;9import java.io.IOException;10import java.nio.file.Files;11import java.nio.file.Path;12import java.nio.file.Paths;13import java.security.PublicKey;14import java.util.ArrayList;15import java.util.List;16public class SshServerTest {17 public static void main(String[] args) {18 .sshServer()19 .port(2222)20 .user("user")21 .password("password")22 .publicKeyAuthenticator(new SinglePublicKeyAuthenticator(new ClassPathResource("ssh/id_rsa.pub")))23 .build();24 sshServer.start();25 }26}27package com.consol.citrus.ssh.server;28import com.consol.citrus.ssh.server.SshServer;29import com.consol.citrus.ssh.server.SshServerBuilder;30import com.consol.citrus.ssh.server.MultiplePublicKeyAuthenticator;31import org.apache.sshd.server.auth.password.PasswordAuthenticator;32import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;33import org.apache.sshd.server.session.ServerSession;34import org.springframework.core.io.ClassPathResource;35import java.io.IOException;36import java.nio.file.Files;37import java.nio.file.Path;38import java.nio.file.Paths;39import java.security.PublicKey;40import java.util.ArrayList;41import java.util.List;42public class SshServerTest {43 public static void main(String[] args) {44 List<Path> keys = new ArrayList<>();45 keys.add(Paths.get("ssh/id_rsa.pub"));46 keys.add(Paths.get("ssh/id_rsa2.pub"));47 .sshServer()48 .port(2222)49 .user("

Full Screen

Full Screen

SinglePublicKeyAuthenticator

Using AI Code Generation

copy

Full Screen

1import java.io.File;2import java.io.IOException;3import java.util.HashMap;4import java.util.Map;5import org.apache.sshd.common.NamedFactory;6import org.apache.sshd.common.keyprovider.FileKeyPairProvider;7import org.apache.sshd.common.util.SecurityUtils;8import org.apache.sshd.server.SshServer;9import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;10import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorDelegate;11import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper;12import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactory;13import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManager;14import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate;15import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactory;16import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactoryManager;17import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactoryManager.PublickeyAuthenticatorFactoryManagerDelegateFactoryManagerFactory;18import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactoryManager.PublickeyAuthenticatorFactoryManagerDelegateFactoryManagerFactoryManager;19import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactoryManager.PublickeyAuthenticatorFactoryManagerDelegateFactoryManagerFactoryManager.PublickeyAuthenticatorFactoryManagerDelegateFactoryManagerFactoryManagerFactory;20import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactoryManager.PublickeyAuthenticatorFactoryManagerDelegateFactoryManagerFactoryManager.PublickeyAuthenticatorFactoryManagerDelegateFactoryManagerFactoryManagerFactoryManager;21import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticatorWrapper.PublickeyAuthenticatorFactoryManagerDelegate.PublickeyAuthenticatorFactoryManagerDelegateFactoryManager.Public

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful