Thursday, November 16, 2006

GlassFish + JNDI + LDAP + JAVA

STEP 1: Create JNDI LDAP Resource

In the GlassFish admin console create a JNDI Custom Resource with the following parameters:

1. Give it a JNDI name such as myLDAP
2. Resource Type: javax.naming.directory.Directory
3. Factory Class: com.sun.jndi.ldap.LdapCtxFactory

Add the following as additional parameters:

1. Name: java.naming.security.principal Value: the reader dn

2. Name:java.naming.security.credentials Value: the password

3. Name: URL Value: ldap://servername/baseDN

STEP 2: JAVA code to access the LDAP

Use code similar to the following to access the LDAP:

try {
Context initCtx = new InitialContext();
DirContext ctx = (DirContext) initCtx.lookup("myLDAP");

SearchControls ctls = new SearchControls();
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

String searchfilter = "(mail="+ email +")";
NamingEnumeration answer = ctx.search("", searchfilter, ctls);

if(answer.hasMore()){
SearchResult entry = (SearchResult) answer.next();
Attributes attrs = entry.getAttributes();
......

} else {
success = false;
}
} catch (NamingException e) {
e.printStackTrace();
}

42 comments:

Nachiket Patel said...

Thanks, Sud.
I want ask one question.
If i want to use Windows Active Directory User-Password for Login in client application (of Glassfish server application), How to use it?

I think, Windows AD <=> LDAP <=> JNDI <=> My app. But what will be the look up key?

Will you be able to give other information??


This is my email : patel.nachiket.r@gmail.com

Regards,
Nachiket

Allan Lykke Christensen said...

Seems like com.sun.jndi.ldap.LdapCtxFactory is not picking up the authentication properties java.naming.security.principal and java.naming.security.credentials. I keep getting javax.naming.NoPermissionException. Any idea what properties to use to force LdapCtxFactory to authenticate?

tom said...

Did anyone find a solution to the question which properties to use to force LdapCtxFactory to authenticate?? Kind Regards, Thomas

ralpus said...

I have the same problem with authentication against AD.
I posted the problem here:
http://www.java.net/forum/topic/glassfish/glassfish/unable-bind-ldap-context-custom-ressource

Are there any solutions?

Anonymous said...

Hello would you mind stating which blog platform you're using? I'm planning to
start my own blog soon but I'm having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something completely unique.
P.S Sorry for getting off-topic but I had to ask!


Check out my page mister cartoon tattoo designs

Anonymous said...

Today, I went to the beach with my children.
I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She
put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is completely off
topic but I had to tell someone!

Here is my web site ... local business index

Anonymous said...

Thanks in favor of sharing such a nice thought, post is
pleasant, thats why i have read it completely

Here is my blog post :: microbiology term paper topics

Anonymous said...

I feel that is one of the most important info for me. And i
am glad reading your article. But should commentary on some common issues,
The website style is perfect, the articles is truly excellent : D.
Good process, cheers

Here is my web blog ... local pages business directory

Anonymous said...

This design is steller! You most certainly
know how to keep a reader amused. Between your wit
and your videos, I was almost moved to start my own blog (well,
almost...HaHa!) Fantastic job. I really enjoyed what
you had to say, and more than that, how you presented it.
Too cool!

Feel free to surf to my weblog - free local business listing sites australia

Anonymous said...

Thank you a lot for sharing this with all people you actually realize what you're speaking about! Bookmarked. Kindly additionally consult with my website =). We will have a link trade agreement between us

my weblog american history term paper topics

Anonymous said...

Wow, that's what I was exploring for, what a stuff! present here at this webpage, thanks admin of this web site.

my web blog - looney tunes bugs bunny t shirts

Anonymous said...

Thank you for another informative blog. The place else could
I am getting that kind of info written in such an ideal method?
I have a undertaking that I am just now operating on, and I've been on the glance out for such information.

my site :: mens cartoon print t-shirts

Anonymous said...

Why visitors still make use of to read news papers when in this technological world all is accessible on web?



my blog post :: submit business site to google

Anonymous said...

I visited many web pages however the audio quality for audio songs present at this site is actually wonderful.


Feel free to visit my web blog: film chatrak

Anonymous said...

Thanks in favor of sharing such a nice idea, article is nice, thats why i have
read it completely

Review my web blog; computers charlotte north carolina

Anonymous said...

Hi there all, here every one is sharing such experience,
so it's pleasant to read this blog, and I used to pay a quick visit this website every day.

Look into my webpage; charlotte north carolina computers

Anonymous said...

Magnificent goods from you, man. I've understand your stuff previous to and you're just too excellent.

I really like what you have acquired here, really like what you're stating and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I can't wait to read far more
from you. This is really a wonderful site.

Also visit my page ... funny cartoon t-shirts

Anonymous said...

Asking questions are truly pleasant thing if you are not understanding something entirely, however
this piece of writing provides pleasant understanding even.


My site: assignment help

Anonymous said...

