public class AuthMetadataCodec extends Object
Modifier and Type | Method and Description |
---|---|
static ByteBuf |
encodeBearerMetadata(ByteBufAllocator allocator,
char[] token)
Encode a Authentication CompositeMetadata payload using Bearer Authentication format
|
static ByteBuf |
encodeMetadata(ByteBufAllocator allocator,
String customAuthType,
ByteBuf metadata)
Encode a Authentication CompositeMetadata payload using custom authentication type
|
static ByteBuf |
encodeMetadata(ByteBufAllocator allocator,
WellKnownAuthType authType,
ByteBuf metadata)
Encode a Authentication CompositeMetadata payload using custom authentication type
|
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). |
static ByteBuf |
encodeSimpleMetadata(ByteBufAllocator allocator,
char[] username,
char[] password)
Encode a Authentication CompositeMetadata payload using Simple Authentication format
|
static boolean |
isWellKnownAuthType(ByteBuf metadata)
|
static char[] |
readBearerTokenAsCharArray(ByteBuf bearerAuthMetadata)
Read all the remaining
bytes from the given ByteBuf |
static CharSequence |
readCustomAuthType(ByteBuf metadata)
Read up to 129 bytes from the given metadata in order to get the custom Auth Type
|
static ByteBuf |
readPassword(ByteBuf simpleAuthMetadata)
Read all the remaining
byte s from the given ByteBuf which represents user's
password |
static char[] |
readPasswordAsCharArray(ByteBuf simpleAuthMetadata)
Read all the remaining
byte s from the given ByteBuf which represents user's
password |
static ByteBuf |
readPayload(ByteBuf metadata)
Read all remaining
bytes from the given ByteBuf and return sliced
representation of a payload |
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 |
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 |
static WellKnownAuthType |
readWellKnownAuthType(ByteBuf metadata)
Read first byte from the given
metadata and tries to convert it's value to WellKnownAuthType . |
public static ByteBuf encodeMetadata(ByteBufAllocator allocator, String customAuthType, ByteBuf metadata)
allocator
- the ByteBufAllocator
to use to create intermediate buffers as needed.customAuthType
- the custom mime type to encode.metadata
- the metadata value to encode.IllegalArgumentException
- in case of customAuthType
is non US_ASCII string or
empty string or its length is greater than 128 bytespublic static ByteBuf encodeMetadata(ByteBufAllocator allocator, WellKnownAuthType authType, ByteBuf metadata)
allocator
- the ByteBufAllocator
to create intermediate buffers as needed.authType
- the well-known mime type to encode.metadata
- the metadata value to encode.IllegalArgumentException
- in case of authType
is WellKnownAuthType.UNPARSEABLE_AUTH_TYPE
or WellKnownAuthType.UNKNOWN_RESERVED_AUTH_TYPE
public static ByteBuf encodeSimpleMetadata(ByteBufAllocator allocator, char[] username, char[] password)
allocator
- the ByteBufAllocator
to use to create intermediate buffers as needed.username
- the char sequence which represents user name.password
- the char sequence which represents user password.IllegalArgumentException
- if the username length is greater than 65535public static ByteBuf encodeBearerMetadata(ByteBufAllocator allocator, char[] token)
allocator
- the ByteBufAllocator
to use to create intermediate buffers as needed.token
- the char sequence which represents BEARER token.public static ByteBuf encodeMetadataWithCompression(ByteBufAllocator allocator, String authType, ByteBuf metadata)
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
.
allocator
- the ByteBufAllocator
to use to create intermediate buffers as needed.authType
- the mime type to encode, as a String
. well known mime types are
compressed.metadata
- the metadata value to encode.encodeMetadata(ByteBufAllocator, WellKnownAuthType, ByteBuf)
,
encodeMetadata(ByteBufAllocator, String, ByteBuf)
public static boolean isWellKnownAuthType(ByteBuf metadata)
byte
from a ByteBuf
and check whether it is length or WellKnownAuthType
. Assuming said buffer properly contains such a byte
metadata
- byteBuf used to get information frompublic static WellKnownAuthType readWellKnownAuthType(ByteBuf metadata)
metadata
and tries to convert it's value to WellKnownAuthType
.metadata
- given metadata buffer to read fromWellKnownAuthType.UNPARSEABLE_AUTH_TYPE
if
field's value is length or unknown auth typeIllegalStateException
- if not enough readable bytes in the given ByteBuf
public static CharSequence readCustomAuthType(ByteBuf metadata)
metadata
- public static ByteBuf readPayload(ByteBuf metadata)
bytes
from the given ByteBuf
and return sliced
representation of a payloadmetadata
- metadata to get payload from. Please note, the metadata#readIndex
should be set to the beginning of the payload bytesByteBuf
or Unpooled.EMPTY_BUFFER
if no bytes readable in the
given onepublic static ByteBuf readUsername(ByteBuf simpleAuthMetadata)
bytes
from the given ByteBuf
where the first two bytes
represent username length and the subsequent number of bytes equal to read lengthsimpleAuthMetadata
- the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex
should be set to the username length positionByteBuf
or Unpooled.EMPTY_BUFFER
if username length is zeropublic static ByteBuf readPassword(ByteBuf simpleAuthMetadata)
byte
s from the given ByteBuf
which represents user's
passwordsimpleAuthMetadata
- the given metadata to read password from. Please note, the simpleAuthMetadata#readIndex
should be set to the beginning of the password bytesByteBuf
or Unpooled.EMPTY_BUFFER
if password length is zeropublic static char[] readUsernameAsCharArray(ByteBuf simpleAuthMetadata)
bytes
from the given ByteBuf
where the first two bytes
represent username length and the subsequent number of bytes equal to read lengthsimpleAuthMetadata
- the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex
should be set to the username length bytechar[]
which represents UTF-8 usernamepublic static char[] readPasswordAsCharArray(ByteBuf simpleAuthMetadata)
byte
s from the given ByteBuf
which represents user's
passwordsimpleAuthMetadata
- the given metadata to read username from. Please note, the simpleAuthMetadata#readIndex
should be set to the beginning of the password byteschar[]
which represents UTF-8 passwordpublic static char[] readBearerTokenAsCharArray(ByteBuf bearerAuthMetadata)
bytes
from the given ByteBuf
bearerAuthMetadata
- the given metadata to read username from. Please note, the bearerAuthMetadata#readIndex
should be set to the beginning of the password byteschar[]
which represents UTF-8 password