Package org.wildfly.security.sasl.util
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 SummaryFields Modifier and Type Field Description static intCOMPLETE_STATEThe SASL negotiation completed state.static intFAILED_STATEThe SASL negotiation failure state.static byte[]NO_BYTESAn empty byte array.- 
Fields inherited from interface org.wildfly.security.sasl.util.SaslWrapperIDENTITY
 
- 
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedAbstractSaslParticipant(String mechanismName, String protocol, String serverName, CallbackHandler callbackHandler)Deprecated.protectedAbstractSaslParticipant(String mechanismName, String protocol, String serverName, CallbackHandler callbackHandler, ElytronMessages log)Construct a new instance.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidassertComplete()A convenience method to throw aIllegalStateExceptionis authentication is not yet complete.voiddispose()Dispose of this participant.protected byte[]evaluateMessage(byte[] message)protected abstract byte[]evaluateMessage(int state, byte[] message)protected CallbackHandlergetCallbackHandler()Get the configured authentication callback handler.intgetIntProperty(Map<String,?> map, String key, int defaultVal)Get a string property value from the given map.StringgetMechanismName()Get the name of this mechanism.ObjectgetNegotiatedProperty(String propName)Get a property negotiated between this participant and the other.protected StringgetProtocol()Get the protocol name.protected StringgetServerName()Get the server name.StringgetStringProperty(Map<String,?> map, String key, String defaultVal)Get a string property value from the given map.protected SaslWrappergetWrapper()Get the current configured SASL wrapper, if any.protected voidhandleCallbacks(Callback... callbacks)Handle callbacks, wrapping exceptions as needed (including unsupported callbacks).voidinit()booleanisComplete()Determine whether the authentication exchange has completed.voidnegotiationComplete()Indicate that negotiation is complete.voidsetNegotiationState(int newState)Set the state to use for the next incoming message.protected voidsetWrapper(SaslWrapper wrapper)Set the current configured SASL wrapper, if any.protected voidtryHandleCallbacks(Callback... callbacks)Handle callbacks, wrapping exceptions as needed.byte[]unwrap(byte[] incoming, int offset, int len)Unwraps a byte array received from the other participant.byte[]wrap(byte[] outgoing, int offset, int len)Wraps a byte array to be sent to the other participant.
 
- 
- 
- 
Field Detail- 
NO_BYTESpublic static final byte[] NO_BYTES An empty byte array.
 - 
FAILED_STATEpublic static final int FAILED_STATE The SASL negotiation failure state.- See Also:
- Constant Field Values
 
 - 
COMPLETE_STATEpublic static final int COMPLETE_STATE The SASL negotiation completed state.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
AbstractSaslParticipantprotected 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- 
handleCallbacksprotected 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
 
 - 
tryHandleCallbacksprotected 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
 
 - 
initpublic void init() 
 - 
getMechanismNamepublic String getMechanismName() Get the name of this mechanism.- Returns:
- the mechanism name
 
 - 
getProtocolprotected String getProtocol() Get the protocol name.- Returns:
- the protocol name
 
 - 
getServerNameprotected String getServerName() Get the server name.- Returns:
- the server name
 
 - 
getCallbackHandlerprotected CallbackHandler getCallbackHandler() Get the configured authentication callback handler.- Returns:
- the callback handler
 
 - 
getWrapperprotected SaslWrapper getWrapper() Get the current configured SASL wrapper, if any.- Returns:
- the SASL wrapper, or nullif none is configured
 
 - 
setNegotiationStatepublic void setNegotiationState(int newState) Set the state to use for the next incoming message.- Parameters:
- newState- the new state
 
 - 
negotiationCompletepublic void negotiationComplete() Indicate that negotiation is complete. To re-initiate negotiation, callsetNegotiationState(int).
 - 
evaluateMessageprotected byte[] evaluateMessage(byte[] message) throws SaslException- Throws:
- SaslException
 
 - 
evaluateMessageprotected abstract byte[] evaluateMessage(int state, byte[] message) throws SaslException- Throws:
- SaslException
 
 - 
setWrapperprotected void setWrapper(SaslWrapper wrapper) Set the current configured SASL wrapper, if any.- Parameters:
- wrapper- the SASL wrapper, or- nullto disable wrapping
 
 - 
wrappublic byte[] wrap(byte[] outgoing, int offset, int len) throws SaslExceptionWraps a byte array to be sent to the other participant.- Specified by:
- wrapin interface- SaslWrapper
- Parameters:
- outgoing- a non-- nullbyte array containing the bytes to encode
- offset- the first byte to encode
- len- the number of bytes to use
- Returns:
- A non-nullbyte array containing the encoded bytes
- Throws:
- SaslException- if wrapping fails
- IllegalStateException- if wrapping is not configured
 
 - 
unwrappublic byte[] unwrap(byte[] incoming, int offset, int len) throws SaslExceptionUnwraps a byte array received from the other participant.- Specified by:
- unwrapin interface- SaslWrapper
- Parameters:
- incoming- a non-- nullbyte array containing the bytes to decode
- offset- the first byte to decode
- len- the number of bytes to use
- Returns:
- A non-nullbyte array containing the decoded bytes
- Throws:
- SaslException- if wrapping fails
- IllegalStateException- if wrapping is not configured
 
 - 
isCompletepublic boolean isComplete() Determine whether the authentication exchange has completed.- Returns:
- trueif the exchange has completed
 
 - 
assertCompleteprotected void assertComplete() A convenience method to throw aIllegalStateExceptionis authentication is not yet complete. To be called by methods that must only be called after authentication is complete.
 - 
getNegotiatedPropertypublic Object getNegotiatedProperty(String propName) Get a property negotiated between this participant and the other.- Parameters:
- propName- the property name
- Returns:
- the property value or nullif not defined
 
 - 
getStringPropertypublic 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
 
 - 
getIntPropertypublic 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
 
 - 
disposepublic void dispose() throws SaslExceptionDispose of this participant.- Throws:
- SaslException- if disposal failed
 
 
- 
 
-