HW1: Certificate Repository Homework

Requirement

Build the following:

NsLDAPBridge

import netscape.ldap.*;
import java.util.*;

/**
 * Bridge for LDAP (tested on Netscape) 
 */ 
public class NsLDAPBridge 
{
	// Variables
	LDAPConnection 	_ld 		= null;
	String 		_hostName	= null;
	String 		_searchFilter	= null;
	String		_searchBase	= null;
	int		_portNumber	= 389;
	LDAPSearchConstraints _cons 	= null;

	/**
	 * Search the LDAP directory
	 */
	// This should return the common search object we want
	public NsBridgeDataRes search(String curSearchFilter, String resultID)
	{

	} // End of search

	/**
	 * Disconnect the bridge from LDAP server
	 */
	public void disconnect()
	{
		// Done, so disconnect

	}

	/**
	 * Constructor
	 */
	public NsLDAPBridge(	String hostName, 
				String portNumber,
				String searchBase,
				String searchFilter)
	{


	} // End of constructor


} // End of class NsLDAPBridge

 

NsBridgeManager.java

import java.util.*;

// FIXME: Implement by all Bridge later on
interface Bridge
{
	/**
	 * Get the name of the bridge
	 */
	public String getBridgeName(); 

	/**
	 * Get the type of the bridge
	 */
	public String getBridgeType();

	/**
	 * Get all user data
	 */
	public String getAllObjects();
}

/**
 * Bridge Manager
 */
class NsBridgeManager
{
	private Vector	_bridgeList;

	/**
	 * Constructor
	 */
	public NsBridgeManager()
	{
		_bridgeList = new Vector();
	}

	//
	// Todo (Bridge)
	// - Read the configuration info (NsBridgeConfInfo.xml)
	// - Determine 
	//    - How many bridges need to construct
	//    - For LDAP bridges, what is the host, port, filter, searchbase,
	//      username, password (if need to bind)  
	//    - For DB bridges, what is the driver, db url, username, password 
	// - Construct LDAP bridge
	// - Do
	//    - create ld connection object (LDAPConnection) 
	//    - keep the object around 
	//    - All detail of LDAP communication is in here 
	// - Construct DB bridge
	// - Do
	//    - create db connection (Connection) 
	//    - All detail of DB communication is in here 
	//
	// Todo (Data Model) (Next homework)
	// - Read the configuration info (NsDataConfInfo.xml)
	// - Determine
	//    - Mapping of user data 
	//    - Store mapping in internal data structure 
	// - Provides function for obtain all user data 
	//   (Loop the bridges and get all user data) 

}


NsBridgeDataRes.java

import java.util.*;
import java.io.*;

public class NsBridgeDataRes
{
	private String _resultName = null;
	// Hashtable cannot do duplicate correctly ... changing
	// FIXME: Change to something faster later, e.g. B+ tree
	// private Hashtable _resultStore = null;
	private Vector _resultStore = null;

	public NsBridgeDataRes (String name)
	{
		_resultName = name; 
		_resultStore = new Vector();
	}	

	public void add(NsNVPairs nvp)
	{
		_resultStore.add(nvp);
	}


	public String toString()
	{
		// FIXME: We might run into some problem if the key is duplicate Hashtable ... 
		/*  
		Enumeration en = _resultStore.elements();
		NsNVPairs mypairs;
		String str = new String();

		str = str.concat("Result Set ID [" + _resultName + "]\n");
	
		while(en.hasMoreElements())
		{   
			mypairs = (NsNVPairs)en.nextElement();
			str = str.concat(mypairs.toString());
			str = str.concat("\n");
		}
		*/
		String str = new String();

		for (int i=0; i<_resultStore.size(); i++)
		{
			str = str.concat(((NsNVPairs) _resultStore.elementAt(i)).toString());
			str = str.concat("\n");
		}	

		return str;
	}

} // End of class BridgeDataRes

 

NsBridgeConfInfo.xml

 

NsTestDriver

A test driver program that uses/tests all the above classes by:

Copyright 1996-2003 OpenLoop Computing. All rights reserved.