Hello folks, I am new to the whole Java thing and the whole LDAP thing, so go easy on me. Basically what I am trying to do is connect to some LDAP server, pass in a paramater such as a user_id and search LDAP for the user_id and if a match is found, return certain fields/attributes for that person. I would then like to store these details as strings or ints or other datatypes to be used in a java bean using setter methods.

At present I am unable to actually work out or understand how to extract certain attributes and their values and convert them from Attribute or Object type to String or Integer types. I would appreciate any help with this.

Code:
// This method does a basic search on the subtree for any entry that has the uid=username attribute
	public NamingEnumeration doSearch(String url, int port, String attribute, String user_id, String search_string) throws Exception{
		DirContext ctx = getDirContext(url, port);
		Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
		matchAttrs.put(new BasicAttribute(attribute, user_id));
	
		// Search for objects with those matching attributes
		NamingEnumeration answer = ctx.search(search_string, matchAttrs);
		ctx.close();
		return answer;
	} //close doSearch
I can connect to the LDAP ok, can retrieve a list of the users attributes and print them on screen, what I am having problems with is isolating each attribute and actually assigning the value of each attribute such as: uid, givenName, cn, sn, userpassword, mail etc etc and assigning them to a java bean.

Code:
public userBean return_results(NamingEnumeration enumber) throws Exception {
		userBean user = new userBean();
		
		int count = 0;
		String name = "";
		String[] attrIDs = {"uid", "cn", "userpassword", "givenName", "sn", "mail"};
		try {
		    while (enumber.hasMore()) {
				SearchResult sr = (SearchResult) enumber.next();
				Attributes attrs = sr.getAttributes();
                                user.setUser_id(uid);
                                user.setPassword(userpassword);
                                user.setUsername(cn);
                                user.setFirstname(givenName);
                                user.setLastname(sn);
                                user.setEmail(email);
				count++;
			} //close while
			System.out.println("LDAP Search returned "+count+ " results");
		} //close try
		catch (NamingException e) {
		    e.printStackTrace();
		} //close catch
		return user;
	} //close return_results
The two methods above basically carry out the search and retrieve ALL results for that user, not selected ones, how can I do that? And finally, in the second method I have posted, what would I need to do to assign just the values of the attributes to the userBeans setter methods and then return that bean so that I can use the values in my program?

Any help is greatly appreciated on this, as I have got as far as I am likely to get for the time being.

thanks!!