FileDocCategorySizeDatePackage
JAASCallbackHandler.javaAPI DocGlassfish v2 API5319Fri May 04 22:32:16 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).

author
Craig R. McClanahan
version
$Revision: 1.3 $ $Date: 2007/05/05 05:32:16 $

Fields Summary
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.

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;
        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.getDebug() >= 3)
                    realm.log("Returning username " + username);
                ((NameCallback) callbacks[i]).setName(username);
            } else if (callbacks[i] instanceof PasswordCallback) {
                if (realm.getDebug() >= 3)
                    realm.log("Returning password " + password);
                  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]);
            }


        }