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");

}

}

}

}

}

[2295 byte] By [geoffda] at [2007-10-1 11:44:10]
# 1
Hey,Click through to the end of this thread: http://forum.java.sun.com/thread.jspa?threadID=611566&start=10&tstart=0Perhaps search IBM's website for a similar active login module for unixKind regards,Darren
bishopd81a at 2007-7-10 13:25:01 > top of Java-index,Security,Other Security APIs, Tools, and Issues...