| Method from com.sshtools.j2ssh.authentication.AuthenticationProtocolClient Detail: |
public void addEventListener(AuthenticationProtocolListener listener) {
if (listener != null) {
listeners.add(listener);
}
}
|
public int authenticate(SshAuthenticationClient auth,
Service serviceToStart) throws IOException {
try {
if (!auth.canAuthenticate() && auth.canPrompt()) {
SshAuthenticationPrompt prompt = auth.getAuthenticationPrompt();
if (!prompt.showPrompt(auth)) {
return AuthenticationProtocolState.CANCELLED;
}
}
auth.authenticate(this, serviceToStart.getServiceName());
SshMessage msg = parseMessage(messageStore.getMessage(resultFilter));
// We should not get this far
throw new AuthenticationProtocolException(
"Unexpected authentication message " + msg.getMessageName());
} catch (TerminatedStateException tse) {
if (tse.getState() == AuthenticationProtocolState.COMPLETE) {
serviceToStart.init(Service.ACCEPTING_SERVICE, transport); //, nativeSettings);
serviceToStart.start();
for (Iterator it = listeners.iterator(); it.hasNext();) {
AuthenticationProtocolListener listener = (AuthenticationProtocolListener) it.next();
if (listener != null) {
listener.onAuthenticationComplete();
}
}
}
return tse.getState();
} catch (InterruptedException ex) {
throw new SshException(
"The thread was interrupted whilst waiting for an authentication message");
}
}
|
public List getAvailableAuths(String username,
String serviceName) throws IOException {
log.info("Requesting authentication methods");
SshMessage msg = new SshMsgUserAuthRequest(username, serviceName,
"none", null);
transport.sendMessage(msg, this);
try {
msg = messageStore.getMessage(resultFilter);
} catch (InterruptedException ex) {
throw new SshException(
"The thread was interrupted whilst waiting for an authentication message");
}
if (msg instanceof SshMsgUserAuthFailure) {
return ((SshMsgUserAuthFailure) msg).getAvailableAuthentications();
} else {
throw new IOException(
"None request returned success! Insecure feature not supported");
}
}
|
public String getBannerMessage(int timeout) throws IOException {
try {
log.debug(
"getBannerMessage is attempting to read the authentication banner");
SshMessage msg = messageStore.peekMessage(SshMsgUserAuthBanner.SSH_MSG_USERAUTH_BANNER,
timeout);
return ((SshMsgUserAuthBanner) msg).getBanner();
} catch (MessageNotAvailableException e) {
return "";
} catch (MessageStoreEOFException eof) {
log.error(
"Failed to retreive banner becasue the message store is EOF");
return "";
} catch (InterruptedException ex) {
throw new SshException(
"The thread was interrupted whilst waiting for an authentication message");
}
}
|
public byte[] getSessionIdentifier() {
return transport.getSessionIdentifier();
}
|
protected void onServiceAccept() throws IOException {
}
|
protected void onServiceInit(int startMode) throws IOException {
if (startMode == Service.ACCEPTING_SERVICE) {
throw new IOException(
"The Authentication Protocol client cannot be accepted");
}
messageStore.registerMessage(SshMsgUserAuthFailure.SSH_MSG_USERAUTH_FAILURE,
SshMsgUserAuthFailure.class);
messageStore.registerMessage(SshMsgUserAuthSuccess.SSH_MSG_USERAUTH_SUCCESS,
SshMsgUserAuthSuccess.class);
messageStore.registerMessage(SshMsgUserAuthBanner.SSH_MSG_USERAUTH_BANNER,
SshMsgUserAuthBanner.class);
//messageStore.registerMessage(SshMsgUserAuthPwdChangeReq.SSH_MSG_USERAUTH_PWD_CHANGEREQ,
// SshMsgUserAuthPwdChangeReq.class);
}
|
protected void onServiceRequest() throws IOException {
throw new IOException("This class implements the client protocol only!");
}
|
protected void onStart() {
}
|
public void readAuthenticationState() throws TerminatedStateException, IOException {
internalReadMessage(resultFilter);
}
|
public SshMessage readMessage(int messageId) throws TerminatedStateException, IOException {
singleIdFilter[2] = messageId;
return internalReadMessage(singleIdFilter);
}
|
public SshMessage readMessage(int[] messageId) throws TerminatedStateException, IOException {
int[] messageIdFilter = new int[messageId.length + resultFilter.length];
System.arraycopy(resultFilter, 0, messageIdFilter, 0,
resultFilter.length);
System.arraycopy(messageId, 0, messageIdFilter, resultFilter.length,
messageId.length);
return internalReadMessage(messageIdFilter);
}
|
public void registerMessage(Class cls,
int messageId) {
messageStore.registerMessage(messageId, cls);
}
|
public void sendMessage(SshMessage msg) throws IOException {
transport.sendMessage(msg, this);
}
|