List of usage examples for java.util Hashtable Hashtable
Hashtable(Void dummy)
From source file:ListBindings.java
public static void main(String[] args) { // Set up the environment for creating the 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 {/* w w w . ja v a2 s.com*/ // Create the initial context Context ctx = new InitialContext(env); // Get listing of context NamingEnumeration bindings = ctx.listBindings("ou=People"); // Go through each item in list while (bindings.hasMore()) { Binding bd = (Binding) bindings.next(); System.out.println(bd.getName() + ": " + bd.getObject()); } // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("List Bindings failed: " + e); } }
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 {/*from w w w.j a v a2s.c o 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:List.java
public static void main(String[] args) { // Set up the environment for creating the 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 . j av a2s . c o m // Create the initial context Context ctx = new InitialContext(env); // Get listing of context NamingEnumeration list = ctx.list("ou=People"); // Go through each item in list while (list.hasMore()) { NameClassPair nc = (NameClassPair) list.next(); System.out.println(nc); } // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("List failed: " + e); } }
From source file:NewConn.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 w ww . j a v a 2 s .com // Create initial context (first connection) DirContext ctx = new InitialDirContext(env); // Get a copy of the same context DirContext ctx2 = (DirContext) ctx.lookup(""); // Change authentication properties in ctx2 ctx2.addToEnvironment(Context.SECURITY_PRINCIPAL, "cn=C. User, ou=NewHires, o=JNDITutorial"); ctx2.addToEnvironment(Context.SECURITY_CREDENTIALS, "mysecret"); // Method on ctx2 will use new connection System.out.println(ctx2.getAttributes("ou=NewHires")); // Close the contexts when we're done ctx.close(); ctx2.close(); } catch (NamingException e) { e.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 {/*from w w w .java2s. c o 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: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 w w w.j ava2 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:None.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"); // Use anonymous authentication env.put(Context.SECURITY_AUTHENTICATION, "none"); try {//from www . j a v a 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: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 ww w . j av a 2s . com*/ // 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:Destroy.java
public static void main(String[] args) { // Set up the environment for creating the 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 {// w ww .j a v a 2s . c o m // Create the initial context Context ctx = new InitialContext(env); // Destroy the context ctx.destroySubcontext("ou=NewOu"); // Check that it has been destroyed by listing its parent NamingEnumeration list = ctx.list(""); // Go through each item in list while (list.hasMore()) { NameClassPair nc = (NameClassPair) list.next(); System.out.println(nc); } // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("destroy failed: " + e); } }
From source file:DigestRealm.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" in realm "JNDITutorial" 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("java.naming.security.sasl.realm", "JNDITutorial"); try {// www . ja v a 2 s.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(); } }