Class SaslUtils
- Author:
- David M. Lloyd
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]A zero-length byte array, useful for sending and receiving empty SASL messages. -
Method Summary
Modifier and TypeMethodDescriptioncreatePropertyMap(OptionMap optionMap, boolean secure) Create a SASL property map from an XNIO option map.static byte[]evaluateChallenge(SaslClient client, ByteBuffer source) Evaluate a sasl challenge.static booleanevaluateChallenge(SaslClient client, ByteBuffer destination, ByteBuffer source) Evaluate a sasl challenge.static byte[]evaluateResponse(SaslServer server, ByteBuffer source) Evaluate a sasl response.static booleanevaluateResponse(SaslServer server, ByteBuffer destination, ByteBuffer source) Evaluate a sasl response.static Iterator<SaslClientFactory>Returns an iterator of all of the registeredSaslClientFactorys where the order is based on the order of the Provider registration and/or class path order.static Iterator<SaslClientFactory>getSaslClientFactories(ClassLoader classLoader, boolean includeGlobal) Returns an iterator of all of the registeredSaslClientFactorys where the order is based on the order of the Provider registration and/or class path order.static Iterator<SaslServerFactory>Returns an iterator of all of the registeredSaslServerFactorys where the order is based on the order of the Provider registration and/or class path order.static Iterator<SaslServerFactory>getSaslServerFactories(ClassLoader classLoader, boolean includeGlobal) Returns an iterator of all of the registeredSaslServerFactorys where the order is based on the order of the Provider registration and/or class path order.static byte[]unwrap(SaslClient client, ByteBuffer source) Unwrap a message.static voidunwrap(SaslClient client, ByteBuffer destination, ByteBuffer source) Unwrap a message.static byte[]unwrap(SaslServer server, ByteBuffer source) Unwrap a message.static voidunwrap(SaslServer server, ByteBuffer destination, ByteBuffer source) Unwrap a message.static byte[]wrap(SaslClient client, ByteBuffer source) Wrap a message.static voidwrap(SaslClient client, ByteBuffer destination, ByteBuffer source) Wrap a message.static byte[]wrap(SaslServer server, ByteBuffer source) Wrap a message.static voidwrap(SaslServer server, ByteBuffer destination, ByteBuffer source) Wrap a message.
-
Field Details
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTESA zero-length byte array, useful for sending and receiving empty SASL messages.
-
-
Method Details
-
getSaslServerFactories
public static Iterator<SaslServerFactory> getSaslServerFactories(ClassLoader classLoader, boolean includeGlobal) Returns an iterator of all of the registeredSaslServerFactorys where the order is based on the order of the Provider registration and/or class path order. Class path providers are listed before global providers; in the event of a name conflict, the class path provider is preferred.- Parameters:
classLoader- the class loader to useincludeGlobal-trueto include globally registered providers,falseto exclude them- Returns:
- the
IteratorofSaslServerFactorys
-
getSaslServerFactories
Returns an iterator of all of the registeredSaslServerFactorys where the order is based on the order of the Provider registration and/or class path order.- Returns:
- the
IteratorofSaslServerFactorys
-
getSaslClientFactories
public static Iterator<SaslClientFactory> getSaslClientFactories(ClassLoader classLoader, boolean includeGlobal) Returns an iterator of all of the registeredSaslClientFactorys where the order is based on the order of the Provider registration and/or class path order. Class path providers are listed before global providers; in the event of a name conflict, the class path provider is preferred.- Parameters:
classLoader- the class loader to useincludeGlobal-trueto include globally registered providers,falseto exclude them- Returns:
- the
IteratorofSaslClientFactorys
-
getSaslClientFactories
Returns an iterator of all of the registeredSaslClientFactorys where the order is based on the order of the Provider registration and/or class path order.- Returns:
- the
IteratorofSaslClientFactorys
-
evaluateChallenge
public static boolean evaluateChallenge(SaslClient client, ByteBuffer destination, ByteBuffer source) throws SaslException Evaluate a sasl challenge. If the result isfalsethen the negotiation is not yet complete and the data written into the destination buffer needs to be sent to the server as a response. If the result istruethen negotiation was successful and no response needs to be sent to the server.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message. The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
client- the SASL client to use to evaluate the challenge messagedestination- the destination buffer into which the response message should be written, if anysource- the source buffer from which the challenge message should be read- Returns:
trueif negotiation is complete and successful,falseotherwise- Throws:
SaslException- if negotiation failed or another error occurred
-
evaluateChallenge
Evaluate a sasl challenge. If the result is non-nullthen the negotiation is not yet complete and the data returned needs to be sent to the server as a response. If the result isnullthen negotiation was successful and no response needs to be sent to the server.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message. The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
client- the SASL client to use to evaluate the challenge messagesource- the source buffer from which the challenge message should be read- Returns:
nullif negotiation is complete and successful, or the response otherwise- Throws:
SaslException- if negotiation failed or another error occurred
-
evaluateResponse
public static boolean evaluateResponse(SaslServer server, ByteBuffer destination, ByteBuffer source) throws SaslException Evaluate a sasl response. If the result isfalsethen the negotiation is not yet complete and the data written into the destination buffer needs to be sent to the server as a response. If the result istruethen negotiation was successful and no response needs to be sent to the client (other than a successful completion message, depending on the protocol).The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message. The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
server- the SASL server to use to evaluate the response messagedestination- the destination buffer into which the response message should be written, if anysource- the source buffer from which the response message should be read- Returns:
trueif negotiation is complete and successful,falseotherwise- Throws:
SaslException- if negotiation failed or another error occurred
-
evaluateResponse
Evaluate a sasl response. If the result is non-nullthen the negotiation is not yet complete and the data returned needs to be sent to the server as a response. If the result isnullthen negotiation was successful and no response needs to be sent to the client (other than a successful completion message, depending on the protocol).The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message. The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
server- the SASL server to use to evaluate the response messagesource- the source buffer from which the response message should be read- Returns:
trueif negotiation is complete and successful,falseotherwise- Throws:
SaslException- if negotiation failed or another error occurred
-
wrap
public static void wrap(SaslClient client, ByteBuffer destination, ByteBuffer source) throws SaslException Wrap a message. Wrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
client- the SASL client to wrap withdestination- the buffer into which bytes should be writtensource- the buffers from which bytes should be read- Throws:
SaslException- if a SASL error occurs- See Also:
-
wrap
Wrap a message. Wrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
client- the SASL client to wrap withsource- the buffers from which bytes should be read- Returns:
- the wrap result
- Throws:
SaslException- if a SASL error occurs- See Also:
-
wrap
public static void wrap(SaslServer server, ByteBuffer destination, ByteBuffer source) throws SaslException Wrap a message. Wrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
server- the SASL server to wrap withdestination- the buffer into which bytes should be writtensource- the buffers from which bytes should be read- Throws:
SaslException- if a SASL error occurs- See Also:
-
wrap
Wrap a message. Wrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
server- the SASL server to wrap withsource- the buffers from which bytes should be read- Returns:
- the wrap result
- Throws:
SaslException- if a SASL error occurs- See Also:
-
unwrap
public static void unwrap(SaslClient client, ByteBuffer destination, ByteBuffer source) throws SaslException Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
client- the SASL client to unwrap withdestination- the buffer into which bytes should be writtensource- the buffers from which bytes should be read- Throws:
SaslException- if a SASL error occurs- See Also:
-
unwrap
Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
client- the SASL client to unwrap withsource- the buffers from which bytes should be read- Returns:
- the wrap result
- Throws:
SaslException- if a SASL error occurs- See Also:
-
unwrap
public static void unwrap(SaslServer server, ByteBuffer destination, ByteBuffer source) throws SaslException Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
server- the SASL server to unwrap withdestination- the buffer into which bytes should be writtensource- the buffers from which bytes should be read- Throws:
SaslException- if a SASL error occurs- See Also:
-
unwrap
Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.The
sourcebuffer should have its position and remaining length set to encompass exactly one SASL message (without the length field). The SASL message itself does not encode any length information so it is up to the protocol implementer to ensure that the message is properly framed.- Parameters:
server- the SASL server to unwrap withsource- the buffers from which bytes should be read- Returns:
- the wrap result
- Throws:
SaslException- if a SASL error occurs- See Also:
-
createPropertyMap
Create a SASL property map from an XNIO option map.- Parameters:
optionMap- the option mapsecure-trueif the channel is secure,falseotherwise- Returns:
- the property map
-