UnixLoginModule not using Callbackhandler
I have a test program using UnixLoginModule and a callback handler. However, the callback handler is never called. I have debug set and it appears to always authenticate with my current logged on password.
How do I get around this as it seems that this module breaks the whole idea of callbacks.
When I run in the debugger the TestCallback constructor is called, but he handle() is not.
Cheers
Geoff
package base.jaas;
import java.io.IOException;
import java.security.Principal;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;
/**
* JAAS class to authenticate a user against the Linux user / password.
*/
public class TestHostingLogin
{
public static void main(String args[])
{
TestHostingLogin app = new TestHostingLogin();
app.test();
}
private void test()
{
Principal principle;
try
{
LoginContext c = new LoginContext("hosting", new TestCallback());
c.login();
c.logout();
System.out.println("Logged in ok");
}
catch (Exception ex)
{
System.out.println("Login failed");
ex.printStackTrace();
}
}
public class TestCallback implements CallbackHandler
{
public TestCallback()
{
}
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException
{
for (int i = 0; i < callbacks.length; i++)
{
if (callbacks instanceof NameCallback)
{
NameCallback nc = (NameCallback) callbacks;
nc.setName("testuser");
}
else if (callbacks instanceof PasswordCallback)
{
PasswordCallback pc = (PasswordCallback) callbacks;
pc.setPassword("testpassword".toCharArray());
}
else
{
throw new UnsupportedCallbackException(callbacks,
"Unrecognized Callback");
}
}
}
}
}

