FileDocCategorySizeDatePackage
JAASCallbackHandler.javaAPI DocApache Tomcat 6.0.145179Fri Jul 20 04:20:36 BST 2007org.apache.catalina.realm

JAASCallbackHandler

public class JAASCallbackHandler extends Object implements CallbackHandler

Implementation of the JAAS CallbackHandler interface, used to negotiate delivery of the username and credentials that were specified to our constructor. No interaction with the user is required (or possible).

This CallbackHandler will pre-digest the supplied password, if required by the <Realm> element in server.xml.

At present, JAASCallbackHandler knows how to handle callbacks of type javax.security.auth.callback.NameCallback and javax.security.auth.callback.PasswordCallback.

author
Craig R. McClanahan
author
Andrew R. Jaquith
version
$Revision: 543691 $ $Date: 2007-06-02 03:37:08 +0200 (sam., 02 juin 2007) $

Fields Summary
protected static final org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected String
password
The password to be authenticated with.
protected JAASRealm
realm
The associated JAASRealm instance.
protected String
username
The username to be authenticated with.
Constructors Summary
public JAASCallbackHandler(JAASRealm realm, String username, String password)
Construct a callback handler configured with the specified values. Note that if the JAASRealm instance specifies digested passwords, the password parameter will be pre-digested here.

param
realm Our associated JAASRealm instance
param
username Username to be authenticated with
param
password Password to be authenticated with


        super();
        this.realm = realm;
        this.username = username;

        if (realm.hasMessageDigest()) {
            this.password = realm.digest(password);
        }
        else {
            this.password = password;
        }
    
Methods Summary
public voidhandle(javax.security.auth.callback.Callback[] callbacks)
Retrieve the information requested in the provided Callbacks. This implementation only recognizes NameCallback and PasswordCallback instances.

param
callbacks The set of Callbacks to be processed
exception
IOException if an input/output error occurs
exception
UnsupportedCallbackException if the login method requests an unsupported callback type



    // --------------------------------------------------------- Public Methods


                                                     
       
           

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

            if (callbacks[i] instanceof NameCallback) {
                if (realm.getContainer().getLogger().isTraceEnabled())
                    realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
                ((NameCallback) callbacks[i]).setName(username);
            } else if (callbacks[i] instanceof PasswordCallback) {
                final char[] passwordcontents;
                if (password != null) {
                    passwordcontents = password.toCharArray();
                } else {
                    passwordcontents = new char[0];
                }
                ((PasswordCallback) callbacks[i]).setPassword
                    (passwordcontents);
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }