Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JAAS: how to login / logout programmatically?

imperfectJan 4 2008 — edited Nov 10 2009
Dear All,

i am writing a web application.

i have created a JSF login form for authentication. the application use JASS mechanism for pages protection.

i want to use the oracle's prebuild loginmodule (class name is
"oracle.security.jazn.login.module.LDAPLoginModule") to authenticate user from LDAP server.

to authenticate the user, my code in the backing bean for the login are:

public String authenticate()
{

MyCallbackHandler callback = new MyCallbackHandler();
callback.setName("name");
callback.setPassword("password");

//create a logoncontext for specific login module, and callbackhandler
LoginContext ctx = new LoginContext("name of configuration", callback );

//login
ctx.login();

//...................
//....................

}

callback handler code:

public class MyCallbackHandler implements javax.security.auth.callback.CallbackHandler
{

private String name = "";
private String password = "";

public void setName(String name)
{
this.name = name;
}

public void setPassword(String password)
{
this.password = password;
}

public void handle(Callback[] callbacks)
{
for(Callback c : callbacks)
{
if (c instanceof NameCallback)
{
((NameCallback)c).setName(name);
}
else if(c instanceof PasswordCallback)
{
((PasswordCallback)c).setPassword(password.toCharArray());
}
}
}
}


the login method SEEMS succeed as no exception thrown.

but the HttpServletRequest.getUserPrincipal() return null and whenever i visit other
protected page (after calling the logincontext.login())...i was redirected to the login page ...

do anyone know what the problem is??

thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2009
Added on Jan 4 2008
6 comments
5,791 views