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
A common base class for SASL participants.
- Author:
- David M. Lloyd
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe SASL negotiation completed state.static final intThe SASL negotiation failure state.static final byte[]An empty byte array.Fields inherited from interface org.wildfly.security.sasl.util.SaslWrapper
IDENTITY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSaslParticipant(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 Summary
Modifier and TypeMethodDescriptionprotected voidA 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 CallbackHandlerGet the configured authentication callback handler.intgetIntProperty(Map<String, ?> map, String key, int defaultVal) Get a string property value from the given map.Get the name of this mechanism.getNegotiatedProperty(String propName) Get a property negotiated between this participant and the other.protected StringGet the protocol name.protected StringGet the server name.getStringProperty(Map<String, ?> map, String key, String defaultVal) Get a string property value from the given map.protected SaslWrapperGet the current configured SASL wrapper, if any.protected voidhandleCallbacks(Callback... callbacks) Handle callbacks, wrapping exceptions as needed (including unsupported callbacks).voidinit()booleanDetermine whether the authentication exchange has completed.voidIndicate 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 Details
-
NO_BYTES
public static final byte[] NO_BYTESAn empty byte array. -
FAILED_STATE
public static final int FAILED_STATEThe SASL negotiation failure state.- See Also:
-
COMPLETE_STATE
public static final int COMPLETE_STATEThe 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 mechanismprotocol- the protocolserverName- the server namecallbackHandler- the callback handlerlog- 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 mechanismprotocol- the protocolserverName- the server namecallbackHandler- the callback handler
-
-
Method Details
-
handleCallbacks
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 failedUnsupportedCallbackException- if a callback isn't supported
-
init
public void init() -
getMechanismName
Get the name of this mechanism.- Returns:
- the mechanism name
-
getProtocol
Get the protocol name.- Returns:
- the protocol name
-
getServerName
Get the server name.- Returns:
- the server name
-
getCallbackHandler
Get the configured authentication callback handler.- Returns:
- the callback handler
-
getWrapper
Get the current configured SASL wrapper, if any.- Returns:
- the SASL wrapper, or
nullif 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, callsetNegotiationState(int). -
evaluateMessage
- Throws:
SaslException
-
evaluateMessage
- Throws:
SaslException
-
setWrapper
Set the current configured SASL wrapper, if any.- Parameters:
wrapper- the SASL wrapper, ornullto disable wrapping
-
wrap
Wraps a byte array to be sent to the other participant.- Specified by:
wrapin interfaceSaslWrapper- Parameters:
outgoing- a non-nullbyte array containing the bytes to encodeoffset- the first byte to encodelen- the number of bytes to use- Returns:
- A non-
nullbyte array containing the encoded bytes - Throws:
SaslException- if wrapping failsIllegalStateException- if wrapping is not configured
-
unwrap
Unwraps a byte array received from the other participant.- Specified by:
unwrapin interfaceSaslWrapper- Parameters:
incoming- a non-nullbyte array containing the bytes to decodeoffset- the first byte to decodelen- the number of bytes to use- Returns:
- A non-
nullbyte array containing the decoded bytes - Throws:
SaslException- if wrapping failsIllegalStateException- if wrapping is not configured
-
isComplete
public boolean isComplete()Determine whether the authentication exchange has completed.- Returns:
trueif the exchange has completed
-
assertComplete
protected 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. -
getNegotiatedProperty
Get a property negotiated between this participant and the other.- Parameters:
propName- the property name- Returns:
- the property value or
nullif not defined
-
getStringProperty
Get a string property value from the given map.- Parameters:
map- the property mapkey- the propertydefaultVal- the value to return if the key is not in the map- Returns:
- the value
-
getIntProperty
Get a string property value from the given map.- Parameters:
map- the property mapkey- the propertydefaultVal- the value to return if the key is not in the map- Returns:
- the value
-
dispose
Dispose of this participant.- Throws:
SaslException- if disposal failed
-