use of org.apache.sshd.server.session.ServerSession in project camel by apache.
the class SftpServerTestSupport method setUpServer.
protected void setUpServer() throws Exception {
canTest = true;
try {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {
// consider all keys as authorized for all users
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
};
sshd.setPublickeyAuthenticator(publickeyAuthenticator);
sshd.start();
} catch (Exception e) {
// ignore if algorithm is not on the OS
NoSuchAlgorithmException nsae = ObjectHelper.getException(NoSuchAlgorithmException.class, e);
if (nsae != null) {
canTest = false;
String name = System.getProperty("os.name");
String message = nsae.getMessage();
log.warn("SunX509 is not avail on this platform [{}] Testing is skipped! Real cause: {}", name, message);
} else {
// some other error then throw it so the test can fail
throw e;
}
}
}
use of org.apache.sshd.server.session.ServerSession in project hadoop by apache.
the class TestSFTPFileSystem method startSshdServer.
private static void startSshdServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
// ask OS to assign a port
sshd.setPort(0);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
if (username.equals("user") && password.equals("password")) {
return true;
}
return false;
}
});
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.start();
port = sshd.getPort();
}
use of org.apache.sshd.server.session.ServerSession in project gitblit by gitblit.
the class SshKerberosAuthenticationTest method testUserManager.
@Test
public void testUserManager() {
IRuntimeManager rm = Mockito.mock(IRuntimeManager.class);
//Build an UserManager that can build a UserModel
IUserManager im = Mockito.mock(IUserManager.class);
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
String user = (String) args[0];
return new UserModel(user);
}
}).when(im).getUserModel(Mockito.anyString());
AuthenticationManager am = new AuthenticationManager(rm, im);
GSSAuthenticator gssAuthenticator = new SshKrbAuthenticator(new MemorySettings(), am);
ServerSession session = Mockito.mock(ServerSession.class);
//Build an SshDaemonClient that can set and get the UserModel
final UserModelWrapper umw = new UserModelWrapper();
SshDaemonClient client = Mockito.mock(SshDaemonClient.class);
Mockito.when(client.getUser()).thenReturn(umw.um);
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
UserModel um = (UserModel) args[0];
umw.um = um;
return null;
}
}).when(client).setUser(Mockito.any(UserModel.class));
Mockito.when(session.getAttribute(SshDaemonClient.KEY)).thenReturn(client);
Assert.assertTrue(gssAuthenticator.validateIdentity(session, "jhappy"));
}
use of org.apache.sshd.server.session.ServerSession in project camel by apache.
the class ScpServerTestSupport method startSshd.
protected boolean startSshd() {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
// dummy authentication: allow any user whose password is the same as the username
return username != null && username.equals(password);
}
});
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
});
try {
sshd.start();
return true;
} catch (IOException e) {
LOG.info("Failed to start ssh server.", e);
}
return false;
}
use of org.apache.sshd.server.session.ServerSession in project karaf by apache.
the class KarafAgentFactory method createServer.
public SshAgentServer createServer(ConnectionService service) throws IOException {
Session session = service.getSession();
if (!(session instanceof ServerSession)) {
throw new IllegalStateException("The session used to create an agent server proxy must be a server session");
}
final AgentServerProxy proxy = new AgentServerProxy(service);
proxies.put(proxy.getId(), proxy);
return new SshAgentServer() {
public String getId() {
return proxy.getId();
}
@Override
public boolean isOpen() {
return proxy.isOpen();
}
public void close() throws IOException {
proxies.remove(proxy.getId());
proxy.close();
}
};
}
Aggregations