Class AbstractSaslParticipant

java.lang.Object
org.wildfly.security.sasl.util.AbstractSaslParticipant
All Implemented Interfaces:
SaslWrapper
Direct Known Subclasses:
AbstractSaslClient, AbstractSaslServer

public abstract class AbstractSaslParticipant extends Object implements SaslWrapper
A common base class for SASL participants.
Author:
David M. Lloyd
  • Field Details

    • NO_BYTES

      public static final byte[] NO_BYTES
      An empty byte array.
    • FAILED_STATE

      public static final int FAILED_STATE
      The SASL negotiation failure state.
      See Also:
    • COMPLETE_STATE

      public static final int COMPLETE_STATE
      The SASL negotiation completed state.
      See Also:
  • Constructor Details

    • AbstractSaslParticipant

      protected AbstractSaslParticipant(String mechanismName, String protocol, String serverName, CallbackHandler callbackHandler, ElytronMessages log)
      Construct a new instance.
      Parameters:
      mechanismName - the name of the defined mechanism
      protocol - the protocol
      serverName - the server name
      callbackHandler - the callback handler
      log - mechanism specific logger
    • AbstractSaslParticipant

      @Deprecated protected AbstractSaslParticipant(String mechanismName, String protocol, String serverName, CallbackHandler callbackHandler)
      Deprecated.
      Construct a new instance.
      Parameters:
      mechanismName - the name of the defined mechanism
      protocol - the protocol
      serverName - the server name
      callbackHandler - the callback handler
  • Method Details

    • handleCallbacks

      protected void handleCallbacks(Callback... callbacks) throws SaslException
      Handle callbacks, wrapping exceptions as needed (including unsupported callbacks).
      Parameters:
      callbacks - the callbacks to handle
      Throws:
      SaslException - if a callback failed
    • tryHandleCallbacks

      protected void tryHandleCallbacks(Callback... callbacks) throws SaslException, UnsupportedCallbackException
      Handle callbacks, wrapping exceptions as needed.
      Parameters:
      callbacks - the callbacks to handle
      Throws:
      SaslException - if a callback failed
      UnsupportedCallbackException - if a callback isn't supported
    • init

      public void init()
    • getMechanismName

      public String getMechanismName()
      Get the name of this mechanism.
      Returns:
      the mechanism name
    • getProtocol

      protected String getProtocol()
      Get the protocol name.
      Returns:
      the protocol name
    • getServerName

      protected String getServerName()
      Get the server name.
      Returns:
      the server name
    • getCallbackHandler

      protected CallbackHandler getCallbackHandler()
      Get the configured authentication callback handler.
      Returns:
      the callback handler
    • getWrapper

      protected SaslWrapper getWrapper()
      Get the current configured SASL wrapper, if any.
      Returns:
      the SASL wrapper, or null if none is configured
    • setNegotiationState

      public void setNegotiationState(int newState)
      Set the state to use for the next incoming message.
      Parameters:
      newState - the new state
    • negotiationComplete

      public void negotiationComplete()
      Indicate that negotiation is complete. To re-initiate negotiation, call setNegotiationState(int).
    • evaluateMessage

      protected byte[] evaluateMessage(byte[] message) throws SaslException
      Throws:
      SaslException
    • evaluateMessage

      protected abstract byte[] evaluateMessage(int state, byte[] message) throws SaslException
      Throws:
      SaslException
    • setWrapper

      protected void setWrapper(SaslWrapper wrapper)
      Set the current configured SASL wrapper, if any.
      Parameters:
      wrapper - the SASL wrapper, or null to disable wrapping
    • wrap

      public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
      Wraps a byte array to be sent to the other participant.
      Specified by:
      wrap in interface SaslWrapper
      Parameters:
      outgoing - a non-null byte array containing the bytes to encode
      offset - the first byte to encode
      len - the number of bytes to use
      Returns:
      A non-null byte array containing the encoded bytes
      Throws:
      SaslException - if wrapping fails
      IllegalStateException - if wrapping is not configured
    • unwrap

      public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
      Unwraps a byte array received from the other participant.
      Specified by:
      unwrap in interface SaslWrapper
      Parameters:
      incoming - a non-null byte array containing the bytes to decode
      offset - the first byte to decode
      len - the number of bytes to use
      Returns:
      A non-null byte array containing the decoded bytes
      Throws:
      SaslException - if wrapping fails
      IllegalStateException - if wrapping is not configured
    • isComplete

      public boolean isComplete()
      Determine whether the authentication exchange has completed.
      Returns:
      true if the exchange has completed
    • assertComplete

      protected void assertComplete()
      A convenience method to throw a IllegalStateException is authentication is not yet complete. To be called by methods that must only be called after authentication is complete.
    • getNegotiatedProperty

      public Object getNegotiatedProperty(String propName)
      Get a property negotiated between this participant and the other.
      Parameters:
      propName - the property name
      Returns:
      the property value or null if not defined
    • getStringProperty

      public String getStringProperty(Map<String,?> map, String key, String defaultVal)
      Get a string property value from the given map.
      Parameters:
      map - the property map
      key - the property
      defaultVal - the value to return if the key is not in the map
      Returns:
      the value
    • getIntProperty

      public int getIntProperty(Map<String,?> map, String key, int defaultVal)
      Get a string property value from the given map.
      Parameters:
      map - the property map
      key - the property
      defaultVal - the value to return if the key is not in the map
      Returns:
      the value
    • dispose

      public void dispose() throws SaslException
      Dispose of this participant.
      Throws:
      SaslException - if disposal failed