差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

java:ldap:jndi [2016/04/07 23:03]
tony
java:ldap:jndi [2023/06/25 09:48]
行 1: 行 1:
-{{tag>​ldap jndi}} 
-====== JNDI API ====== 
-這裡主要記載我在安裝測試機器時,所做的API存取嘗試。 
-===== Search Base ===== 
-<code java> 
-Hashtable<​String,​ Object> env = new Hashtable<​String,​ Object>​();​ 
-env.put(Context.INITIAL_CONTEXT_FACTORY,​ 
- "​com.sun.jndi.ldap.LdapCtxFactory"​);​ 
-env.put(Context.PROVIDER_URL,​ 
- "​ldap://​192.168.1.13:​389/​dc=testldap,​dc=org"​);​ 
-env.put(Context.SECURITY_AUTHENTICATION,​ "​simple"​);​ 
-env.put(Context.SECURITY_PRINCIPAL,​ "​cn=admin,​dc=testldap,​dc=org"​);​ 
-env.put(Context.SECURITY_CREDENTIALS,​ "​123456"​);​ 
- 
-DirContext ctx = null; 
-try { 
- ctx = new InitialDirContext(env);​ 
- 
- NamingEnumeration<​SearchResult>​ srs = ctx.search("",​ null); 
- while (srs.hasMore()) { 
- SearchResult sr = srs.next(); 
- System.out.println(sr);​ 
- } 
-} catch (NamingException e) { 
- throw new RuntimeException(e);​ 
-} finally { 
- closeDirContext(ctx);​ 
-} 
-</​code>​ 
-Output: 
-<​code>​ 
-cn=admin: null:​null:​{userpassword=userPassword:​ [B@677327b6,​ description=description:​ LDAP administrator,​ objectclass=objectClass:​ simpleSecurityObject,​ organizationalRole,​ cn=cn: admin} 
-ou=sw: null:​null:​{ou=ou:​ sw, objectclass=objectClass:​ top, organizationalUnit} 
-</​code>​ 
-===== Get SASL mechanisms ===== 
-<code java> 
-DirContext ctx = new InitialDirContext();​ 
-try { 
- Attributes attrs = ctx.getAttributes("​ldap://​10.134.15.131:​389/",​ new String[]{"​supportedSASLMechanisms"​});​ 
- System.out.println(attrs);​ 
-} finally { 
- closeDirContext(ctx);​ 
-} 
-</​code>​ 
-Output: 
-<​code>​ 
-{supportedsaslmechanisms=supportedSASLMechanisms:​ DIGEST-MD5, CRAM-MD5, NTLM} 
-</​code>​ 
-===== Articles ===== 
-  * [[java:​ldap:​jndi:​ldapname|LdapName]] 
- 
-=====  ===== 
----- 
-\\ 
-~~DISQUS~~ 
-