Fetching LargeInteger, Dates and Group Distribution Lists from LDAP/Active Directory



In our AD system

The value lastLogon is a LargeInteger
The value whenCreated is a UTC Coded Time
The value group is a multi valued list Email Distribution Lists.

I'd need a tip so I can see how to fetch these values. Your help is
appreciated.

Here is a clip of code:

Note that only the String attributes such as
cn,givenName,sn,mail,sAMAccountName are fetched.

Note the comments.

If you're wondering about the JDOM I'm trying to write a reusable AD
data fetcher that returns the result of a query in XML. That should
sort of explain the method layout.

Again. Thanks.

//This is the calling function in a Servlet.
public Vector getDataFromAD(String searchText) {
String searchFilter = "(&(objectCategory=user)
(sAMAccountName="+searchText+"*))";
searchFilter = "(&(objectClass=user)(sAMAccountName=frog*))";
AdXml adXml = (AdXml)SpringContext.getContext().getBean("AdXml");
String[] attributes = {"cn","givenName", "sn",
"mail","sAMAccountName","group","lastLogon","logonCount"};
Vector v = null;
try {
v = adXml.search(attributes, searchFilter, 1000); // Here is
the call to search shown below
if ( null == v ) {
System.out.println("no search results returning null");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return v;
}

These are from AdXml:

public Vector search(String[] aAttributes, String searchFilter, int
countLimit)
throws Exception {
DirContext ctx = getDirContext();
try {
SearchControls sc = new SearchControls();
sc.setCountLimit(countLimit);
sc.setReturningAttributes(aAttributes);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration searchEnum = ctx.search(baseDN, searchFilter,
sc);
Vector results = new Vector ();
while(searchEnum != null && searchEnum.hasMore()) {
results.add(getAttributes((SearchResult)searchEnum.next()));
}
return results;
} catch ( Exception e){
e.printStackTrace();

} finally {
close(ctx);
}
}

public Element getAttributes(SearchResult result) throws BobException
{
Element elm = new Element("all");
try {
Attributes attrs = result.getAttributes();
NamingEnumeration enum = attrs.getIDs();
while ( enum.hasMoreElements() ) {
String key = (String) enum.nextElement(); // OK to assume all keys
are Strings?
Attribute attr = attrs.get(key);
getAttributesHelper(elm,key,attr);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return elm;
}

private void getAttributesHelper(Element elm, String key, Attribute
attr) throws NamingException {
Object obj = attr.get();
if ("class java.lang.String".equals(obj.getClass().toString())) {
elm.addContent(new Element(key)).addContent((obj.toString()));
} else { // This statement never gets executed I expected an
enumeration for multiple valued attributes
System.out.println(obj.getClass().toString());
}
}

.



Relevant Pages

  • RE: Detailed ASP.Net info not displaying in browser
    ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.xml)
  • RE: Detailed ASP.Net info not displaying in browser
    ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.xml)
  • Re: App_data - ASPNETDB.MDF
    ... is only because I want my site work, without exception. ... Server Error in '/' Application. ... serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Could not load file or assembly...
    ... The problem shows when EL exception handling ... context, ExceptionHandlerData objectConfiguration, IConfigurationSource ... configurationSource, ConfigurationReflectionCache reflectionCache) ... context, String name, IConfigurationSource configurationSource, ...
    (microsoft.public.dotnet.framework)
  • Re: Error handling not working
    ... Dim exception As Exception = Server.GetLastError.GetBaseException ... Dim ErrorString as String ... GetBaseException retrieves the "real" innerException object. ... CustomErrors in my webconfig file: ...
    (microsoft.public.dotnet.framework.aspnet)