Package org.wildfly.security.sasl.util
Class AbstractSaslParticipant
- java.lang.Object
-
- org.wildfly.security.sasl.util.AbstractSaslParticipant
-
- All Implemented Interfaces:
SaslWrapper
- Direct Known Subclasses:
AbstractDigestMechanism
,AbstractGssapiMechanism
,AbstractSaslClient
,AbstractSaslServer
public abstract class AbstractSaslParticipant extends Object implements SaslWrapper
A common base class for SASL participants.- Author:
- David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description private CallbackHandler
callbackHandler
static int
COMPLETE_STATE
The SASL negotiation completed state.static int
FAILED_STATE
The SASL negotiation failure state.private ElytronMessages
legacyLog
private ElytronMessages
log
private String
mechanismName
static byte[]
NO_BYTES
An empty byte array.private String
protocol
private String
serverName
private int
state
private SaslWrapper
wrapper
-
Fields inherited from interface org.wildfly.security.sasl.util.SaslWrapper
IDENTITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSaslParticipant(String mechanismName, String protocol, String serverName, CallbackHandler callbackHandler)
Deprecated.protected
AbstractSaslParticipant(String mechanismName, String protocol, String serverName, CallbackHandler callbackHandler, ElytronMessages log)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
assertComplete()
A convenience method to throw aIllegalStateException
is authentication is not yet complete.void
dispose()
Dispose of this participant.protected byte[]
evaluateMessage(byte[] message)
protected abstract byte[]
evaluateMessage(int state, byte[] message)
protected CallbackHandler
getCallbackHandler()
Get the configured authentication callback handler.int
getIntProperty(Map<String,?> map, String key, int defaultVal)
Get a string property value from the given map.String
getMechanismName()
Get the name of this mechanism.Object
getNegotiatedProperty(String propName)
Get a property negotiated between this participant and the other.protected String
getProtocol()
Get the protocol name.protected String
getServerName()
Get the server name.String
getStringProperty(Map<String,?> map, String key, String defaultVal)
Get a string property value from the given map.protected SaslWrapper
getWrapper()
Get the current configured SASL wrapper, if any.protected void
handleCallbacks(Callback... callbacks)
Handle callbacks, wrapping exceptions as needed (including unsupported callbacks).void
init()
boolean
isComplete()
Determine whether the authentication exchange has completed.void
negotiationComplete()
Indicate that negotiation is complete.void
setNegotiationState(int newState)
Set the state to use for the next incoming message.protected void
setWrapper(SaslWrapper wrapper)
Set the current configured SASL wrapper, if any.protected void
tryHandleCallbacks(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_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
-
mechanismName
private final String mechanismName
-
callbackHandler
private final CallbackHandler callbackHandler
-
protocol
private final String protocol
-
serverName
private final String serverName
-
log
private ElytronMessages log
-
legacyLog
private ElytronMessages legacyLog
-
state
private int state
-
wrapper
private SaslWrapper wrapper
-
-
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 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 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
-
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
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, callsetNegotiationState(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, ornull
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 interfaceSaslWrapper
- Parameters:
outgoing
- a non-null
byte array containing the bytes to encodeoffset
- the first byte to encodelen
- the number of bytes to use- Returns:
- A non-
null
byte array containing the encoded bytes - Throws:
SaslException
- if wrapping failsIllegalStateException
- 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 interfaceSaslWrapper
- Parameters:
incoming
- a non-null
byte array containing the bytes to decodeoffset
- the first byte to decodelen
- the number of bytes to use- Returns:
- A non-
null
byte 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:
true
if the exchange has completed
-
assertComplete
protected void assertComplete()
A convenience method to throw aIllegalStateException
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 mapkey
- the propertydefaultVal
- 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 mapkey
- the propertydefaultVal
- 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
-
-