public final class TokenHandler extends Object
String.format(String, Object...) with the token
as a single string argument.| Modifier and Type | Class and Description |
|---|---|
static class |
TokenHandler.Builder
Fluent API builder to create
TokenHandler. |
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(Map<String,List<String>> headers,
String token)
Add the token as a new header value.
|
static TokenHandler.Builder |
builder()
Fluent API builder to create
TokenHandler. |
static TokenHandler |
create(Config config)
Create a
TokenHandler from configuration. |
Optional<String> |
extractToken(Map<String,List<String>> headers)
Extracts the token from request.
|
String |
extractToken(String tokenRawValue)
Extracts the token from the string value of the header (or other field).
|
static TokenHandler |
forHeader(String header)
A shortcut method to build a token handler that does not modify the token content.
|
void |
header(Map<String,List<String>> headers,
String token)
Set the token as a new header.
|
String |
tokenHeader()
Name of the header the token is expected in (or will be written into).
|
public static TokenHandler.Builder builder()
TokenHandler.public static TokenHandler forHeader(String header)
header - header name (to read or write to)public static TokenHandler create(Config config)
TokenHandler from configuration.
Expected configuration (to be located on token key):
token {
header = "Authorization"
# or do not specify - then the whole header is considered to be the token value
prefix = "bearer "
# optional alternative - looking for first matching group
#regexp = "bearer (.*)"
}
config - config to parse into an instance of this objectpublic Optional<String> extractToken(Map<String,List<String>> headers)
headers - Headers to extract token fromSecurityException - in case the token data is malformedpublic String extractToken(String tokenRawValue)
tokenRawValue - such as "bearer AAAAAAA"public String tokenHeader()
public void header(Map<String,List<String>> headers, String token)
headers - Headers to updatetoken - Token valueCopyright © 2018–2019 Oracle Corporation. All rights reserved.