Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with LDAP  RSS feed

 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to know how to integrate JSP with LDAP, can anyone show me how ? (including connect, add,delete, modify)

i have tried using EasyLDAP JSP Tag Library, but when i run it, the output is

if possible i need the source code , you can send to my email => irvank@windowslive.com

thanks for advance
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Irvan Kosini wrote:
if possible i need the source code , you can send to my email =>

Sorry, it doesn't work that way around here. Our philosophy is to teach you to fish, not give you a fish. You'll need to show us your code and explain exactly what you are trying to do and we'll help you on your journey of discovery.

I'm not familiar with EasyLDAP. Why are you using that instead of the native ldap classes? Is it a project requirement?

I suggest you start with that link and then this one.



 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm sorry kevin, i have tried what you tell me to do and i got this problem, can you help me to solve this ?

Java


Error
/home/irvank/.cache/netbeans/8.0.2/executor-snippets/run.xml:48:
Cancelled by user.

The row in the xml is:
<translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />

i have also clear cache but still cant
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have make a new workspace too

and i got this TT

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is your LDAP server really running on your localhost? I rather doubt it. This should be the IP address to your LDAP server.
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried with ip too, but still cant

i follow this tutorial, is it wrong ? please correct me if i'm wrong

http://techpubs.spinlocksolutions.com/dklar/ldap.html
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so it looks like you are setting up a local LDAP. Are you sure it's working? Do the ldapsearch tests described at the end of that document work correctly?
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do think i did it correctly from the tutorial and i have also create user from it, i have also test ldapadd and search and it show exactly like the tutorial did. So i think nothing wrong.

I need to know how to integrate it to jsp , can you show me how ?

