| Method from com.sshtools.daemon.authentication.AuthenticationProtocolServer Detail: |
public void acceptService(Service service) {
acceptServices.put(service.getServiceName(), service);
}
|
protected int[] getAsyncMessageFilter() {
return messageFilter;
}
|
public TransportProtocolState getConnectionState() {
return transport.getState();
}
|
public byte[] getSessionIdentifier() {
return transport.getSessionIdentifier();
}
|
protected void onMessageReceived(SshMessage msg) throws IOException {
switch (msg.getMessageId()) {
case SshMsgUserAuthRequest.SSH_MSG_USERAUTH_REQUEST: {
onMsgUserAuthRequest((SshMsgUserAuthRequest) msg);
break;
}
default:
throw new AuthenticationProtocolException(
"Unregistered message received!");
}
}
|
protected void onServiceAccept() throws IOException {
}
|
protected void onServiceInit(int startMode) throws IOException {
// Register the required messages
messageStore.registerMessage(SshMsgUserAuthRequest.SSH_MSG_USERAUTH_REQUEST,
SshMsgUserAuthRequest.class);
transport.addMessageStore(methodMessages);
}
|
protected void onServiceRequest() throws IOException {
// Send a user auth banner if configured
ServerConfiguration server = (ServerConfiguration) ConfigurationLoader.getConfiguration(ServerConfiguration.class);
if (server == null) {
throw new AuthenticationProtocolException(
"Server configuration unavailable");
}
availableAuths = new ArrayList();
Iterator it = SshAuthenticationServerFactory.getSupportedMethods()
.iterator();
String method;
List allowed = server.getAllowedAuthentications();
while (it.hasNext()) {
method = (String) it.next();
if (allowed.contains(method)) {
availableAuths.add(method);
}
}
if (availableAuths.size() < = 0) {
throw new AuthenticationProtocolException(
"No valid authentication methods have been specified");
}
// Accept the service request
sendServiceAccept();
String bannerFile = server.getAuthenticationBanner();
if (bannerFile != null) {
if (bannerFile.length() > 0) {
InputStream in = ConfigurationLoader.loadFile(bannerFile);
if (in != null) {
byte[] data = new byte[in.available()];
in.read(data);
in.close();
SshMsgUserAuthBanner bannerMsg = new SshMsgUserAuthBanner(new String(
data));
transport.sendMessage(bannerMsg, this);
} else {
log.info("The banner file '" + bannerFile +
"' was not found");
}
}
}
}
|
protected void onStop() {
try {
// If authentication succeeded then wait for the
// disconnect and logoff the user
if (completed) {
try {
transport.getState().waitForState(TransportProtocolState.DISCONNECTED);
} catch (InterruptedException ex) {
log.warn("The authentication service was interrupted");
}
NativeAuthenticationProvider nap = NativeAuthenticationProvider.getInstance();
nap.logoffUser();
}
} catch (IOException ex) {
log.warn("Failed to logoff " + SshThread.getCurrentThreadUser());
}
}
|
public SshMessage readMessage() throws IOException {
try {
return methodMessages.nextMessage();
} catch (InterruptedException ex) {
throw new SshException("The thread was interrupted");
}
}
|
public void registerMessage(int messageId,
Class cls) {
methodMessages.registerMessage(messageId, cls);
}
|
public void sendMessage(SshMessage msg) throws IOException {
transport.sendMessage(msg, this);
}
|