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:SearchControlsExample.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=S*)(account>1005))"; String[] attrIDs = { "cn", "email" }; SearchControls sc = new SearchControls(); sc.setReturningAttributes(attrIDs);//from ww w . j a v a 2 s . c o m NamingEnumeration result = dctx.search("ou=People", filter, sc); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); } }
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); DirContext ctx = new InitialDirContext(env); String[] attrIDs = { "sn", "number", "value", "mail" }; Attributes answer = ctx.getAttributes("cn=yourName, ou=People", attrIDs); NamingEnumeration e = answer.getAll(); while (e.hasMore()) { Attribute attr = (Attribute) e.next(); System.out.println(attr.getID()); }/*from w w w . j a v a 2 s. c o m*/ }
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"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People")); NamingListener listener = new SampleNCListener(); ctx.addNamingListener("cn=John", EventContext.ONELEVEL_SCOPE, listener); }
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"); LdapContext ctx = new InitialLdapContext(env, null); NamingEnumeration answer = ctx.search("ou=People", "(cn=*)", null); System.out.println(ctx.getResponseControls()); while (answer.hasMore()) { SearchResult si = (SearchResult) answer.next(); if (si instanceof HasControls) { System.out.println(((HasControls) si).getControls()); }// ww w .j a v a2s.c o m } System.out.println(ctx.getResponseControls()); }
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"); Control[] connectCtls = new Control[] { null }; LdapContext ctx = new InitialLdapContext(env, null); Control[] ctxCtls = new Control[] { new SortControl(new String[] { "cn" }, Control.CRITICAL) }; ctx.setRequestControls(ctxCtls);//from w ww. j ava 2 s. c om NamingEnumeration answer = ctx.list(""); while (answer.hasMore()) { NameClassPair item = (NameClassPair) answer.next(); } }
From source file:Delete.java
public static void main(String[] args) throws Exception { String initalContextString = "/tmp/marketing/reports"; if (args.length < 1) { System.out.println("Usage: java Delete filename"); System.exit(-1);/*from ww w. ja v a 2 s. co m*/ } System.out.println("This program assumes the context is " + initalContextString); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initalContextString); Context initCtx = new InitialContext(env); System.out.println("Attempting to unbind " + args[0]); initCtx.unbind(args[0]); System.out.println("Done."); }
From source file:TestDSBind.java
public static void main(String args[]) throws SQLException, NamingException { // For this to work you will need to create the // directories /JNDI/JDBC on your file system first Context ctx = null;//from w ww . j a v a2 s . c o m try { Properties prop = new Properties(); prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC"); ctx = new InitialContext(prop); } catch (NamingException ne) { System.err.println(ne.getMessage()); } OracleDataSource ds = new OracleDataSource(); ds.setDriverType("thin"); ds.setServerName("dssw2k01"); ds.setPortNumber(1521); ds.setDatabaseName("orcl"); ds.setUser("scott"); ds.setPassword("tiger"); ctx.bind("joe", ds); }
From source file:AttributeExample.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); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email")); attrs.put(new BasicAttribute("website", "www.pri.com")); NamingEnumeration result = dctx.search("ou=People", attrs); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); Attributes srchAttrs = sr.getAttributes(); NamingEnumeration attributes = srchAttrs.getAll(); while (attributes.hasMore()) { Attribute attr = (Attribute) attributes.next(); System.out.println("Attribute: " + attr.getID()); NamingEnumeration values = attr.getAll(); while (values.hasMore()) { Object value = values.next(); System.out.println("Value = " + value); }/*from w ww .j a v a2s. com*/ } } }
From source file:LdapSearch.java
public static void main(String[] args) throws Exception { Hashtable env = new Hashtable(); String sp = "com.sun.jndi.ldap.LdapCtxFactory"; env.put(Context.INITIAL_CONTEXT_FACTORY, sp); String ldapUrl = "ldap://localhost:389/dc=yourName, dc=com"; env.put(Context.PROVIDER_URL, ldapUrl); DirContext dctx = new InitialDirContext(env); String base = "ou=People"; SearchControls sc = new SearchControls(); String[] attributeFilter = { "cn", "mail" }; sc.setReturningAttributes(attributeFilter); sc.setSearchScope(SearchControls.SUBTREE_SCOPE); String filter = "(&(sn=W*)(l=Criteria*))"; NamingEnumeration results = dctx.search(base, filter, sc); while (results.hasMore()) { SearchResult sr = (SearchResult) results.next(); Attributes attrs = sr.getAttributes(); Attribute attr = attrs.get("cn"); System.out.print(attr.get() + ": "); attr = attrs.get("mail"); System.out.println(attr.get()); }//from w w w. j a v a2s. c o m dctx.close(); }
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"); EventDirContext ctx = (EventDirContext) (new InitialContext(env).lookup("ou=People")); NamingListener listener = new SampleObjListener(); SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); String filter = "(mail=*)"; ctx.addNamingListener("cn=YourName", filter, ctls, listener); }