jfz2004
asked on
How to make Java use Microsoft's DirectoryServices?
Hi,
I can use .Net C# to use DirectoryServices; but I don't know how to use
Directory Services in my Java Middleware.
Does any one have sample Java code on using DirectoryServices?
My current Java code looks like:
Hashtable env = new Hashtable(); env.put(Context.INITIAL_CO NTEXT_FACT ORY,"com.s un.jndi.ld ap.LdapCtx Factory");
env.put(Context.PROVIDER_U RL, "<LDAP://dc=myco,dc=com>\\ reap_ldap" );
env.put(Context.SECURITY_P RINCIPAL," CN=tmyid") ;
But, something is wrong with the third line.
Anyone knows why?
Thanks,
Jennifer
I can use .Net C# to use DirectoryServices; but I don't know how to use
Directory Services in my Java Middleware.
Does any one have sample Java code on using DirectoryServices?
My current Java code looks like:
Hashtable env = new Hashtable(); env.put(Context.INITIAL_CO
env.put(Context.PROVIDER_U
env.put(Context.SECURITY_P
But, something is wrong with the third line.
Anyone knows why?
Thanks,
Jennifer
Looks like the second line to me. Lose the '<' maybe
Sorry may have misread that
See here for LDAP use examples:
http://javaalmanac.com/egs/javax.naming.ldap/pkg.html
Hope this could help you.
Bye, Giant.
http://javaalmanac.com/egs/javax.naming.ldap/pkg.html
Hope this could help you.
Bye, Giant.
And here for a tutorial:
http://java.sun.com/products/jndi/tutorial/
http://java.sun.com/products/jndi/tutorial/
This example could be interesting:
http://java.sun.com/products/jndi/tutorial/getStarted/examples/directory.html
http://java.sun.com/products/jndi/tutorial/getStarted/examples/directory.html
the following does'nt seems a valid URL
<LDAP://dc=myco,dc=com>\\r eap_ldap
<LDAP://dc=myco,dc=com>\\r
and this last seems a strange username
CN=tmyid
CN=tmyid
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot,
I am reading the tutorials.
The username "CN=tmyid" is indeed strange; but it is something
i am using.
Thanks,
Jennifer
I am reading the tutorials.
The username "CN=tmyid" is indeed strange; but it is something
i am using.
Thanks,
Jennifer
ASKER
still not working.
Here is the error I got:
Exception in thread "main" javax.naming.Communication Exception:
dc=******(which is my company name), dc=com\reap_ldap:389
[Root exception is java.net.UnknownHostExcept ion: dc=
******(which is again my company name), dc=com\reap_ldap
Any ideas?
Jennifer
Here is the error I got:
Exception in thread "main" javax.naming.Communication
dc=******(which is my company name), dc=com\reap_ldap:389
[Root exception is java.net.UnknownHostExcept
******(which is again my company name), dc=com\reap_ldap
Any ideas?
Jennifer
com\reap_ldap
could be:
com/reap_ldap
could be:
com/reap_ldap
ASKER
let me try. Thanks,
Jennifer
Jennifer
ASKER
Hi, I asked my company's support and he told me that:
ADS connection url : "<LDAP://dc=******(which is my company name),dc=com>"
User ID : reap_ldap
PASSWORD : abcedfg
So I am going to write my java code like this:
env.put(Context.PROVIDER_U RL, "<LDAP://dc=******,dc=com> ");
env.put(Context.SECURITY_P RINCIPAL, "reap_ldap");
env.put(Context.SECURITY_C REDENTIALS , "abcedfg ");
I will this and see what happens.
ADS connection url : "<LDAP://dc=******(which is my company name),dc=com>"
User ID : reap_ldap
PASSWORD : abcedfg
So I am going to write my java code like this:
env.put(Context.PROVIDER_U
env.put(Context.SECURITY_P
env.put(Context.SECURITY_C
I will this and see what happens.
Ok. If not goes ok, try to remove the <...>, so
ADS connection url : "LDA://dc=........,dc=com"
Hope this solve.
ADS connection url : "LDA://dc=........,dc=com"
Hope this solve.
ASKER
Now my java code is like this:
env.put(Context.PROVIDER_U RL, "LDAP://******.com");
env.put(Context.SECURITY_A UTHENTICAT ION,"none" );
env.put(Context.SECURITY_P RINCIPAL," CN=reap_ld ap");
env.put(Context.SECURITY_C REDENTIALS , "abcdefg");
and it works.
Thanks a lot for your help. Your tutorials are good.
http://java.sun.com/products/jndi/tutorial/basics/prepare/initial.html
Jennifer
env.put(Context.PROVIDER_U
env.put(Context.SECURITY_A
env.put(Context.SECURITY_P
env.put(Context.SECURITY_C
and it works.
Thanks a lot for your help. Your tutorials are good.
http://java.sun.com/products/jndi/tutorial/basics/prepare/initial.html
Jennifer
Happy you solved.
tx accepting.
Bye, Giant.
tx accepting.
Bye, Giant.
ASKER
I searched in the web and found that the cause of my problem is
that the DN specified in the User Search tab is wrong,
or incorrectly formatted. But I don't know what is should be the DN
and what is the User Search tab.
Anyone knows what is User Search tab or DN here?
Thanks,
Jennifer
that the DN specified in the User Search tab is wrong,
or incorrectly formatted. But I don't know what is should be the DN
and what is the User Search tab.
Anyone knows what is User Search tab or DN here?
Thanks,
Jennifer
See:
http://www.ipswitch.com/support/instant_messaging/guides/v2/IMServer/User_s_Guide/Getting_Started/Server/LDAP.htm
the example reported is:
Server Name
ldapserver.ipswitch.com
Port number
389
User Authorize DN
CN=%s,CN=Users,DC=ldapserv er,DC=ipsw itch,DC=co m
User Search DN
CN=Users,DN=ldapserver,DC= ipswitch,D C=com
User Search Filter (All Users)
(|(objectClass=user)(objec tClass=per son))
LDAP User Search Filter (Single User)
(&(|(objectClass=user)(obj ectClass=p erson))(CN =%s))
http://www.ipswitch.com/support/instant_messaging/guides/v2/IMServer/User_s_Guide/Getting_Started/Server/LDAP.htm
the example reported is:
Server Name
ldapserver.ipswitch.com
Port number
389
User Authorize DN
CN=%s,CN=Users,DC=ldapserv
User Search DN
CN=Users,DN=ldapserver,DC=
User Search Filter (All Users)
(|(objectClass=user)(objec
LDAP User Search Filter (Single User)
(&(|(objectClass=user)(obj
ASKER
Thanks,
I will look into that url.
But for now, I keep getting this error when I use getAttributes("samaccountn ame=t1234" )
javax.naming.NamingExcepti on: [LDAP: error code 1 - 000020D6: SvcErr Problem 5012, remaining name 'samaccountname=t1234'.
In a separated .Net C# example, getAttributes works fine, but in java it does not work.
I searched in the internet on ldap's error msg, and found that this error is caused
by: the DN specified in the User Search tab is wrong, or incorrectly formatted.
But I don't understand it.
Ang sample code on using getAttributes?
Thanks,
Jennifer
I will look into that url.
But for now, I keep getting this error when I use getAttributes("samaccountn
javax.naming.NamingExcepti
In a separated .Net C# example, getAttributes works fine, but in java it does not work.
I searched in the internet on ldap's error msg, and found that this error is caused
by: the DN specified in the User Search tab is wrong, or incorrectly formatted.
But I don't understand it.
Ang sample code on using getAttributes?
Thanks,
Jennifer
ASKER
I checked on my computer. I don't see
"Start > Programs > Ipswitch IM Server" in my start->programs.
Hmmm.
"Start > Programs > Ipswitch IM Server" in my start->programs.
Hmmm.
ASKER
Hi,
In a DN like "cn=users,dc=company,dc=tl d",
is cn really should be users always?
Should I replace users here with actual user name like "John Joe"?
Also, my company has something called 'samaccountname', is it
a common attributes?
Thanks,
Jennifer
In a DN like "cn=users,dc=company,dc=tl
is cn really should be users always?
Should I replace users here with actual user name like "John Joe"?
Also, my company has something called 'samaccountname', is it
a common attributes?
Thanks,
Jennifer
samaccountname, mhmm. It's the first time I see it.
I found this thread speaking about it:
http://forum.java.sun.com/thread.jspa?threadID=517580&messageID=2469179
I found this thread speaking about it:
http://forum.java.sun.com/thread.jspa?threadID=517580&messageID=2469179