Java Reference
In-Depth Information
L ISTING 11.2
11
Continued
/**
* Returns all of the necessary environment information required to
* create a Context and bind to an LDAP server.
*/
protected Hashtable getEnvironment() {
Hashtable env = new Hashtable();
// generate LDAP host URL
StringBuffer url = new StringBuffer(“ldap://”);
url.append(serverName).append(“:”).append(port);
// set Context Factory class
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, factory);
// set host URL
env.put(javax.naming.Context.PROVIDER_URL, url.toString());
// Only set authentication information if there is a username
// present
if ((dirManager != null) && (dirManager.trim().length() > 0)) {
env.put(javax.naming.Context.SECURITY_AUTHENTICATION,
securityAuthentication);
env.put(javax.naming.Context.SECURITY_PRINCIPAL, dirManager);
env.put(javax.naming.Context.SECURITY_CREDENTIALS, dirManagerPw);
}
return env;
}
/**
* Creates a new Directory Context based on the local settings.
*/
protected DirContext getInitialContext(Hashtable env) throws
NamingException {
return new InitialDirContext(env);
}
/**
* Searches the ldap server using the search filter that is passed to the
* method.
*/
 
Search WWH ::




Custom Search