Author: gnodet Date: Mon Dec 22 03:10:47 2008 New Revision: 728645 URL: http://svn.apache.org/viewvc?rev=728645&view=rev Log: SSHD-3: Provide access to the session and the authentication bits from commands
Modified: mina/sshd/trunk/src/main/java/org/apache/sshd/server/CommandFactory.java mina/sshd/trunk/src/main/java/org/apache/sshd/server/channel/ChannelSession.java Modified: mina/sshd/trunk/src/main/java/org/apache/sshd/server/CommandFactory.java URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/server/CommandFactory.java?rev=728645&r1=728644&r2=728645&view=diff ============================================================================== --- mina/sshd/trunk/src/main/java/org/apache/sshd/server/CommandFactory.java (original) +++ mina/sshd/trunk/src/main/java/org/apache/sshd/server/CommandFactory.java Mon Dec 22 03:10:47 2008 @@ -22,16 +22,45 @@ import java.io.OutputStream; import java.io.IOException; +import org.apache.sshd.server.session.ServerSession; + /** - * TODO Add javadoc + * A factory of commands. + * Commands are executed on the server side when an "exec" channel is + * requested by the SSH client. * * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> * @version $Rev$, $Date$ */ public interface CommandFactory { + /** + * Create a command with the given name. + * If the command is not known, a dummy command should be returned to allow + * the display output to be sent back to the client. + * + * @param command + * @return a non null command + */ Command createCommand(String command); + /** + * Interface that can be implemented by a command to be able to access the + * server session in which this command will be used. + */ + public interface SessionAware { + + /** + * Set the server session in which this command will be executed. + * + * @param session + */ + void setSession(ServerSession session); + } + + /** + * A command that can be executed on the server side + */ public interface Command { /** @@ -68,7 +97,7 @@ /** - * Callback used by the shell to notify the SSH server is has exited + * Callback used by a command to notify the SSH server is has exited */ public interface ExitCallback { Modified: mina/sshd/trunk/src/main/java/org/apache/sshd/server/channel/ChannelSession.java URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/server/channel/ChannelSession.java?rev=728645&r1=728644&r2=728645&view=diff ============================================================================== --- mina/sshd/trunk/src/main/java/org/apache/sshd/server/channel/ChannelSession.java (original) +++ mina/sshd/trunk/src/main/java/org/apache/sshd/server/channel/ChannelSession.java Mon Dec 22 03:10:47 2008 @@ -398,6 +398,11 @@ } CommandFactory.Command command = ((ServerSession) session).getServerFactoryManager().getCommandFactory().createCommand(commandLine); + // If the command wants to be aware of the session, let's do that + if (command instanceof CommandFactory.SessionAware) { + ((CommandFactory.SessionAware) command).setSession((ServerSession) session); + } + // Set streams and exit callback out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA); err = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_EXTENDED_DATA); // Wrap in logging filters @@ -418,6 +423,7 @@ } } }); + // Launch command command.start(); if (wantReply) {