|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sptci.system.CommandExecutor
public class CommandExecutor
The class that is used to interact with the system. Provides methods to log user to the system and execute the password change command.
Modified version of class documented in informit.com.
| Field Summary | |
|---|---|
private TelnetClient |
client
The telnet client instance to use to communicate with the server. |
private InputStream |
in
The InputStream for the telnet session. |
private static Logger |
logger
The logger to use to log errors/messages to. |
static String |
LOGIN_PROMPT
The name of the property that contains the login prompt sent back by telnet server when a connection attempt is made. |
private PrintStream |
out
The OutputStream for the telnet session. |
static String |
PASSWORD_PROMPT
The name of the property that contains the password prompt sent back by telnet server after a response is sent to the LOGIN_PROMPT
"password" |
(package private) int |
port
The port on which to connect to the server. |
static String |
PORT
The name of the property that contains the port on which a telnet session will be established. |
static String |
PROMPT
The name of the property that contains the shell prompt character used by the system. |
(package private) Properties |
properties
The properties object that contains the configured properties for this instance. |
static String |
PROPERTY_FILE
The name of the system property that points to the properties file used to configure this instance. |
(package private) String |
server
The server to log on to affect the change in password. |
static String |
SERVER
The name of the property that contains the hostname of the server to which a telnet session will be initiated. |
(package private) String |
user
The user who is trying to change his password. |
| Constructor Summary | |
|---|---|
CommandExecutor()
Create a new instance of the class; |
|
| Method Summary | |
|---|---|
void |
connect(String password)
Connect to the server via telnet and log the
user to the system. |
void |
connect(String user,
String password)
Connect to the server via telnet and log the
user to the system. |
void |
disconnect()
Disconnect from the telnet session. |
private String |
execute(String command)
Send a command for execution to the telnet session. |
String |
getUser()
Returns user. |
void |
password(String password,
String newpassword)
Change the user's password. |
private String |
readLoginResponse()
Read the response from the server after a login attempt. |
private String |
readPasswordResponse(String success,
String error,
String message)
Read the response from the server after the current password has been entered during a password change request. |
private String |
readUntil(String pattern)
Read the response from the server until the specified pattern is found. |
void |
setUser(String user)
Set user. |
private void |
write(String response)
Write a response to the telnet OutputStream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final Logger logger
public static final String PROPERTY_FILE
public static final String SERVER
telnet session will be initiated.
"server"
public static final String PORT
telnet session will be established. This propery is
optional. By default a connection to the standard telnet
port 23 will be attempted.
"port"
public static final String LOGIN_PROMPT
public static final String PASSWORD_PROMPT
LOGIN_PROMPT
"password"
public static final String PROMPT
Note: This of course depends upon the shell used by the user and the user's settings.
"prompt"
final String server
final int port
server.
String user
private TelnetClient client
server.
final Properties properties
private InputStream in
InputStream for the telnet session.
private PrintStream out
OutputStream for the telnet session.
| Constructor Detail |
|---|
public CommandExecutor()
throws RuntimeException
RuntimeException - If errors are encountered while initialising
the instance from the PROPERTY_FILE file.| Method Detail |
|---|
public void connect(String password)
throws SocketException,
IOException,
AuthenticationFailedException
server via telnet and log the
user to the system. This method assumes that caller has either
invoked setUser(java.lang.String) or connect( String, String ) prior
to calling this method.
SocketException - If the socket timeout could not be set.
IOException - If the socket could not be opened. In most cases
you will only want to catch IOException since SocketException is
derived from it.
AuthenticationFailedException - If the login attempt failed due
to username or password error.connect( String, String )
public void connect(String user,
String password)
throws SocketException,
IOException,
AuthenticationFailedException
server via telnet and log the
user to the system.
SocketException - If the socket timeout could not be set.
IOException - If the socket could not be opened. In most cases
you will only want to catch IOException since SocketException is
derived from it.
AuthenticationFailedException - If the login attempt failed due
to username or password error.readUntil(java.lang.String),
write(java.lang.String),
readLoginResponse()
public void password(String password,
String newpassword)
throws IOException,
PasswordException
user's password.
password - The current password of the user.newpassword - The new password to set.
IOException - If the socket could not be opened. In most cases
you will only want to catch IOException since SocketException is
derived from it.
PasswordException - If the current or new password are incorrect
or insufficientpublic void disconnect()
telnet session.
private String readUntil(String pattern)
throws IOException
pattern - The pattern until which the response from the server
is to be read
IOException - If errors are encountered while reading/writing
to the socket streams.
private String readLoginResponse()
throws IOException,
AuthenticationFailedException
IOException - If errors are encountered while reading/writing
to the socket streams.
AuthenticationFailedException - If the login attempt failed due
to username or password error.
private String readPasswordResponse(String success,
String error,
String message)
throws IOException,
PasswordException
success - The pattern that indicates a successful entryerror - The pattern that indicates an errormessage - The message to use in PasswordException.
IOException - If errors are encountered while reading/writing
to the socket streams.
PasswordException - If the current password specified is
incorrect.
private void write(String response)
throws IOException
telnet OutputStream.
response - The response that is to be written to the stream.
IOException - If errors are encountered while reading/writing
to the socket streams.
private String execute(String command)
throws IOException
command - The command that is to be executed.
IOException - If errors are encountered while sending the
command for execution.write(java.lang.String),
readUntil(java.lang.String)public String getUser()
user.
public void setUser(String user)
user.
user - The value to set.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||