LDAP Search Tree with Java

hahahahahahahaaaaaaaaaaaaaaaa,,,,finally,,i finished my job,,work with LDAP using Java it’s my first time experience,,,

this is my code :

import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NameAlreadyBoundException;
import javax.naming.directory.*;
import java.util.*;
public class SimpleQuery {

final static String ldapServerName = “xxx.xxx.xxx.xxx”;
final static String rootdn = “cn=wssldap,cn=Users,dc=vas,dc=indosat,dc=com”;
final static String rootpass = “xxxxxxxx”;
final static String rootContext = “o=subscribers,dc=vas,dc=indosat,dc=com”;

public static void main( String[] args ) {
// set up environment to access the server

Properties env = new Properties();

“com.sun.jndi.ldap.LdapCtxFactory” );
env.put( Context.PROVIDER_URL, “ldap://” + ldapServerName + “/” + rootContext );
env.put( Context.SECURITY_PRINCIPAL, rootdn );
env.put( Context.SECURITY_CREDENTIALS, rootpass );

try {
// obtain initial directory context using the environment
DirContext ctx = new InitialDirContext( env );
SearchControls ctls = new SearchControls();

String filter = “(&(msisdn=628155133456))”;
com.sun.jndi.ldap.LdapCtx i = (com.sun.jndi.ldap.LdapCtx) ctx.lookup( “msisdn=628155133456” );
NamingEnumeration e = ctx.search(“”, filter, ctls);

while (e.hasMore()) {
SearchResult entry = (SearchResult) e.next();
//System.out.println( “Retrieved i from directory with value: ” + i.getAttributes(“substype”));
} catch ( NameAlreadyBoundException nabe ) {
System.err.println( “value has already been bound!” );
} catch ( Exception e ) {
System.err.println( e );


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: