List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY
String INITIAL_CONTEXT_FACTORY
To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); DirContext ctx = new InitialDirContext(env); }
From source file:Main.java
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); NamingEnumeration e = ctx.list("child"); while (e.hasMore()) { NameClassPair entry = (NameClassPair) e.next(); System.out.println(entry.getName()); }/*ww w. jav a 2s .co m*/ }
From source file:Modify2Example.java
public static void main(String args[]) { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); try {/*from w w w . j ava 2 s. c o m*/ DirContext dctx = new InitialDirContext(env); ModificationItem[] mods = new ModificationItem[3]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("department", "sales")); mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("quota", "$1")); mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("assistant")); dctx.modifyAttributes("cn=Name, ou=People", mods); } catch (Exception e) { System.out.println(e); } }
From source file:FilterExample.java
public static void main(String[] argc) throws Exception { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); DirContext dctx = new InitialDirContext(env); String filter = "(&(cn=E*)(account>1005))"; NamingEnumeration result = dctx.search("ou=People", filter, null); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); }// w w w. j a v a2 s . c o m }
From source file:Bind.java
License:asdf
public static void main(String[] args) throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:/tmp"); Context initCtx = new InitialContext(env); initCtx.rebind("Susan", new Car("Toyota", "Camry")); Car c = (Car) initCtx.lookup("Susan"); System.out.println(c);/* w ww . j a va2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); // Create connection controls to use Control[] connectCtls = new Control[] { null }; LdapContext ctx = new InitialLdapContext(env, connectCtls); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); // Get an attribute of that type Attributes attrs = ctx.getAttributes("cn=YourName, ou=People", new String[] { "cn" }); Attribute cnAttr = attrs.get("cn"); // Get its attribute definition DirContext cnSchema = cnAttr.getAttributeDefinition(); // Get cnSchema's attributes Attributes cnAttrs = cnSchema.getAttributes(""); }
From source file:Modify1Example.java
public static void main(String args[]) { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); try {/* w ww. j a v a2s .co m*/ DirContext dctx = new InitialDirContext(env); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email", "name@site.com")); attrs.put(new BasicAttribute("website")); dctx.modifyAttributes("cn=Name, ou=People", DirContext.ADD_ATTRIBUTE, attrs); } catch (Exception e) { System.out.println(e); } }
From source file:Rename.java
public static void main(String[] args) throws Exception { String initialContextString = "/"; if (args.length < 2) { System.out.println("Useage: java Rename filename1 filename2"); System.exit(-1);//ww w .j av a 2 s . c om } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initialContextString); Context initCtx = new InitialContext(env); System.out.println("Renaming " + args[0] + " to " + args[1]); initCtx.rename(args[0], args[1]); }
From source file:SearchScopeExample.java
public static void main(String[] argc) { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); try {//from www .ja v a 2s .c o m DirContext dctx = new InitialDirContext(env); String filter = "(&(cn=S*)(account>1000))"; String[] attrIDs = { "cn", "email" }; SearchControls sc = new SearchControls(); sc.setReturningAttributes(attrIDs); sc.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration result = dctx.search("ou=People", filter, sc); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); } } catch (NamingException e) { System.out.println(e); } }