Top Description Fields Constructors Methods
org.xnio.sasl

public final Class SaslUtils

extends Object
Class Inheritance
Static Imports
java.security.AccessController.doPrivileged, org.xnio._private.Messages.msg

Utility methods for handling SASL authentication using NIO-style programming methods.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
public static final byte[]
EMPTY_BYTES

A zero-length byte array, useful for sending and receiving empty SASL messages.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static <T> void
add(OptionMap optionMap, Option<T> option, Map<String, Object> map, String propName, T defaultVal)

private static void
addQopList(OptionMap optionMap, Option<Sequence<SaslQop>> option, Map<String, Object> map, String propName)

private static void
public static Map<String, Object>

Returns:

the property map
createPropertyMap
(final OptionMap
the option map
optionMap
,
final boolean
true if the channel is secure, false otherwise
secure
)

Create a SASL property map from an XNIO option map.

public static boolean

Returns:

true if negotiation is complete and successful, false otherwise
evaluateChallenge
(SaslClient
the SASL client to use to evaluate the challenge message
client
,
ByteBuffer
the destination buffer into which the response message should be written, if any
destination
,
ByteBuffer
the source buffer from which the challenge message should be read
source
)

Evaluate a sasl challenge.

public static byte[]

Returns:

null if negotiation is complete and successful, or the response otherwise
evaluateChallenge
(SaslClient
the SASL client to use to evaluate the challenge message
client
,
ByteBuffer
the source buffer from which the challenge message should be read
source
)

Evaluate a sasl challenge.

public static boolean

Returns:

true if negotiation is complete and successful, false otherwise
evaluateResponse
(SaslServer
the SASL server to use to evaluate the response message
server
,
ByteBuffer
the destination buffer into which the response message should be written, if any
destination
,
ByteBuffer
the source buffer from which the response message should be read
source
)

Evaluate a sasl response.

public static byte[]

Returns:

true if negotiation is complete and successful, false otherwise
evaluateResponse
(final SaslServer
the SASL server to use to evaluate the response message
server
,
final ByteBuffer
the source buffer from which the response message should be read
source
)

Evaluate a sasl response.

private static <T> Iterator<T>
getFactories(Class<T> type, ClassLoader classLoader, boolean includeGlobal)

public static Iterator<SaslClientFactory>

Returns:

the Iterator of SaslClientFactorys
getSaslClientFactories
(ClassLoader
the class loader to use
classLoader
,
boolean
true to include globally registered providers, false to exclude them
includeGlobal
)

Returns an iterator of all of the registered SaslClientFactorys where the order is based on the order of the Provider registration and/or class path order.

public static Iterator<SaslClientFactory>

Returns:

the Iterator of SaslClientFactorys
getSaslClientFactories
()

Returns an iterator of all of the registered SaslClientFactorys where the order is based on the order of the Provider registration and/or class path order.

public static Iterator<SaslServerFactory>

Returns:

the Iterator of SaslServerFactorys
getSaslServerFactories
(ClassLoader
the class loader to use
classLoader
,
boolean
true to include globally registered providers, false to exclude them
includeGlobal
)

Returns an iterator of all of the registered SaslServerFactorys where the order is based on the order of the Provider registration and/or class path order.

public static Iterator<SaslServerFactory>

Returns:

the Iterator of SaslServerFactorys
getSaslServerFactories
()

Returns an iterator of all of the registered SaslServerFactorys where the order is based on the order of the Provider registration and/or class path order.

public static void
unwrap(SaslClient
the SASL client to unwrap with
client
,
ByteBuffer
the buffer into which bytes should be written
destination
,
ByteBuffer
the buffers from which bytes should be read
source
)

Unwrap a message.

public static byte[]

Returns:

the wrap result
unwrap
(final SaslClient
the SASL client to unwrap with
client
,
final ByteBuffer
the buffers from which bytes should be read
source
)

Unwrap a message.

public static void
unwrap(SaslServer
the SASL server to unwrap with
server
,
ByteBuffer
the buffer into which bytes should be written
destination
,
ByteBuffer
the buffers from which bytes should be read
source
)

Unwrap a message.

public static byte[]

Returns:

the wrap result
unwrap
(final SaslServer
the SASL server to unwrap with
server
,
final ByteBuffer
the buffers from which bytes should be read
source
)

