Hi,
I'm trying to build a user login system with JSP and servlets. This should run on a tomcat server. I have built a HTML form which calls for a "login" servlet when the submit button is pressed.
Now what I want to do is that this login servlet checks the username and password using RMI because the machine that will store the user accounts is a different machine then the machine the website runs on.
What I've done so far is I've created an interface IAuthenticate and an implementation of this interface: Authenticate. I've created a RMI server application that creates and registers this authentication object to the RMI registry.
In the login servlet
init() function I try to obtain the authenticate object using the following code:
public class Login extends HttpServlet {
private IAuthenticate authenticate;
public void init() throws ServletException {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
Registry registry = LocateRegistry.getRegistry("localhost");
this.authenticate = (IAuthenticate) registry.lookup("Authenticate");
} catch (Exception e) {
System.err.println("Error");
System.out.println("ERROR with obtaining RMI Authenticate");
e.printStackTrace();
}
}
So this servlet is the RMI client. In the doPost() method (which is called when a user presses the submit button on the login form) I want to call a function on the (remote) Authentication object:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
HttpSession s = request.getSession(true);
//Obtain username and password that were submitted on the HTML page
String user = request.getParameter("user");
String pass = request.getParameter("pass");
Account userAccount = this.authenticate.authenticateClient(user, pass));
etc
}
When I was done programming this I realized that normally you would need to add some RMI parameters to the java startup command:
Djava.rmi.server.codebase=
Djava.rmi.server.hostname=
Djava.security.policy=
But since the servlet is basically executed by tomcat I can't set these parameters. I tested it and indeed it doesn't work.I get an error in the security manager when I try to login
So my questions is, how can I set these RMI parameters? Can it be done in the code?
And more general, since I'm new to both RMI and JSP/Servlets programming: is this going to work? Is my approach to this right? Are there some good examples available for using JSP/servlets and RMI together?
Thanks,
Marc