Top Fields Constructors Methods
io.rsocket.metadata

public Class AuthMetadataCodec

extends Object
Class Inheritance
Imports
io.netty.buffer.ByteBuf, .ByteBufAllocator, .ByteBufUtil, .Unpooled, io.netty.util.CharsetUtil, io.rsocket.util.CharByteBufUtil

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final char[]
pack-priv static final int
pack-priv static final byte
pack-priv static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ByteBuf
encodeBearerMetadata(ByteBufAllocator
the ByteBufAllocator to use to create intermediate buffers as needed.
allocator
,
char[]
the char sequence which represents BEARER token.
token
)

Encode a Authentication CompositeMetadata payload using Bearer Authentication format

public static ByteBuf
encodeMetadata(ByteBufAllocator
the ByteBufAllocator to use to create intermediate buffers as needed.
allocator
,
String
the custom mime type to encode.
customAuthType
,
ByteBuf
the metadata value to encode.
metadata
)

Encode a Authentication CompositeMetadata payload using custom authentication type

public static ByteBuf
encodeMetadata(ByteBufAllocator
the ByteBufAllocator to create intermediate buffers as needed.
allocator
,
WellKnownAuthType
the well-known mime type to encode.
authType
,
ByteBuf
the metadata value to encode.
metadata
)

Encode a Authentication CompositeMetadata payload using custom authentication type

public static ByteBuf
encodeMetadataWithCompression(ByteBufAllocator
the ByteBufAllocator to use to create intermediate buffers as needed.
allocator
,
String
the mime type to encode, as a String. well known mime types are compressed.
authType
,
ByteBuf
the metadata value to encode.
metadata
)

Encode a new Authentication Metadata payload information, first verifying if the passed String matches a WellKnownAuthType (in which case it will be encoded in a compressed fashion using the mime id of that type).

public static ByteBuf
encodeSimpleMetadata(ByteBufAllocator
the ByteBufAllocator to use to create intermediate buffers as needed.
allocator
,
char[]
the char sequence which represents user name.
username
,
char[]
the char sequence which represents user password.
password
)

Encode a Authentication CompositeMetadata payload using Simple Authentication format

public static boolean
isWellKnownAuthType(ByteBuf
byteBuf used to get information from
metadata
)

Get the first byte from a ByteBuf and check whether it is length or WellKnownAuthType.

public static char[]

Returns:

char[] which represents UTF-8 password
readBearerTokenAsCharArray
(ByteBuf
the given metadata to read username from. Please note, the bearerAuthMetadata#readIndex should be set to the beginning of the password bytes
bearerAuthMetadata
)

Read all the remaining bytes from the given ByteBuf

public static CharSequence
readCustomAuthType(ByteBuf metadata)

Read up to 129 bytes from the given metadata in order to get the custom Auth Type

public static ByteBuf

Returns:

sliced ByteBuf or Unpooled#EMPTY_BUFFER if password length is zero
readPassword
(ByteBuf
the given metadata to read password from. Please note, the simpleAuthMetadata#readIndex should be set to the beginning of the password bytes
simpleAuthMetadata
)

Read all the remaining bytes from the given ByteBuf which represents user's password

public static char[]

Returns:

char[] which represents UTF-8 password
readPasswordAsCharArray
(ByteBuf
the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex should be set to the beginning of the password bytes
simpleAuthMetadata
)

Read all the remaining bytes from the given ByteBuf which represents user's password

public static ByteBuf

Returns:

sliced ByteBuf or Unpooled#EMPTY_BUFFER if no bytes readable in the given one
readPayload
(ByteBuf
metadata to get payload from. Please note, the metadata#readIndex should be set to the beginning of the payload bytes
metadata
)

Read all remaining bytes from the given ByteBuf and return sliced representation of a payload

public static ByteBuf

Returns:

sliced ByteBuf or Unpooled#EMPTY_BUFFER if username length is zero
readUsername
(ByteBuf
the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex should be set to the username length position
simpleAuthMetadata
)

