Establish Secure Connection and Unauthenticate from eDirectory

Your user would never enter information over the Internet without using a secure connection. Change the Modify servlet to use a SSL connection and Unauthenticate from the Directory.

  1. Use the HTML page from Exercise #4. Assign rights to the page so that the page is accessed from a secure connection, for example https instead of http. Check the documentation of your Web server for instructions on how to do this.

  2. Use the same Java code as Exercise #4. Add the functionality to use a secure connection and authenticate from the Directory.

  3. Before you execute the AuthenticateLdap bean, add the line to use the SSL protocol by typing: bean.setProtocol("SSL");

  4. Change the URL of your server to use port 636 instead of port 389, which is the default LDAP port if one is not specified.

  5. After you assign the LdapConnection to the connection you created with the AuthenticateLdap bean, output which protocol you are using by typing: connection.getProtocol();

  6. After you execute the ModifyEntry bean, instantiate an UnauthenticateLdap bean passing to it as a parameter the LdapConnection object.

  7. Execute the bean.

  8. Output HTML letting the user know that the connection has been unauthenticated with the statement:


out.println("<h1>Authenticated: = " + u.isAuthenticated() + "</h1>");

Here is my code for the servlet.


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.novell.ecb.*;
import com.novell.ecb.ldap.*;

public class modify extends HttpServlet
{
LdapConnection connection = null;
private static final String CONTENT_TYPE = "text/html";
public void init() throws ServletException
{
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head><title>modify</title></head>");
out.println("<body bgcolor=\"#ffc800\">");

//I'll first authenticate as admin
AuthenticateLdap bean = new AuthenticateLdap();
bean.setURL("ldap://edu-qc.provo.novell.com:636");
bean.setDN("cn=admin, o=novell");
bean.setPassword("password");
bean.setProtocol("ssl");
try
{
bean.execute();
}
catch(Exception e)
{
out.println("<h1>Connection to the Directory failed</h1>");
e.printStackTrace(out);
}
connection = bean.getLdapConnection();
out.println("<h1>Connection Protocol is: " + connection.getProtocol() +
"</h1>");

ModifyLdapEntry mle = new ModifyLdapEntry(connection);
String s = "cn=" + request.getParameter("username") + ", o=novell";
mle.setName(s);
mle.replaceAttribute("givenName", request.getParameter("firstname"));
mle.replaceAttribute("sn", request.getParameter("lastname"));
mle.replaceAttribute("mail", request.getParameter("email"));
mle.replaceAttribute("fullName", request.getParameter("firstname") + " "
+ request.getParameter("lastname"));
try
{
mle.execute();
out.println("<h1>User: " + request.getParameter("username") + "
modified successfully</h1>");
}
catch(Exception e)
{
e.printStackTrace(out);
}

SetPasswordLdapEntry sple = new SetPasswordLdapEntry(connection);
sple.setName(s);
sple.setPassword(request.getParameter("password"));
try
{
sple.execute();
out.println("<h1>Password for user: " +
request.getParameter("username")+ " changed successfully</h1>");
}
catch(Exception e)
{
e.printStackTrace(out);
}

UnauthenticateLdap u = new UnauthenticateLdap(connection);

try
{
u.execute();
out.println("<h1>Authenticated = " + u.isAuthenticated() + "</h1>");
}
catch(Exception e)
{
out.println("Error Unauthenticating...");
e.printStackTrace();
}
out.println("</body></html>");
}
//Clean up resources
public void destroy()
{
}
}

download sample files
Previous blank Table of Contents blank Next