Smack

org.jivesoftware.smack.sasl
Class SASLMechanism

java.lang.Object
  extended by org.jivesoftware.smack.sasl.SASLMechanism
All Implemented Interfaces:
javax.security.auth.callback.CallbackHandler
Direct Known Subclasses:
SASLAnonymous, SASLCramMD5Mechanism, SASLDigestMD5Mechanism, SASLExternalMechanism, SASLGSSAPIMechanism, SASLPlainMechanism

public abstract class SASLMechanism
extends Object
implements javax.security.auth.callback.CallbackHandler

Base class for SASL mechanisms. Subclasses must implement these methods:

Subclasses will likely want to implement their own versions of these mthods:
  • authenticate(String, String, String) -- Initiate authentication stanza using the deprecated method.
  • authenticate(String, String, CallbackHandler) -- Initiate authentication stanza using the CallbackHandler method.
  • challengeReceived(String) -- Handle a challenge from the server.
  • Author:
    Jay Kline

    Nested Class Summary
     class SASLMechanism.AuthMechanism
              Initiating SASL authentication by select a mechanism.
    static class SASLMechanism.Challenge
              A SASL challenge stanza.
    static class SASLMechanism.Failure
              A SASL failure stanza.
     class SASLMechanism.Response
              A SASL response stanza.
    static class SASLMechanism.Success
              A SASL success stanza.
     
    Field Summary
    protected  String authenticationId
               
    protected  String hostname
               
    protected  String password
               
    protected  javax.security.sasl.SaslClient sc
               
     
    Constructor Summary
    SASLMechanism(SASLAuthentication saslAuthentication)
               
     
    Method Summary
    protected  void authenticate()
               
     void authenticate(String username, String host, javax.security.auth.callback.CallbackHandler cbh)
              Builds and sends the auth stanza to the server.
     void authenticate(String username, String host, String password)
              Builds and sends the auth stanza to the server.
     void challengeReceived(String challenge)
              The server is challenging the SASL mechanism for the stanza he just sent.
    protected abstract  String getName()
              Returns the common name of the SASL mechanism.
    protected  SASLAuthentication getSASLAuthentication()
               
     void handle(javax.security.auth.callback.Callback[] callbacks)
               
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    sc

    protected javax.security.sasl.SaslClient sc

    authenticationId

    protected String authenticationId

    password

    protected String password

    hostname

    protected String hostname
    Constructor Detail

    SASLMechanism

    public SASLMechanism(SASLAuthentication saslAuthentication)
    Method Detail

    authenticate

    public void authenticate(String username,
                             String host,
                             String password)
                      throws IOException,
                             XMPPException
    Builds and sends the auth stanza to the server. Note that this method of authentication is not recommended, since it is very inflexable. Use authenticate(String, String, CallbackHandler) whenever possible.

    Parameters:
    username - the username of the user being authenticated.
    host - the hostname where the user account resides.
    password - the password for this account.
    Throws:
    IOException - If a network error occurs while authenticating.
    XMPPException - If a protocol error occurs or the user is not authenticated.

    authenticate

    public void authenticate(String username,
                             String host,
                             javax.security.auth.callback.CallbackHandler cbh)
                      throws IOException,
                             XMPPException
    Builds and sends the auth stanza to the server. The callback handler will handle any additional information, such as the authentication ID or realm, if it is needed.

    Parameters:
    username - the username of the user being authenticated.
    host - the hostname where the user account resides.
    cbh - the CallbackHandler to obtain user information.
    Throws:
    IOException - If a network error occures while authenticating.
    XMPPException - If a protocol error occurs or the user is not authenticated.

    authenticate

    protected void authenticate()
                         throws IOException,
                                XMPPException
    Throws:
    IOException
    XMPPException

    challengeReceived

    public void challengeReceived(String challenge)
                           throws IOException
    The server is challenging the SASL mechanism for the stanza he just sent. Send a response to the server's challenge.

    Parameters:
    challenge - a base64 encoded string representing the challenge.
    Throws:
    IOException - if an exception sending the response occurs.

    getName

    protected abstract String getName()
    Returns the common name of the SASL mechanism. E.g.: PLAIN, DIGEST-MD5 or GSSAPI.

    Returns:
    the common name of the SASL mechanism.

    getSASLAuthentication

    protected SASLAuthentication getSASLAuthentication()

    handle

    public void handle(javax.security.auth.callback.Callback[] callbacks)
                throws IOException,
                       javax.security.auth.callback.UnsupportedCallbackException
    Specified by:
    handle in interface javax.security.auth.callback.CallbackHandler
    Throws:
    IOException
    javax.security.auth.callback.UnsupportedCallbackException

    Smack

    Copyright © 2003-2007 Jive Software.