Read up to 65537 bytes from the given ByteBuf where the first two bytes represent username length and the subsequent number of bytes equal to read length

public static char[]

Returns:

char[] which represents UTF-8 username
readUsernameAsCharArray
(ByteBuf
the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex should be set to the username length byte
simpleAuthMetadata
)

Read up to 65537 bytes from the given ByteBuf where the first two bytes represent username length and the subsequent number of bytes equal to read length

private static int
readUsernameLength(ByteBuf simpleAuthMetadata)

public static WellKnownAuthType

Returns:

Return on of the know Auth types or WellKnownAuthType#UNPARSEABLE_AUTH_TYPE if field's value is length or unknown auth type
readWellKnownAuthType
(ByteBuf
given metadata buffer to read from
metadata
)

Read first byte from the given metadata and tries to convert it's value to WellKnownAuthType.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTH_TYPE_ID_LENGTHback to summary
pack-priv static final int AUTH_TYPE_ID_LENGTH
EMPTY_CHARS_ARRAYback to summary
pack-priv static final char[] EMPTY_CHARS_ARRAY
STREAM_METADATA_KNOWN_MASKback to summary
pack-priv static final int STREAM_METADATA_KNOWN_MASK
STREAM_METADATA_LENGTH_MASKback to summary
pack-priv static final byte STREAM_METADATA_LENGTH_MASK
USERNAME_BYTES_LENGTHback to summary
pack-priv static final int USERNAME_BYTES_LENGTH

Constructor Detail

AuthMetadataCodecback to summary
private AuthMetadataCodec()

Method Detail

encodeBearerMetadataback to summary
public static ByteBuf encodeBearerMetadata(ByteBufAllocator allocator, char[] token)

Encode a Authentication CompositeMetadata payload using Bearer Authentication format

Parameters
allocator:ByteBufAllocator

the ByteBufAllocator to use to create intermediate buffers as needed.

token:char[]

the char sequence which represents BEARER token.

encodeMetadataback to summary
public static ByteBuf encodeMetadata(ByteBufAllocator allocator, String customAuthType, ByteBuf metadata)

Encode a Authentication CompositeMetadata payload using custom authentication type

Parameters
allocator:ByteBufAllocator

the ByteBufAllocator to use to create intermediate buffers as needed.

customAuthType:String

the custom mime type to encode.

metadata:ByteBuf

the metadata value to encode.

Exceptions
IllegalArgumentException:
in case of customAuthType is non US_ASCII string or empty string or its length is greater than 128 bytes
encodeMetadataback to summary
public static ByteBuf encodeMetadata(ByteBufAllocator allocator, WellKnownAuthType authType, ByteBuf metadata)

Encode a Authentication CompositeMetadata payload using custom authentication type

Parameters
allocator:ByteBufAllocator

the ByteBufAllocator to create intermediate buffers as needed.

authType:WellKnownAuthType

the well-known mime type to encode.

metadata:ByteBuf

the metadata value to encode.

Exceptions
IllegalArgumentException:
in case of authType is WellKnownAuthType#UNPARSEABLE_AUTH_TYPE or WellKnownAuthType#UNKNOWN_RESERVED_AUTH_TYPE
encodeMetadataWithCompressionback to summary
public static ByteBuf encodeMetadataWithCompression(ByteBufAllocator allocator, String authType, ByteBuf metadata)

Encode a new Authentication Metadata payload information, first verifying if the passed String matches a WellKnownAuthType (in which case it will be encoded in a compressed fashion using the mime id of that type).

Prefer using encodeMetadata(ByteBufAllocator, String, ByteBuf) if you already know that the mime type is not a WellKnownAuthType.

Parameters
allocator:ByteBufAllocator

the ByteBufAllocator to use to create intermediate buffers as needed.

authType:String

the mime type to encode, as a String. well known mime types are compressed.

metadata:ByteBuf

the metadata value to encode.

See Also
encodeMetadata(ByteBufAllocator, WellKnownAuthType, ByteBuf), encodeMetadata(ByteBufAllocator, String, ByteBuf)
encodeSimpleMetadataback to summary
public static ByteBuf encodeSimpleMetadata(ByteBufAllocator allocator, char[] username, char[] password)

