Parsing a JNDI Compound Name : Name « JNDI LDAP « Java






Parsing a JNDI Compound Name

  

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameParser;

public class Main {
  public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);
    NameParser parser = ctx.getNameParser("");
    Name dn = parser.parse("cn=John, ou=People, o=JNDITutorial");

    dn.remove(1); 
    dn.add(0, "c=us"); 
    dn.add("cn=fs"); 
  }
}

   
    
  








Related examples in the same category

1.Getting an Object's Fully Qualified Name
2.Using a URL as a Name to the Initial Context
3.Parsing a JNDI Composite Name
4.Show only the common name (cn) and e-mail address (mail) attributes
5.Replace the placeholders in the filter with the proper values from the userName