The Telnet Service is a library that provides easy-to-integrate TELNET functionality to Java(TM) applications. Althrough its main purpose is to integrate servers as an administration console, its versatility puts creativity as the only limitation to its usage.
This example is based on 'Example 1: Telnet Service Core Simple Example Step-by-Step' and extends its functionality by adding JAAS authentication (using the telnetservice-jaas library).
The following sections show the basics of this integration activity using a simple (trivial) example.
JAAS provides a pluggable interface allowing applications to be independent from the underlying authentication system.
In our first example, we did not integrate with an application server and therefore we do not have an underlying authentication framework. To get around this, the second part of this guide will implement a very simple, hard-coded, single-user authentication, and then configure the java security framework to use it.
Notice that this example depends on the telnetservice-example1-core project, if you're using maven as a build tool, then you must run mvn install on that project to have it in your local repository; another option would be to include one of the many repositories that mirror maven artifact deployments to your project pom.
It is easy to add the JAAS extension to our code; Example2 will extend Example1 and overload its initialize() method to register this extension. [Example2.java ]
public class Example2 extends Example1 { public void initialize() { super.initialize(); super.telnetService.registerExtension(new TelnetServiceExtensionJAASImpl()); } public static void main(String[] args) throws TelnetServiceStartException { Example2 example = new Example2(); example.initialize(); example.run(); } }
That's it! If we were integrating on a framework that already provides JAAS, we would have been done! In our case, we'll include a simple LoginModule copyright of Sun Microsystems, Inc that was slightly modified for our needs.
We won't go into the details of writing a LoginModule and its related classes, there are many good tutorials on the net for that. Look at the sources if you are curious ;-) They're here: [Sources ]
If you're running on a framework check its documentation on how to setup and enable its LoginModule configuration, the telnet service JAAS implementation looks for the login module associated with TelnetService .
Let's configure the SampleLoginModule and try the example. For that we need to:
# # Default login configuration file # login.config.url.1=file:${user.home}/.java.login.config
TelnetService { fr.gedeon.telnetservice.jaasexample2.simplejaas.SampleLoginModule required debug=true; };
which points to the SampleLoginModule we have included. The 'debug=true' is set there temporarly to get feedback on what's going on, remove it when you know it's working as expected.
Let's try it with its only valid credentials: username='user', password='pass':
user name: user password: user> help help: display this help message sayhello: meet and greet exit: exit this session shutdown: shutdown the server user> sayhello Jojo Hello, Jojo! testUser>
The complete example sources can be downloaded at the project download section .
Please check the FAQ for common causes of misbehaviour.