JAASCallbackHandler (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.catalina.realm, class: JAASCallbackHandler

# Class JAASCallbackHandler

java.lang.Object
org.apache.catalina.realm.JAASCallbackHandler

All Implemented Interfaces:
  `CallbackHandler`

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`, `javax.security.auth.callback.PasswordCallback` and `javax.security.auth.callback.TextInputCallback`.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final String`
  `algorithm`
  Algorithm.
  `protected final String`
  `authMethod`
  The authentication method to be used.
  `protected final String`
  `cnonce`
  Client generated nonce.
  `protected final String`
  `digestA2`
  Second digest.
  `protected final String`
  `nc`
  Nonce count.
  `protected final String`
  `nonce`
  Server generated nonce.
  `protected final String`
  `password`
  The password to be authenticated with.
  `protected final String`
  `qop`
  Quality of protection applied to the message.
  `protected final JAASRealm`
  `realm`
  The associated `JAASRealm` instance.
  `protected final String`
  `realmName`
  Realm name.
  `protected static final StringManager`
  `sm`
  The string manager for this package.
  `protected final String`
  `username`
  The username to be authenticated with.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JAASCallbackHandler(JAASRealm realm, String username, String password)`
  Construct a callback handler configured with the specified values.
  `JAASCallbackHandler(JAASRealm realm, String username, String password, String nonce, String nc, String cnonce, String qop, String realmName, String digestA2, String algorithm, String authMethod)`
  Construct a callback handler for DIGEST authentication.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `handle(Callback[] callbacks)`
  Retrieve the information requested in the provided `Callbacks`.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

  - ### password

    protected final String password
    The password to be authenticated with.

  - ### realm

    protected final JAASRealm realm
    The associated `JAASRealm` instance.

  - ### username

    protected final String username
    The username to be authenticated with.

  - ### nonce

    protected final String nonce
    Server generated nonce.

  - ### nc

    protected final String nc
    Nonce count.

  - ### cnonce

    protected final String cnonce
    Client generated nonce.

  - ### qop

    protected final String qop
    Quality of protection applied to the message.

  - ### realmName

    protected final String realmName
    Realm name.

  - ### digestA2

    protected final String digestA2
    Second digest.

  - ### authMethod

    protected final String authMethod
    The authentication method to be used. If null, assume BASIC/FORM.

  - ### algorithm

    protected final String algorithm
    Algorithm.

- ## Constructor Details

  - ### JAASCallbackHandler

    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.
    Parameters:
      `realm` - Our associated JAASRealm instance
      `username` - Username to be authenticated with
      `password` - Password to be authenticated with

  - ### JAASCallbackHandler

    public JAASCallbackHandler(JAASRealm realm, String username, String password, String nonce, String nc, String cnonce, String qop, String realmName, String digestA2, String algorithm, String authMethod)
    Construct a callback handler for DIGEST authentication.
    Parameters:
      `realm` - Our associated JAASRealm instance
      `username` - Username to be authenticated with
      `password` - Password to be authenticated with
      `nonce` - Server generated nonce
      `nc` - Nonce count
      `cnonce` - Client generated nonce
      `qop` - Quality of protection applied to the message
      `realmName` - Realm name
      `digestA2` - Second digest calculated as digest(Method + ":" + uri)
      `algorithm` - The digest algorithm to use
      `authMethod` - The authentication method in use

- ## Method Details

  - ### handle

    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
    Retrieve the information requested in the provided `Callbacks`. This implementation only recognizes `NameCallback`, `PasswordCallback` and `TextInputCallback`. `TextInputCallback` is used to pass the various additional parameters required for DIGEST authentication.
    Specified by:
      `handle` in interface `CallbackHandler`
    Parameters:
      `callbacks` - The set of `Callback`s to be processed
    Throws:
      `IOException` - if an input/output error occurs
      `UnsupportedCallbackException` - if the login method requests an unsupported callback type