Class AbstractSaslParticipant

    • Field Detail

      • 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:
        Constant Field Values
      • COMPLETE_STATE

        public static final int COMPLETE_STATE
        The SASL negotiation completed state.
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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 Detail

      • 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
      • 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 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