Unwrap a message.

public static void
wrap(SaslClient
the SASL client to wrap with
client
,
ByteBuffer
the buffer into which bytes should be written
destination
,
ByteBuffer
the buffers from which bytes should be read
source
)

Wrap a message.

public static byte[]

Returns:

the wrap result
wrap
(final SaslClient
the SASL client to wrap with
client
,
final ByteBuffer
the buffers from which bytes should be read
source
)

Wrap a message.

public static void
wrap(SaslServer
the SASL server to wrap with
server
,
ByteBuffer
the buffer into which bytes should be written
destination
,
ByteBuffer
the buffers from which bytes should be read
source
)

Wrap a message.

public static byte[]

Returns:

the wrap result
wrap
(final SaslServer
the SASL server to wrap with
server
,
final ByteBuffer
the buffers from which bytes should be read
source
)

Wrap a message.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_BYTESback to summary
public static final byte[] EMPTY_BYTES

A zero-length byte array, useful for sending and receiving empty SASL messages.

Constructor Detail

SaslUtilsback to summary
private SaslUtils()

Method Detail

addback to summary
private static <T> void add(OptionMap optionMap, Option<T> option, Map<String, Object> map, String propName, T defaultVal)
addQopListback to summary
private static void addQopList(OptionMap optionMap, Option<Sequence<SaslQop>> option, Map<String, Object> map, String propName)
addSaslPropertiesback to summary
private static void addSaslProperties(OptionMap optionMap, Option<Sequence<Property>> option, Map<String, Object> map)
createPropertyMapback to summary
public static Map<String, Object> createPropertyMap(final OptionMap optionMap, final boolean secure)

Create a SASL property map from an XNIO option map.

Parameters
optionMap:OptionMap

the option map

secure:boolean

true if the channel is secure, false otherwise

Returns:Map<String, Object>

the property map

evaluateChallengeback to summary
public static boolean evaluateChallenge(SaslClient client, ByteBuffer destination, ByteBuffer source) throws SaslException

Evaluate a sasl challenge. If the result is false then 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 is true then negotiation was successful and no response needs to be sent to the server.

The source buffer 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:SaslClient

the SASL client to use to evaluate the challenge message

destination:ByteBuffer

the destination buffer into which the response message should be written, if any

source:ByteBuffer

the source buffer from which the challenge message should be read

Returns:boolean

true if negotiation is complete and successful, false otherwise

Exceptions
SaslException:
if negotiation failed or another error occurred
evaluateChallengeback to summary
public static byte[] evaluateChallenge(SaslClient client, ByteBuffer source) throws SaslException

Evaluate a sasl challenge. If the result is non-null then the negotiation is not yet complete and the data returned needs to be sent to the server as a response. If the result is null then negotiation was successful and no response needs to be sent to the server.

The source buffer 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:SaslClient

the SASL client to use to evaluate the challenge message

source:ByteBuffer

the source buffer from which the challenge message should be read

Returns:byte[]

null if negotiation is complete and successful, or the response otherwise

Exceptions
SaslException:
if negotiation failed or another error occurred
evaluateResponseback to summary
public static boolean evaluateResponse(SaslServer server, ByteBuffer destination, ByteBuffer source) throws SaslException

Evaluate a sasl response. If the result is false then 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 is true then negotiation was successful and no response needs to be sent to the client (other than a successful completion message, depending on the protocol).

The source buffer 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:SaslServer

the SASL server to use to evaluate the response message

destination:ByteBuffer

the destination buffer into which the response message should be written, if any

source:ByteBuffer

the source buffer from which the response message should be read

Returns:boolean

true if negotiation is complete and successful, false otherwise

Exceptions
SaslException:
if negotiation failed or another error occurred
evaluateResponseback to summary
public static byte[] evaluateResponse(final SaslServer server, final ByteBuffer source) throws SaslException

Evaluate a sasl response. If the result is non-null then the negotiation is not yet complete and the data returned needs to be sent to the server as a response. If the result is null then negotiation was successful and no response needs to be sent to the client (other than a successful completion message, depending on the protocol).

The source buffer 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:SaslServer

the SASL server to use to evaluate the response message

source:ByteBuffer

the source buffer from which the response message should be read