Encode a Authentication CompositeMetadata payload using Simple Authentication format

Parameters
allocator:ByteBufAllocator

the ByteBufAllocator to use to create intermediate buffers as needed.

username:char[]

the char sequence which represents user name.

password:char[]

the char sequence which represents user password.

Exceptions
IllegalArgumentException:
if the username length is greater than 65535
isWellKnownAuthTypeback to summary
public static boolean isWellKnownAuthType(ByteBuf metadata)

Get the first byte from a ByteBuf and check whether it is length or WellKnownAuthType. Assuming said buffer properly contains such a byte

Parameters
metadata:ByteBuf

byteBuf used to get information from

readBearerTokenAsCharArrayback to summary
public static char[] readBearerTokenAsCharArray(ByteBuf bearerAuthMetadata)

Read all the remaining bytes from the given ByteBuf

Parameters
bearerAuthMetadata:ByteBuf

the given metadata to read username from. Please note, the bearerAuthMetadata#readIndex should be set to the beginning of the password bytes

Returns:char[]

char[] which represents UTF-8 password

readCustomAuthTypeback to summary
public static CharSequence readCustomAuthType(ByteBuf metadata)

Read up to 129 bytes from the given metadata in order to get the custom Auth Type

readPasswordback to summary
public static ByteBuf readPassword(ByteBuf simpleAuthMetadata)

Read all the remaining bytes from the given ByteBuf which represents user's password

Parameters
simpleAuthMetadata:ByteBuf

the given metadata to read password from. Please note, the simpleAuthMetadata#readIndex should be set to the beginning of the password bytes

Returns:ByteBuf

sliced ByteBuf or Unpooled#EMPTY_BUFFER if password length is zero

readPasswordAsCharArrayback to summary
public static char[] readPasswordAsCharArray(ByteBuf simpleAuthMetadata)

Read all the remaining bytes from the given ByteBuf which represents user's password

Parameters
simpleAuthMetadata:ByteBuf

the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex should be set to the beginning of the password bytes

Returns:char[]

char[] which represents UTF-8 password

readPayloadback to summary
public static ByteBuf readPayload(ByteBuf metadata)

Read all remaining bytes from the given ByteBuf and return sliced representation of a payload

Parameters
metadata:ByteBuf

metadata to get payload from. Please note, the metadata#readIndex should be set to the beginning of the payload bytes

Returns:ByteBuf

sliced ByteBuf or Unpooled#EMPTY_BUFFER if no bytes readable in the given one

readUsernameback to summary
public static ByteBuf readUsername(ByteBuf simpleAuthMetadata)

Read up to 65537 bytes from the given ByteBuf where the first two bytes represent username length and the subsequent number of bytes equal to read length

Parameters
simpleAuthMetadata:ByteBuf

the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex should be set to the username length position

Returns:ByteBuf

sliced ByteBuf or Unpooled#EMPTY_BUFFER if username length is zero

readUsernameAsCharArrayback to summary
public static char[] readUsernameAsCharArray(ByteBuf simpleAuthMetadata)

Read up to 65537 bytes from the given ByteBuf where the first two bytes represent username length and the subsequent number of bytes equal to read length

Parameters
simpleAuthMetadata:ByteBuf

the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex should be set to the username length byte

Returns:char[]

char[] which represents UTF-8 username

readUsernameLengthback to summary
private static int readUsernameLength(ByteBuf simpleAuthMetadata)
readWellKnownAuthTypeback to summary
public static WellKnownAuthType readWellKnownAuthType(ByteBuf metadata)

Read first byte from the given metadata and tries to convert it's value to WellKnownAuthType.

Parameters
metadata:ByteBuf

given metadata buffer to read from

Returns:WellKnownAuthType

Return on of the know Auth types or WellKnownAuthType#UNPARSEABLE_AUTH_TYPE if field's value is length or unknown auth type

Exceptions
IllegalStateException:
if not enough readable bytes in the given ByteBuf