FileDocCategorySizeDatePackage
MakeRoot.javaAPI DocExample1709Sun Jul 06 01:05:38 BST 2003antipatterns

MakeRoot

public class MakeRoot extends Object

Fields Summary
static final String
ldapServerName
static final String
rootdn
static final String
rootpass
static final String
rootContext
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        
               
                // set up environment to access the server
                
                Properties env = new Properties();
                
                env.put( Context.INITIAL_CONTEXT_FACTORY,
                         "com.sun.jndi.ldap.LdapCtxFactory" );
                env.put( Context.PROVIDER_URL, "ldap://" + ldapServerName + "/" );
                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 );
                        
                        // now, create the root context, which is just a subcontext
                        // of this initial directory context.
                        ctx.createSubcontext( rootContext );
                } catch ( NameAlreadyBoundException nabe ) {
                        System.err.println( rootContext + " has already been bound!" );
                } catch ( Exception e ) {
                        System.err.println( e );
                }