List of usage examples for javax.naming NamingException printStackTrace
public void printStackTrace()
From source file:RenameDiffParent.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {//ww w .ja va2 s .co m // Create initial context DirContext ctx = new InitialDirContext(env); // Perform rename ctx.rename("cn=C. User, ou=NewHires", "cn=C. User, ou=People"); // Check that it worked System.out.println(ctx.lookup("cn=C. User, ou=People")); // Revert change ctx.rename("cn=C. User, ou=People", "cn=C. User, ou=NewHires"); // Check that we are back at our original setup System.out.println(ctx.lookup("cn=C. User, ou=NewHires")); // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:Ssl.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:636/o=JNDITutorial"); // Specify SSL env.put(Context.SECURITY_PROTOCOL, "ssl"); // Authenticate as S. User and password "mysecret" env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial"); env.put(Context.SECURITY_CREDENTIALS, "mysecret"); try {/*from w w w . java2s.c om*/ // Create initial context DirContext ctx = new InitialDirContext(env); System.out.println(ctx.lookup("ou=NewHires")); // ... do something useful with ctx // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:Digest.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); // Authenticate as C. User and password "mysecret" env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5"); env.put(Context.SECURITY_PRINCIPAL, "dn:cn=C. User, ou=NewHires, o=JNDITutorial"); env.put(Context.SECURITY_CREDENTIALS, "mysecret"); env.put("com.sun.jndi.ldap.trace.ber", System.out); try {/*from w w w .java 2 s .c o m*/ // Create initial context DirContext ctx = new InitialDirContext(env); System.out.println(ctx.lookup("ou=NewHires")); // do something useful with ctx // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:UseDiff.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); // Authenticate as S. User and password "mysecret" env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial"); env.put(Context.SECURITY_CREDENTIALS, "mysecret"); try {/* w w w . j a v a 2s . co m*/ // Create initial context DirContext ctx = new InitialDirContext(env); // do something useful with ctx System.out.println(ctx.lookup("ou=NewHires")); // Change to using no authentication ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, "none"); System.out.println(ctx.lookup("ou=NewHires")); // do something useful with ctx // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:Compare.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {/*from ww w. ja v a2 s. c o m*/ // Create initial context DirContext ctx = new InitialDirContext(env); // Value of attribute byte[] key = { (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67 }; // Set up search controls SearchControls ctls = new SearchControls(); ctls.setReturningAttributes(new String[0]); // return no attrs ctls.setSearchScope(SearchControls.OBJECT_SCOPE); // search object only // Invoke search method that will use the LDAP "compare" operation NamingEnumeration answer = ctx.search("cn=S. User, ou=NewHires", "(mySpecialKey={0})", new Object[] { key }, ctls); // Print the answer // FilterArgs.printSearchEnumeration(answer); // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:ManageReferral.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:489/o=JNDITutorial"); // env.put(Context.REFERRAL, "follow"); env.put(Context.REFERRAL, "ignore"); try {//from w w w . ja va 2s . com // Create initial context LdapContext ctx = (LdapContext) new InitialLdapContext(env, null); // ctx.setRequestControls(new Control[] { // new ManageReferralControl() }); // Set controls for performing subtree search SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); // Perform search NamingEnumeration answer = ctx.search("", "(objectclass=*)", ctls); // Print the answer while (answer.hasMore()) { System.out.println(">>>" + ((SearchResult) answer.next()).getName()); } // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:UsePool.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); // Enable connection pooling env.put("com.sun.jndi.ldap.connect.pool", "true"); try {// w w w . j a v a2 s . c o m // Create one initial context (Get connection from pool) DirContext ctx = new InitialDirContext(env); System.out.println(ctx.getAttributes("ou=NewHires")); // do something useful with ctx // Close the context when we're done ctx.close(); // Return connection to pool // Create another initial context (Get connection from pool) DirContext ctx2 = new InitialDirContext(env); System.out.println(ctx2.getAttributes("ou=People")); // do something useful with ctx2 // Close the context when we're done ctx2.close(); // Return connection to pool } catch (NamingException e) { e.printStackTrace(); } }
From source file:RenameKeepRDN.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); // Set property to keep RDN env.put("java.naming.ldap.deleteRDN", "false"); try {//from ww w. j av a2 s. c o m // Create initial context DirContext ctx = new InitialDirContext(env); // Perform rename ctx.rename("cn=C. User, ou=NewHires", "cn=Claude User,ou=NewHires"); // Check that it worked System.out.println(ctx.getAttributes("cn=Claude User,ou=NewHires")); // Revert change // Make sure new name doesn't get converted into attribute ctx.removeFromEnvironment("java.naming.ldap.deleteRDN"); ctx.rename("cn=Claude User, ou=NewHires", "cn=C. User,ou=NewHires"); // Check that we are back at our original setup System.out.println(ctx.getAttributes("cn=C. User,ou=NewHires")); // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:ReadTimeoutTest.java
public static void main(String[] args) throws Exception { boolean passed = false; // Set up the environment for creating the initial context Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put("com.sun.jndi.ldap.read.timeout", "1000"); env.put(Context.PROVIDER_URL, "ldap://localhost:2001"); Server s = new Server(); try {/* ww w .j a va 2 s . co m*/ // start the server s.start(); // Create initial context DirContext ctx = new InitialDirContext(env); System.out.println("LDAP Client: Connected to the Server"); // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } s.interrupt(); }
From source file:SortedResults.java
public static void main(String[] args) throws IOException { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {//from w w w. java 2 s. co m // Create initial context with no connection request controls LdapContext ctx = new InitialLdapContext(env, null); // Create a sort control that sorts based on CN String sortKey = "cn"; ctx.setRequestControls(new Control[] { new SortControl(sortKey, Control.CRITICAL) }); // Perform a search NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); // Iterate over search results System.out.println("---->sort by cn"); while (results != null && results.hasMore()) { // Display an entry SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); // Handle the entry's response controls (if any) if (entry instanceof HasControls) { // ((HasControls)entry).getControls(); } } // Examine the sort control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof SortResponseControl) { SortResponseControl src = (SortResponseControl) controls[i]; if (!src.isSorted()) { throw src.getException(); } } else { // Handle other response controls (if any) } } } // Close when no longer needed ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }