JAAS with LDAP

Hi,

I've been thru the tutorial and written my own CallbackHandler but when debugging the handle method is never entered.

Here's a code snippet

LoginContext lc =null;

try

{

LocalCallbackHandler localCallbackHandler =new LocalCallbackHandler(user, pwd);

lc =new LoginContext("LDAP", localCallbackHandler);

}

catch (LoginException innerException)

{

System.out.println("Error creating LoginContext");

}

lc.login();

and...

class LocalCallbackHandlerimplements CallbackHandler

{

private String user;

private String password;

public LocalCallbackHandler(String user, String password)

{

this.user = user;

this.password = password;

}

publicvoid handle(Callback[] callbacks)throws UnsupportedCallbackException

{

for (int i = 0; i < callbacks.length; i++)

{

if (callbacks[i]instanceof TextOutputCallback)

{

TextOutputCallback toc = (TextOutputCallback)callbacks[i];

System.out.println(toc.getMessage());

}

elseif (callbacks[i]instanceof NameCallback)

{

NameCallback nc = (NameCallback)callbacks[i];

nc.setName(user);

}

elseif (callbacks[i]instanceof PasswordCallback)

{

PasswordCallback pc = (PasswordCallback)callbacks[i];

pc.setPassword(password.toCharArray());

}

else

{

thrownew UnsupportedCallbackException

(callbacks[i],"Unrecognized Callback");

}

}

}

}

There is no problem creating the LoginContext. Is there a reason my callback handler isnt used?

Ted.

[3154 byte] By [ted_trippina] at [2007-9-23]
# 1

Forgot to add the login config...

LDAP {

sample.module.JndiLoginModule required debug=true user.provider.url="ldap://localhost:389/" group.provider.url="ldap://localhost:389/";

};

Everything is running on localhost.

ted_trippina at 2007-7-8 > top of java,Security,Other Security APIs, Tools, and Issues...
# 2

> Forgot to add the login config...

> > LDAP {

> sample.module.JndiLoginModule required debug=true

> ue user.provider.url="ldap://localhost:389/"

> group.provider.url="ldap://localhost:389/";

> };

>

> Everything is running on localhost.

Hello Ted,

I'm new to this. I'm trying to get JAAS JNDI running with LDAP.Running into some problems.

I'm having problem setting up the user and group provider. Seem to me that you didn't set up the LDAPName (entry name in the LDAP directory), and you didn't get the error for it? I did the same and received the error.I'm not sure what to put in there.

Pnguyenka at 2007-7-8 > top of java,Security,Other Security APIs, Tools, and Issues...
# 3

Hi ted and pnguyenk,

I'm just wondering are u using ur custom JNDILoginModule or com.sun.security.auth.module.JndiLoginModule provided by the JDK1.4 above.

If you're using Sun's JNDILoginModule then maybe make sure your useFirstPass, tryFirstPass are set to false. ( I may be stating an obvious thing to you). But i was playing around with the JNDILoginModule provided by Sun and I could use it to authenticate.. except that i had another problem that the LoginModule assumes your password is encrypted etc.

But hope u were able to solve ur problem..

RR

rave-Rovera at 2007-7-8 > top of java,Security,Other Security APIs, Tools, and Issues...