Best Citrus code snippet using com.consol.citrus.ssh.server.SinglePublicKeyAuthenticator.CitrusRuntimeException
Source:SinglePublicKeyAuthenticatorTest.java
...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.ssh.server;17import com.consol.citrus.exceptions.CitrusRuntimeException;18import org.apache.sshd.common.util.io.IoUtils;19import org.apache.sshd.common.util.security.SecurityUtils;20import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;21import org.bouncycastle.jce.provider.BouncyCastleProvider;22import org.bouncycastle.openssl.PEMKeyPair;23import org.bouncycastle.openssl.PEMParser;24import org.springframework.util.FileCopyUtils;25import org.testng.annotations.Test;26import java.io.*;27import java.security.PublicKey;28import static org.testng.Assert.assertFalse;29import static org.testng.Assert.assertTrue;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 pResource88 * @return89 * @throws IOException90 */91 private File copyToTempFile(String pResource) throws IOException {92 File temp = File.createTempFile("citrus-ssh", "pem");93 FileCopyUtils.copy(getClass().getResourceAsStream(pResource),94 new FileOutputStream(temp));95 return temp;96 }97 98 /**99 * Create public key instance from file input stream.100 * @param is101 * @return102 * @throws IOException103 */104 private PublicKey getPublicKeyFromStream(InputStream is) throws IOException {105 Reader reader = new InputStreamReader(is);106 try {107 Object o = new PEMParser(reader).readObject();108 if (o instanceof PEMKeyPair) {109 return new BouncyCastleProvider().getPublicKey(((PEMKeyPair) o).getPublicKeyInfo());110 } else if (o instanceof SubjectPublicKeyInfo) {111 return new BouncyCastleProvider().getPublicKey((SubjectPublicKeyInfo) o);112 } else {113 throw new CitrusRuntimeException("Unable to read public key");114 }115 } catch (IOException e) {116 throw new CitrusRuntimeException("Failed to read public key", e);117 } finally {118 IoUtils.closeQuietly(is, reader);119 }120 }121}...
Source:SinglePublicKeyAuthenticator.java
...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.ssh.server;17import com.consol.citrus.exceptions.CitrusRuntimeException;18import com.consol.citrus.util.FileUtils;19import org.apache.sshd.common.util.io.IoUtils;20import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;21import org.apache.sshd.server.session.ServerSession;22import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;23import org.bouncycastle.jce.provider.BouncyCastleProvider;24import org.bouncycastle.openssl.PEMKeyPair;25import org.bouncycastle.openssl.PEMParser;26import org.slf4j.Logger;27import org.slf4j.LoggerFactory;28import java.io.*;29import java.security.PublicKey;30/**31 * Public key authenticator which verifies a single provided public key. The public key32 * itself must be in PEM format.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 }65 }66 /**67 * {@inheritDoc}68 */69 public boolean authenticate(String pUser, PublicKey pKey, ServerSession pSession) {70 return user != null && user.equals(pUser) && allowedKey.equals(pKey);71 }72 /**73 * Read the key with bouncycastle's PEM tools 74 * @param is75 * @return...
CitrusRuntimeException
Using AI Code Generation
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 java.security.PublicKey;6public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {7 private PublicKey publicKey;8 public SinglePublicKeyAuthenticator(PublicKey publicKey) {9 this.publicKey = publicKey;10 }11 public boolean authenticate(String username, PublicKey key, ServerSession session) {12 return key.equals(publicKey);13 }14}15package com.consol.citrus.ssh.server;16import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;17import org.apache.sshd.server.session.ServerSession;18import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;19import java.security.PublicKey;20public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {21 private PublicKey publicKey;22 public SinglePublicKeyAuthenticator(PublicKey publicKey) {23 this.publicKey = publicKey;24 }25 public boolean authenticate(String username, PublicKey key, ServerSession session) {26 return key.equals(publicKey);27 }28}29package com.consol.citrus.ssh.server;30import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;31import org.apache.sshd.server.session.ServerSession;32import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;33import java.security.PublicKey;34public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {35 private PublicKey publicKey;36 public SinglePublicKeyAuthenticator(PublicKey publicKey) {37 this.publicKey = publicKey;38 }39 public boolean authenticate(String username, PublicKey key, ServerSession session) {40 return key.equals(publicKey);41 }42}43package com.consol.citrus.ssh.server;44import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;45import org.apache.s
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import org.apache.sshd.server.session.ServerSession;3import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;4import org.apache.sshd.common.util.Buffer;5import org.apache.sshd.common.util.KeyUtils;6import org.apache.sshd.common.util.SecurityUtils;7import org.apache.sshd.common.util.ValidateUtils;8import org.apache.sshd.common.util.io.IoUtils;9import org.apache.sshd.common.util.logging.AbstractLoggingBean;10import org.apache.sshd.common.util.logging.LoggingLevel;11import org.apache.sshd.common.util.security.SecurityUtils;12import org.apache.sshd.common.util.security.bouncycastle.BouncyCastleUtils;13import org.apache.sshd.common.util.security.eddsa.BCEdDSAPublicKey;14import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProviderRegistrar;15import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProviderRegistrar;16import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProv
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import java.io.File;3import java.io.IOException;4import java.nio.file.Files;5import java.nio.file.Paths;6import java.security.PublicKey;7import java.util.List;8import org.apache.sshd.common.config.keys.KeyUtils;9import org.apache.sshd.common.util.GenericUtils;10import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;11import org.apache.sshd.server.session.ServerSession;12import org.slf4j.Logger;13import org.slf4j.LoggerFactory;14import com.consol.citrus.exceptions.CitrusRuntimeException;15public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {16 private static final Logger LOG = LoggerFactory.getLogger(SinglePublicKeyAuthenticator.class);17 private final File authorizedKeysFile;18 private PublicKey authorizedKey;19 public SinglePublicKeyAuthenticator(File authorizedKeysFile) {20 this.authorizedKeysFile = authorizedKeysFile;21 }22 public boolean authenticate(String username, PublicKey key, ServerSession session) {23 if (authorizedKey == null) {24 LOG.info("Loading authorized key file: '" + authorizedKeysFile.getAbsolutePath() + "'");25 List<String> lines;26 try {27 lines = Files.readAllLines(Paths.get(authorizedKeysFile.getAbsolutePath()));28 } catch (IOException e) {29 throw new CitrusRuntimeException("Failed to read authorized key file", e);30 }31 if (GenericUtils.isEmpty(lines)) {32 throw new CitrusRuntimeException("No public keys found in authorized key file");33 }34 authorizedKey = KeyUtils.createPublicKey(lines.get(0));35 }36 return authorizedKey.equals(key);37 }38}39package com.consol.citrus.ssh.server;40import java.io.File;41import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;42import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;43import org.apache.sshd.server.session.ServerSession;44import org.springframework.context.annotation.Bean;45import org.springframework.context.annotation.Configuration;46public class SshServerConfig {47 public SshServer sshServer() {48 SshServer sshServer = new SshServer();49 sshServer.setPort(2222);50 sshServer.setHost("localhost");51 sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("target/hostkey.ser")));52 sshServer.setPublickeyAuthenticator(publickeyAuthenticator
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import com.consol.citrus.exceptions.CitrusRuntimeException;3import com.consol.citrus.ssh.server.SshServer;4import org.apache.sshd.common.session.Session;5import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;6import org.apache.sshd.server.session.ServerSession;7import org.springframework.core.io.ClassPathResource;8import java.io.IOException;9import java.security.PublicKey;10public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {11 private final PublicKey publicKey;12 public SinglePublicKeyAuthenticator(String publicKeyPath) {13 try {14 this.publicKey = SshServer.readPublicKey(new ClassPathResource(publicKeyPath).getInputStream());15 } catch (IOException e) {16 throw new CitrusRuntimeException("Failed to read public key resource", e);17 }18 }19 public boolean authenticate(String username, PublicKey key, ServerSession session) {20 return publicKey.equals(key);21 }22}23package com.consol.citrus.ssh.server;24import org.apache.sshd.common.session.Session;25import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;26import org.apache.sshd.server.session.ServerSession;27import java.security.PublicKey;28public class AcceptAllPublicKeysAuthenticator implements PublickeyAuthenticator {29 public boolean authenticate(String username, PublicKey key, ServerSession session) {30 return true;31 }32}33package com.consol.citrus.ssh.server;34import org.apache.sshd.common.session.Session;35import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;36import org.apache.sshd.server.session.ServerSession;37import java.security.PublicKey;38public class RejectAllPublicKeysAuthenticator implements PublickeyAuthenticator {39 public boolean authenticate(String username, PublicKey key, ServerSession session) {40 return false;41 }42}43package com.consol.citrus.ssh.server;44import com.consol.citrus.exceptions.CitrusRuntimeException;45import com.consol.citrus.ssh.server.SshServer;46import org.apache.sshd.common.session.Session;47import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;48import org.apache.sshd.server
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import java.io.File;3import java.util.ArrayList;4import java.util.List;5import org.apache.sshd.common.config.keys.KeyUtils;6import org.apache.sshd.common.util.security.SecurityUtils;7import org.apache.sshd.server.auth.password.PasswordAuthenticator;8import org.apache.sshd.server.session.ServerSession;9import org.springframework.beans.factory.annotation.Autowired;10import org.springframework.beans.factory.annotation.Value;11import org.springframework.core.io.Resource;12import org.springframework.core.io.ResourceLoader;13import org.springframework.stereotype.Component;14import com.consol.citrus.exceptions.CitrusRuntimeException;15import com.consol.citrus.ssh.server.auth.SshAuthenticationProvider;16import com.consol.citrus.ssh.server.auth.SshPasswordAuthenticator;17import com.consol.citrus.ssh.server.auth.SshPublicKeyAuthenticator;18import com.consol.citrus.ssh.server.auth.SshUserAuthenticator;19import com.consol.citrus.ssh.server.auth.SshUserAuthenticatorProvider;20import com.consol.citrus.ssh.server.auth.SshUserAuthenticatorProviderImpl;21import com.consol.citrus.ssh.server.auth.SshUserAuthenticatorProviderImpl.SshUserAuthenticatorProviderBuilder;22import com.consol.citrus.ssh.server.auth.SshUserAuthenticatorProviderImpl.SshUserAuthenticatorProviderBuilder.SshUserAuthenticatorProviderBuilderImpl;23import com.consol.citrus.ssh.server.auth.SshUserAuthenticatorProviderImpl.SshUserAuthenticatorProviderBuilderImpl.SshUserAuthenticatorProviderBuilderImplImpl;24public class SinglePublicKeyAuthenticator implements SshUserAuthenticator {25 private ResourceLoader resourceLoader;26 @Value("${ssh.public.key}")27 private String publicKey;28 public SshUserAuthenticatorProvider getProvider() {29 final SshUserAuthenticatorProviderBuilderImplImpl providerBuilder = SshUserAuthenticatorProviderImpl.builder();30 providerBuilder.withAuthenticationProvider(getAuthenticationProvider());31 return providerBuilder.build();32 }33 private SshAuthenticationProvider getAuthenticationProvider() {34 final SshPasswordAuthenticator passwordAuthenticator = new SshPasswordAuthenticator();35 passwordAuthenticator.setPasswordAuthenticator(new PasswordAuthenticator() {36 public boolean authenticate(String username, String password, ServerSession session) {37 return false;38 }39 });
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2public class SinglePublicKeyAuthenticator extends org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator {3public boolean authenticate(String username, PublicKey key, ServerSession session) {4throw new CitrusRuntimeException("Invalid public key");5}6}7package com.consol.citrus.ssh.server;8import org.apache.sshd.server.session.ServerSession;9import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;10import org.apache.sshd.common.session.SessionContext;11import org.apache.sshd.common.util.buffer.Buffer;12import org.apache.sshd.common.util.buffer.ByteArrayBuffer;13import org.apache.sshd.common.util.buffer.BufferUtils;14import org.apache.sshd.common.util.buffer.BufferUtils.ClearableBuffer;15import org.apache.sshd.common.signature.Signature;16import org.apache.sshd.common.signature.SignatureFactoriesManager;17import org.apache.sshd.common.signature.SignatureFactory;18import org.apache.sshd.common.signature.SignatureFactoriesManager;19import org.apache.sshd.common.signature.Signature;20import org.apache.sshd.common.signature.SignatureFactory;21import org.apache.sshd.common.signature.SignatureFactoriesManager;22import org.apache.sshd.common.signature.Signature;23import org.apache.sshd.common.signature.SignatureFactory;24import org.apache.sshd.common.signature.SignatureFactoriesManager;25import org.apache.sshd.common.signature.Signature;26import org.apache.sshd.common.signature.SignatureFactory;27import org.apache.sshd.common.signature.SignatureFactoriesManager;28import org.apache.sshd.common.signature.Signature;29import org.apache.sshd.common.signature.SignatureFactory;30import org.apache.sshd.common.signature.SignatureFactoriesManager;31import org.apache.sshd.common.signature.Signature;32import org.apache.sshd.common.signature.SignatureFactory;33import org.apache.sshd.common.signature.SignatureFactoriesManager;34import org.apache.sshd.common.signature.Signature;35import org.apache.sshd.common.signature.SignatureFactory;36import org.apache.sshd.common.signature.SignatureFactoriesManager;37import org.apache.sshd.common.signature.Signature;38import org.apache.sshd.common.signature.SignatureFactory;39import org.apache.sshd.common.signature.SignatureFactoriesManager;40import
CitrusRuntimeException
Using AI Code Generation
1import com.consol.citrus.ssh.server.SinglePublicKeyAuthenticator;2SinglePublicKeyAuthenticator singlePublicKeyAuthenticator = new SinglePublicKeyAuthenticator();3singlePublicKeyAuthenticator.setPublicKey("publicKey");4singlePublicKeyAuthenticator.setException(new CitrusRuntimeException("exception"));5import com.consol.citrus.ssh.server.SinglePublicKeyAuthenticator;6SinglePublicKeyAuthenticator singlePublicKeyAuthenticator = new SinglePublicKeyAuthenticator();7singlePublicKeyAuthenticator.setPublicKey("publicKey");8singlePublicKeyAuthenticator.getException();
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import org.apache.sshd.common.util.security.SecurityUtils;3import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;4import org.apache.sshd.server.session.ServerSession;5import org.testng.annotations.Test;6import java.security.PublicKey;7import static org.testng.Assert.assertEquals;8public class SinglePublicKeyAuthenticatorTest {9 public void test() {10 SinglePublicKeyAuthenticator singlePublicKeyAuthenticator = new SinglePublicKeyAuthenticator();11 PublicKey publicKey = SecurityUtils.createTestHostKeyProvider().loadKey("dsa");12 ServerSession serverSession = new ServerSession();13 PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {14 public boolean authenticate(String s, PublicKey publicKey, ServerSession serverSession) {15 return false;16 }17 };18 singlePublicKeyAuthenticator.setDelegate(publickeyAuthenticator);19 assertEquals(singlePublicKeyAuthenticator.getDelegate(), publickeyAuthenticator);20 }21}
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import com.consol.citrus.exceptions.CitrusRuntimeException;3import com.consol.citrus.ssh.SshServer;4import com.consol.citrus.ssh.SshServerBuilder;5import com.consol.citrus.ssh.SshServerConfiguration;6import com.consol.citrus.ssh.SshServerConfigurationBuilder;7import com.consol.citrus.ssh.SshServerSupport;8import com.consol.citrus.ssh.SshServerSupportBuilder;9import com.consol.citrus.ssh.SshServerSupportBuilder;10import com.consol.citrus.ssh.SshServerSupport;11import com.consol.citrus.ssh.SshServerSupportBuilder;12import com.consol.citrus.ssh.SshServerSupport;13import com.consol.citrus.ssh.SshServerSupportBuilder;14import com.consol.citrus.ssh.SshServerSupport;15import com.consol.citrus.ssh.SshServerSupportBuilder;16import com.consol.citrus.ssh.SshServerSupport;17import com.consol.citrus.ssh.SshServerSupportBuilder;18import com.consol.citrus.ssh.SshServerSupport;19import com.consol.citrus.ssh.SshServerSupportBuilder;20import com.consol.citrus.ssh.SshServerSupport;21import com.consol.citrus.ssh.SshServerSupportBuilder;22import com.consol.citrus.ssh.SshServerSupport;23import com.consol.citrus.ssh.SshServerSupportBuilder;24import com.consol.citrus.ssh.SshServerSupport;25import com.consol.citrus.ssh.SshServerSupportBuilder;26import com.consol.citrus.ssh.SshServerSupport;27import com.consol.citrus.ssh.SshServerSupportBuilder;28import com.consol.citrus.ssh.SshServerSupport;29import com.consol.citrus.ssh.SshServerSupportBuilder;30import com.consol.citrus.ssh.SshServerSupport;31import com.consol.citrus.ssh.SshServerSupportBuilder;32import com.consol.citrus.ssh.SshServerSupport;33import com.consol.citrus.ssh.SshServerSupportBuilder;34import com.consol.citrus.ssh.SshServerSupport;
CitrusRuntimeException
Using AI Code Generation
1package com.consol.citrus.ssh.server;2import java.io.IOException;3import java.security.PublicKey;4import java.util.Arrays;5import org.apache.sshd.common.config.keys.KeyUtils;6import org.apache.sshd.common.session.Session;7import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;8import org.apache.sshd.server.session.ServerSession;9import org.apache.sshd.server.session.ServerSessionHolder;10import org.slf4j.Logger;11import org.slf4j.LoggerFactory;12public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {13 private static final Logger LOG = LoggerFactory.getLogger(SinglePublicKeyAuthenticator.class);14 private final PublicKey publicKey;15 public SinglePublicKeyAuthenticator(PublicKey publicKey) {16 this.publicKey = publicKey;17 }18 public boolean authenticate(String username, PublicKey key, ServerSession session) {19 try {20 if (KeyUtils.compareKeys(key, publicKey)) {21 LOG.info("Public key authentication successful for user '{}'", username);22 return true;23 } else {24 LOG.info("Public key authentication failed for user '{}'", username);25 CitrusRuntimeException exception = new CitrusRuntimeException("Public key authentication failed");26 throw exception;27 }28 } catch (IOException e) {29 LOG.info("Public key authentication failed for user '{}'", username);30 CitrusRuntimeException exception = new CitrusRuntimeException("Public key authentication failed");31 throw exception;32 }33 }34}35package com.consol.citrus.ssh.server;36import java.io.IOException;37import java.security.PublicKey;38import java.util.Arrays;39import org.apache.sshd.common.config.keys.KeyUtils;40import org.apache.sshd.common.session.Session;41import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;42import org.apache.sshd.server.session.ServerSession;43import org.apache.sshd.server.session.ServerSessionHolder;44import org.slf4j.Logger;45import org.slf4j.LoggerFactory;46public class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {47 private static final Logger LOG = LoggerFactory.getLogger(SinglePublicKeyAuthenticator.class);48 private final PublicKey publicKey;49 public SinglePublicKeyAuthenticator(PublicKey
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!