Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.javax.security.auth.callback
Class AbstractCallbackHandler  view AbstractCallbackHandler download AbstractCallbackHandler.java

java.lang.Object
  extended bygnu.javax.security.auth.callback.AbstractCallbackHandler
All Implemented Interfaces:
javax.security.auth.callback.CallbackHandler
Direct Known Subclasses:
AWTCallbackHandler, ConsoleCallbackHandler, DefaultCallbackHandler, SwingCallbackHandler

public abstract class AbstractCallbackHandler
extends java.lang.Object
implements javax.security.auth.callback.CallbackHandler


Field Summary
protected  java.util.ResourceBundle messages
           
private  java.lang.String name
           
private static java.lang.String SERVICE
           
 
Constructor Summary
protected AbstractCallbackHandler(java.lang.String name)
           
 
Method Summary
static javax.security.auth.callback.CallbackHandler getInstance(java.lang.String type)
           
static javax.security.auth.callback.CallbackHandler getInstance(java.lang.String type, java.security.Provider provider)
           
static javax.security.auth.callback.CallbackHandler getInstance(java.lang.String type, java.lang.String provider)
           
 java.lang.String getName()
           
 void handle(javax.security.auth.callback.Callback[] callbacks)
          Retrieve or display the information requested in the provided javax.security.auth.callback.Callbacks.
protected abstract  void handleChoice(javax.security.auth.callback.ChoiceCallback callback)
          Handles a javax.security.auth.callback.ChoiceCallback.
protected abstract  void handleConfirmation(javax.security.auth.callback.ConfirmationCallback callback)
          Handles a javax.security.auth.callback.ConfirmationCallback.
protected abstract  void handleLanguage(javax.security.auth.callback.LanguageCallback callback)
          Handles a javax.security.auth.callback.LanguageCallback.
protected abstract  void handleName(javax.security.auth.callback.NameCallback callback)
          Handles a javax.security.auth.callback.NameCallback.
protected  void handleOther(javax.security.auth.callback.Callback callback)
          Handles an unknown callback.
protected abstract  void handlePassword(javax.security.auth.callback.PasswordCallback callback)
          Handles a javax.security.auth.callback.PasswordCallback.
protected abstract  void handleTextInput(javax.security.auth.callback.TextInputCallback callback)
          Handles a javax.security.auth.callback.TextInputCallback.
protected abstract  void handleTextOutput(javax.security.auth.callback.TextOutputCallback callback)
          Handles a javax.security.auth.callback.TextOutputCallback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE

private static final java.lang.String SERVICE
See Also:
Constant Field Values

messages

protected final java.util.ResourceBundle messages

name

private final java.lang.String name
Constructor Detail

AbstractCallbackHandler

protected AbstractCallbackHandler(java.lang.String name)
Method Detail

getInstance

public static javax.security.auth.callback.CallbackHandler getInstance(java.lang.String type)
                                                                throws java.security.NoSuchAlgorithmException

getInstance

public static javax.security.auth.callback.CallbackHandler getInstance(java.lang.String type,
                                                                       java.lang.String provider)
                                                                throws java.security.NoSuchAlgorithmException,
                                                                       java.security.NoSuchProviderException

getInstance

public static javax.security.auth.callback.CallbackHandler getInstance(java.lang.String type,
                                                                       java.security.Provider provider)
                                                                throws java.security.NoSuchAlgorithmException

handle

public void handle(javax.security.auth.callback.Callback[] callbacks)
            throws java.io.IOException,
                   javax.security.auth.callback.UnsupportedCallbackException
Description copied from interface: javax.security.auth.callback.CallbackHandler

Retrieve or display the information requested in the provided javax.security.auth.callback.Callbacks.

The handle() method implementation checks the instance(s) of the javax.security.auth.callback.Callback object(s) passed in to retrieve or display the requested information. The following example is provided to help demonstrate what an handle() method implementation might look like. This example code is for guidance only. Many details, including proper error handling, are left out for simplicity.

public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
   for (int i = 0; i < callbacks.length; i++) {
      if (callbacks[i] instanceof TextOutputCallback) {
         // display the message according to the specified type
         TextOutputCallback toc = (TextOutputCallback)callbacks[i];
         switch (toc.getMessageType()) {
         case TextOutputCallback.INFORMATION:
            System.out.println(toc.getMessage());
            break;
         case TextOutputCallback.ERROR:
            System.out.println("ERROR: " + toc.getMessage());
            break;
         case TextOutputCallback.WARNING:
            System.out.println("WARNING: " + toc.getMessage());
            break;
         default:
            throw new IOException("Unsupported message type: "
                  + toc.getMessageType());
         }
      } else if (callbacks[i] instanceof NameCallback) {
         // prompt the user for a username
         NameCallback nc = (NameCallback)callbacks[i];
         // ignore the provided defaultName
         System.err.print(nc.getPrompt());
         System.err.flush();
         nc.setName((new BufferedReader(
               new InputStreamReader(System.in))).readLine());
      } else if (callbacks[i] instanceof PasswordCallback) {
         // prompt the user for sensitive information
         PasswordCallback pc = (PasswordCallback)callbacks[i];
         System.err.print(pc.getPrompt());
         System.err.flush();
         pc.setPassword(readPassword(System.in));
      } else {
         throw new UnsupportedCallbackException(
               callbacks[i], "Unrecognized Callback");
      }
   }
}

 // Reads user password from given input stream.
private char[] readPassword(InputStream in) throws IOException {
   // insert code to read a user password from the input stream
}
 

Specified by:
handle in interface javax.security.auth.callback.CallbackHandler

getName

public final java.lang.String getName()

handleChoice

protected abstract void handleChoice(javax.security.auth.callback.ChoiceCallback callback)
                              throws java.io.IOException
Handles a javax.security.auth.callback.ChoiceCallback.


handleConfirmation

protected abstract void handleConfirmation(javax.security.auth.callback.ConfirmationCallback callback)
                                    throws java.io.IOException
Handles a javax.security.auth.callback.ConfirmationCallback.


handleLanguage

protected abstract void handleLanguage(javax.security.auth.callback.LanguageCallback callback)
                                throws java.io.IOException
Handles a javax.security.auth.callback.LanguageCallback.


handleName

protected abstract void handleName(javax.security.auth.callback.NameCallback callback)
                            throws java.io.IOException
Handles a javax.security.auth.callback.NameCallback.


handlePassword

protected abstract void handlePassword(javax.security.auth.callback.PasswordCallback callback)
                                throws java.io.IOException
Handles a javax.security.auth.callback.PasswordCallback.


handleTextInput

protected abstract void handleTextInput(javax.security.auth.callback.TextInputCallback callback)
                                 throws java.io.IOException
Handles a javax.security.auth.callback.TextInputCallback.


handleTextOutput

protected abstract void handleTextOutput(javax.security.auth.callback.TextOutputCallback callback)
                                  throws java.io.IOException
Handles a javax.security.auth.callback.TextOutputCallback.


handleOther

protected void handleOther(javax.security.auth.callback.Callback callback)
                    throws java.io.IOException,
                           javax.security.auth.callback.UnsupportedCallbackException
Handles an unknown callback. The default implementation simply throws an javax.security.auth.callback.UnsupportedCallbackException.