users@glassfish.java.net

Re: Glassfish & JAAS & LoginContext

From: <glassfish_at_javadesktop.org>
Date: Tue, 11 Nov 2008 03:41:47 PST

Hi, I'm having the exact same problem, much like you, using custom jaas with FileLoginModule in glassfish. Did you find any solution?

here the relevant code:

  [i] LoginCallbackHandler handler = new LoginCallbackHandler(username, password);
        try {
            jLoginContext ctx = new LoginContext(securityPolicyName, handler);
            ctx.login();
            ....
        } catch (LoginException e) { ... }[/i]

And my callback handler is very simple and looks like this:

[i]private class LoginCallbackHandler implements CallbackHandler {
            private String username;
            private String password;

            public LoginCallbackHandler(String username, String password) {
                    this.username = username;
                    this.password = password;
            }

                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (int i = 0; i < callbacks.length; i++) {
                                Callback callback = callbacks[i];
                                if (callback instanceof NameCallback) {
                                        ((NameCallback) callback).setName(username);
                                } else if (callback instanceof PasswordCallback) {
                                        PasswordCallback pwCallback = (PasswordCallback) callback;
                                        pwCallback.setPassword(password.toCharArray());
                                } else {
                                        throw new UnsupportedCallbackException(callbacks[i], "Callback type not supported");
                                }
                        }
                }
    }
[/i]

Appreciate any input that could help me solve this problem.

/andreas
[Message sent by forum member 'mrfatstrat' (mrfatstrat)]

http://forums.java.net/jive/thread.jspa?messageID=315997