Returns:byte[]

true if negotiation is complete and successful, false otherwise

Exceptions
SaslException:
if negotiation failed or another error occurred
getFactoriesback to summary
private static <T> Iterator<T> getFactories(Class<T> type, ClassLoader classLoader, boolean includeGlobal)
getSaslClientFactoriesback to summary
public static Iterator<SaslClientFactory> getSaslClientFactories(ClassLoader classLoader, boolean includeGlobal)

Returns an iterator of all of the registered SaslClientFactorys 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:ClassLoader

the class loader to use

includeGlobal:boolean

true to include globally registered providers, false to exclude them

Returns:Iterator<SaslClientFactory>

the Iterator of SaslClientFactorys

getSaslClientFactoriesback to summary
public static Iterator<SaslClientFactory> getSaslClientFactories()

Returns an iterator of all of the registered SaslClientFactorys where the order is based on the order of the Provider registration and/or class path order.

Returns:Iterator<SaslClientFactory>

the Iterator of SaslClientFactorys

getSaslServerFactoriesback to summary
public static Iterator<SaslServerFactory> getSaslServerFactories(ClassLoader classLoader, boolean includeGlobal)

Returns an iterator of all of the registered SaslServerFactorys 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:ClassLoader

the class loader to use

includeGlobal:boolean

true to include globally registered providers, false to exclude them

Returns:Iterator<SaslServerFactory>

the Iterator of SaslServerFactorys

getSaslServerFactoriesback to summary
public static Iterator<SaslServerFactory> getSaslServerFactories()

Returns an iterator of all of the registered SaslServerFactorys where the order is based on the order of the Provider registration and/or class path order.

Returns:Iterator<SaslServerFactory>

the Iterator of SaslServerFactorys

unwrapback to summary
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 source buffer 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:SaslClient

the SASL client to unwrap with

destination:ByteBuffer

the buffer into which bytes should be written

source:ByteBuffer

the buffers from which bytes should be read

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslClient#unwrap(byte[], int, int)
unwrapback to summary
public static byte[] unwrap(final SaslClient client, final ByteBuffer source) throws SaslException

Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.

The source buffer 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:SaslClient

the SASL client to unwrap with

source:ByteBuffer

the buffers from which bytes should be read

Returns:byte[]

the wrap result

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslClient#unwrap(byte[], int, int)
unwrapback to summary
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 source buffer 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:SaslServer

the SASL server to unwrap with

destination:ByteBuffer

the buffer into which bytes should be written

source:ByteBuffer

the buffers from which bytes should be read

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslServer#unwrap(byte[], int, int)
unwrapback to summary
public static byte[] unwrap(final SaslServer server, final ByteBuffer source) throws SaslException

Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.

The source buffer 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:SaslServer

the SASL server to unwrap with

source:ByteBuffer

the buffers from which bytes should be read

Returns:byte[]

the wrap result

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslServer#unwrap(byte[], int, int)
wrapback to summary
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 source buffer 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:SaslClient

the SASL client to wrap with

destination:ByteBuffer

the buffer into which bytes should be written

source:ByteBuffer

the buffers from which bytes should be read

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslClient#wrap(byte[], int, int)
wrapback to summary
public static byte[] wrap(final SaslClient client, final ByteBuffer source) throws SaslException

Wrap a message. Wrapping occurs from the source buffer to the destination idea.

The source buffer 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:SaslClient

the SASL client to wrap with

source:ByteBuffer

the buffers from which bytes should be read

Returns:byte[]

the wrap result

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslClient#wrap(byte[], int, int)
wrapback to summary
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 source buffer 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:SaslServer

the SASL server to wrap with

destination:ByteBuffer

the buffer into which bytes should be written

source:ByteBuffer

the buffers from which bytes should be read

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslServer#wrap(byte[], int, int)
wrapback to summary
public static byte[] wrap(final SaslServer server, final ByteBuffer source) throws SaslException

Wrap a message. Wrapping occurs from the source buffer to the destination idea.

The source buffer 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:SaslServer

the SASL server to wrap with

source:ByteBuffer

the buffers from which bytes should be read

Returns:byte[]

the wrap result

Exceptions
SaslException:
if a SASL error occurs
See Also
SaslServer#wrap(byte[], int, int)