If you have do it before, can you tell me step by step so nothing will go wrong , thank you
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried using EasyLDAP, and i follow the instruction ( i download it from http://easyldap.sourceforge.net/)



and this error come


but when i remove <%@ taglib uri="/ldap" prefix="ldap" %> from JSP , it can run, but when i put wrong ip,user,and pass it still say connection success even though it wrong TT, please help me

i just need simple add, modify , delete function
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Irvan Kosini wrote:
but when i remove <%@ taglib uri="/ldap" prefix="ldap" %> from JSP , it can run, but when i put wrong ip,user,and pass it still say connection success even though it wrong TT, please help me

That uri doesn't look correct. There are two ways to specify the uri. The preferred method is to make up a unique uri like "http://my.domain/tlds/mytldfile". This uri should exactly match the uri tag in the tld file like so:


The other way, which it appears you are trying to do, is use the relative path to the tld file like "/WEB-INF/tlds/mycustomtags.tld". In the case the <uri> element in the tld file is left blank.

If this this is the method you are trying to use, make sure the path is relative to the context root and specify the file name. What you have now is pointing to a folder called "/ldap" with no file name.
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr.J. Kevin Robbins, thank you for replying. from your suggestion i have tried to change the uri to this


after i run it, i got this



can you download EasyLDAP ? so you can know my problem. since i follow their instruction and nothing go right, (maybe i do not understand) TT
- Copy ldaptaglib.jar to your application's WEB-INF/lib directory
- Copy ldaptaglib.tld to your application's WEB-INF/tlds directory.
- In your WEB-INF/web.xml file, declare taglib and cache servlet. (You can copy from our web.xml and paste to yours.)

i have copy their web.xml and paste to mine too.

web.xml
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Irvan Kosini wrote:
can you download EasyLDAP ? so you can know my problem. since i follow their instruction and nothing go right, (maybe i do not understand) TT

I don't have a Linux box available to me for testing. I wish I did, this problem has me intrigued and I wish I could run your code.

Delete this section from your web.xml. It conflicts with the entry in your jsp file and I don't know which one will take precedence.

Does your ldap.tld file have a <uri></uri> element defined? Is ldap.tld located in /WEB-INF/tlds?


 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ldap.tld file doesn't have a <uri></uri> element defined

ldap.tld located in /WEB-INF/tlds? yes it is

i have delete the section you mentioned, and the error log still like the error log i post before
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Irvan Kosini wrote:ldap.tld file doesn't have a <uri></uri> element defined

That means you have to use the path method of referencing the taglib.

Irvan Kosini wrote:ldap.tld located in /WEB-INF/tlds? yes it is

So "/WEB-INF/tlds/ldap.tld" should be the correct uri for your jsp taglib declaration. So far so good.

Irvan Kosini wrote:i have delete the section you mentioned, and the error log still like the error log i post before

I'm not sure why you are getting the NPE. And the fact that you are getting it at compile time puzzles me, but I never compile jsps as part of the build. What happens if you don't compile the jsps? Can you get it to build and deploy?
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have use <uri> </uri> but it just get it printed when i run the jsp, no effect.

J. Kevin Robbins wrote:I'm not sure why you are getting the NPE. And the fact that you are getting it at compile time puzzles me, but I never compile jsps as part of the build. What happens if you don't compile the jsps? Can you get it to build and deploy?



i dont understand this line , can you explain it ?
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the compile messages, it appears that you are compiling the jsps. This isn't necessary as they are compiled by the container when invoked. I've seen it lead to some odd compiler failures due to jsp fragments and such.

It looks like you are using Netbeans. Right-click the project and choose "Properties". Then select the "Compile" branch of the tree. It will look like this.



See that check-box at the bottom labeled "Test compile all JSP files during builds"? Uncheck it.

Now do a clean and build. Do you get a successful build?
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i open properties , the check-box with labeled "Test compile all JSP files during builds" was unchecked from the start, so the result is still like the error log before.

i think you can download easyldap and run it on your netbeans, so we will know whats wrong with it, you dont need to make the connection successful, just try so it can be run on the browser.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've spent the last hour trying to get EasyLdap to run. This thing doesn't even include a valid tld file and I can't get it to load. It hasn't been updated since 2003.

My advice, abandon this product and use the native Java libraries. I think you are wasting your time trying to get EasyLdap working. I'm not spending any more time on it.
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:My advice, abandon this product and use the native Java libraries. I think you are wasting your time trying to get EasyLdap working. I'm not spending any more time on it.


advice accepted :D, can you tell me what kind of native java libraries that can integrate JSP with LDAP ?, can you tell me the step too ? thank you
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this for information on the Oracle LDAP libraries. And here is a good example of how to use it.

It's crucial that you verify that your LDAP service is working outside of all Java interaction. Make sure you can manually browse, add and delete from the LDAP directory using whatever tools you have available before you start trying to manipulate it using Java code. If it turns out that your LDAP isn't working correctly, you'll be running in circles trying to get Java code to work in a failing environment.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also seem to be focused on doing this in the JSPs. You should be thinking of doing this from Java classes, leaving the JSPs for generating views only.
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr.Kevin, i'll try JNDI later.

Bear Bibeault wrote:You also seem to be focused on doing this in the JSPs. You should be thinking of doing this from Java classes, leaving the JSPs for generating views only.

advice accepted :D

I have school tomorrow so i need to sleep now :D
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code



Error Log :
Problem getting attribute: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn = admin, ou=people'

on http://docs.oracle.com/javase/jndi/tutorial/getStarted/examples/directory.html there is a line like this

env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

what 'o=' means ?

when running there is something like this
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Irvan Kosini wrote:
Error Log :
Problem getting attribute: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn = admin, ou=people'

on http://docs.oracle.com/javase/jndi/tutorial/getStarted/examples/directory.html there is a line like this

env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

what 'o=' means ?

"o" is another attribute like ou and cn. It stands for organization. The attributes are part part of the Distinguished Name of the directory objects.


<%
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldap://192.168.1.1:389/");

try {
DirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes("cn = admin, ou=people");
attrs.get("sn").get();
System.out.println("sn: "+attrs.get("sn").get());
} catch (NamingException e) {
System.err.println("Problem getting attribute: "+ e);
}
%>

Why are you still using scriptlets?
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for 'o' answer.

for the scriptlets, i'm sorry, i forgot to change it here, i have place it on a java class, but how to solve that error ?

Problem getting attribute: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn = admin, ou=people'

Note:
My LDAP working perfectly on Terminal :D
cn= admin
dc= dtn, dc=com
pass= kosini
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!