I have read some good stuff here. Certainly value bookmarking for revisiting.
I wonder how a lot attempt you place to make this kind
of fantastic informative site.

Also visit my web-site :: movie discussion forum

Anonymous said...

Your way of explaining everything in this post is really fastidious, all be able to effortlessly be aware of it, Thanks a lot.



Here is my page ... anime t-shirts online

Anonymous said...

My partner and I stumbled over here from a different page and thought I may as
well check things out. I like what I see so i am just following
you. Look forward to looking into your web page for a second time.


my blog post small business yellow pages

Anonymous said...

Since the admin of this website is working, no uncertainty very
quickly it will be famous, due to its feature contents.


my weblog :: local business

Anonymous said...

Everyone loves it when folks come together and share opinions.
Great site, stick with it!

my homepage - local serach directories

Anonymous said...

I read this paragraph completely about the comparison of most up-to-date and preceding technologies, it's amazing article.

Feel free to surf to my blog post us business directories

Anonymous said...

Hi, I do think this is an excellent web site. I stumbledupon
it ;) I am going to come back once again since I saved
as a favorite it. Money and freedom is the best way to change,
may you be rich and continue to help other people.

Feel free to visit my page research paper apa style

Anonymous said...

I have been surfing on-line greater than three hours as of late, yet
I never discovered any interesting article like yours. It's pretty price sufficient for me. Personally, if all website owners and bloggers made good content as you probably did, the internet will likely be a lot more helpful than ever before.

Also visit my web-site ... cartoon t shirts india

Anonymous said...

Hello There. I found your blog using msn. This is a very
well written article. I will be sure to bookmark it and return to read more of your useful
information. Thanks for the post. I'll definitely return.

my blog post research paper topics ideas

Anonymous said...

Greetings, I do believe your blog might be having browser compatibility problems.

When I take a look at your website in Safari, it
looks fine however when opening in Internet Explorer,
it has some overlapping issues. I just wanted to give you a quick
heads up! Aside from that, excellent blog!

Also visit my webpage - apa format for a research paper

Anonymous said...

I'm truly enjoying the design and layout of your website. It's
a very easy on the eyes which makes it much more
pleasant for me to come here and visit more often.
Did you hire out a designer to create your theme?
Superb work!

Have a look at my weblog - apa outline template for research paper

Anonymous said...

I'm truly enjoying the design and layout of your website. It's
a very easy on the eyes which makes it much more pleasant
for me to come here and visit more often. Did you hire out a designer to create your theme?
Superb work!

Visit my web blog ... apa outline template for research paper

Anonymous said...

Hello! I just wanted to ask if you ever have any problems with hackers?
My last blog (wordpress) was hacked and I ended up losing several
weeks of hard work due to no back up. Do you have
any methods to protect against hackers?

Here is my weblog ... local directory company

Anonymous said...

Hello There. I found your weblog using msn.

That is a very smartly written article. I'll be sure to bookmark it and return to read more of your helpful information. Thanks for the post. I'll certainly return.


My web-site - mla format research paper

Anonymous said...

I was able to find good info from your blog posts.

Here is my website ... find a realtor

Anonymous said...

I know this if off topic but I'm looking into starting my own weblog and was curious what all is needed to get set up? I'm assuming having a blog like yours would cost a pretty penny?

I'm not very web smart so I'm not 100% positive.

Any suggestions or advice would be greatly appreciated. Many thanks

my page: book reports

Anonymous said...

Greetings! This is my 1st comment here so I just wanted to give a quick shout out and say I truly
enjoy reading through your posts. Can you recommend any
other blogs/websites/forums that cover the same topics?

Thanks for your time!

Also visit my website :: local small businesses

Anonymous said...

Hmm is anyone else having problems with the pictures on
this blog loading? I'm trying to find out if its a problem on my end or if it's the
blog. Any responses would be greatly appreciated.



Check out my web page: local small buisness directory and white pages

Anonymous said...

Pretty component of content. I simply stumbled upon your
weblog and in accession capital to say that I
get actually loved account your blog posts.
Any way I will be subscribing on your augment and even I achievement you get
admission to constantly quickly.

Look at my homepage ... antichrist film discussions

Anonymous said...

Hi, for all time i used to check blog posts here early in the break of day, since i enjoy to gain knowledge
of more and more.

Here is my web site ... us business listings

Anonymous said...

I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an shakiness over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this hike.

Also visit my blog: charlotte nc computer upgrades

Anonymous said...

If you desire to obtain a good deal from this paragraph then you have to apply such strategies to your won web site.


Look into my web page film chateau de william

Anonymous said...

Hey I know this is off topic but I was wondering if you knew
of any widgets I could add to my blog that automatically tweet my newest twitter updates.
I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

Here is my webpage :: remove virus charlotte north carolina

Anonymous said...

An impressive share! I've just forwarded this onto a co-worker who has been conducting a little research on this. And he actually ordered me dinner simply because I stumbled upon it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanx for spending time to talk about this subject here on your site.

Feel free to visit my weblog written papers