Giriş
Şu satırı dahil ederiz.
constructor - simple
Bind işlemi gerçekleşince, LDAP sunucusuna bağlanmak için kullanılan kullanıcı ismi ve şifrenin doğrulanması da yapılmış olur. Bağlantı gerçekleşemez ise veya kullanıcı doğrulanamazsa exception atılır.
Örnek
Şöyle yaparız.
Örnek
Şöyle yaparız
SASL ise Simle Authentication and Security Layer anlamına geliyor. Açıklaması şöyle:
Şöyle yaparız.
Şöyle yaparız.
NamingEnumeration döner. Şöyle yaparız.
Şu satırı dahil ederiz.
import javax.naming.directory.InitialDirContext
;
Bu sınıf LDAP üzerinde çalışabilmek için gerekli. Bir çeşit soket bağlantısı gibi düşünülebilir.constructor - simple
Bind işlemi gerçekleşince, LDAP sunucusuna bağlanmak için kullanılan kullanıcı ismi ve şifrenin doğrulanması da yapılmış olur. Bağlantı gerçekleşemez ise veya kullanıcı doğrulanamazsa exception atılır.
Örnek
Şöyle yaparız.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");
DirContext ctx = new InitialDirContext (env);
Bu kod ile şu aynıdır.String ldapContext = String.format("ldap://%s", ldapHostname);
Hashtable<String, String> ldapUserProperties = new Hashtable<String, String>();
ldapUserProperties.put(Context.SECURITY_PRINCIPAL, ldapUsername);
ldapUserProperties.put(Context.SECURITY_CREDENTIALS, ldapPassword);
try {DirContext directoryContext = LdapCtxFactory.getLdapCtxInstance(ldapContext, ldapUserProperties);
authenticationGranted = true;} catch (NamingException e) {System.out.println("Authentication failed!");}
Örnek
Şöyle yaparız
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
DirContext ctx = new InitialDirContext(env);
Şu parametreleri de kullanabilirdik.Context.SECURITY_PRINCIPAL = "cn=Directory Manager,dc=corio";
Context.SECURITY_CREDENTIALS = "secret";
constructor - SASLSASL ise Simle Authentication and Security Layer anlamına geliyor. Açıklaması şöyle:
close metoduA BIND request has two forms: simple and SASL. Simple uses a distinguished name and a password, SASL uses one of a choice of mechanisms, for example, PLAIN, LOGIN, CRAM-MD5, DIGEST-MD5, GSSAPI, and EXTERNAL - all of which except for GSSAPI and EXTERNAL are too weak to use in production scenarios or mission-critical areas.
Şöyle yaparız.
ctx.close();
getEnvironment metoduŞöyle yaparız.
System.out.println (ctx.getEnvironment());
search metodu - name + filter + SearchControlsNamingEnumeration döner. Şöyle yaparız.
SearchControls ctl = new SearchControls();
ctl.setSearchScope (SearchControls.SUBTREE_SCOPE);
NamingEnumeration results = ctx.search (
"dc=corio","uid=swethagm",ctl);
Şöyle yaparız.// Perform search in the entire subtree.
SearchControls ctl = new SearchControls();
ctl.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration results = ctx.search ("", null, ctl);
Hiç yorum yok:
Yorum Gönderme