com.sshtools.client.DefaultClientChannelFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maverick-synergy-client Show documentation
Show all versions of maverick-synergy-client Show documentation
The client-side implementation for the Maverick Synergy SSH API
The newest version!
package com.sshtools.client;
/*-
* #%L
* Client API
* %%
* Copyright (C) 2002 - 2024 JADAPTIVE Limited
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.Map;
import com.sshtools.common.command.ExecutableCommand;
import com.sshtools.common.permissions.PermissionDeniedException;
import com.sshtools.common.ssh.SessionChannel;
import com.sshtools.common.ssh.SshConnection;
import com.sshtools.common.ssh.Subsystem;
import com.sshtools.common.ssh.UnsupportedChannelException;
import com.sshtools.common.ssh.components.ComponentFactory;
import com.sshtools.synergy.ssh.ChannelFactory;
import com.sshtools.synergy.ssh.ChannelNG;
/**
* Implements a default ChannelFactory for an SSH client.
*/
public class DefaultClientChannelFactory implements ChannelFactory {
public DefaultClientChannelFactory() {
}
/**
* Called when a channel needs to be created.
*/
public final ChannelNG createChannel(String channeltype, SshConnection con)
throws UnsupportedChannelException, PermissionDeniedException {
if(channeltype.equals(RemoteForwardingClientChannel.REMOTE_FORWARDING_CHANNEL_TYPE)) {
return new RemoteForwardingClientChannel(con);
}
return onCreateChannel(channeltype, con);
}
protected ChannelNG onCreateChannel(String channeltype, SshConnection con)
throws UnsupportedChannelException, PermissionDeniedException {
throw new UnsupportedChannelException(String.format("%s is not a supported channel type", channeltype));
}
/**
* Request to create a subsystem. This method throws an UnsupportedChannelException as we do not support the opening
* of subsystems on the client.
*/
@Override
public Subsystem createSubsystem(String name, SessionChannel session)
throws UnsupportedChannelException, PermissionDeniedException {
throw new PermissionDeniedException("Client cannot start subsystems");
}
@Override
public ExecutableCommand executeCommand(SessionChannel channel, String[] args, Map environment)
throws PermissionDeniedException, UnsupportedChannelException {
throw new PermissionDeniedException("Client cannot execute commands");
}
@Override
public ComponentFactory supportedCommands() {
throw new UnsupportedOperationException("Commands are not supported in client configurations");
}
}