public final class TokenHandler extends Object
String.format(String, Object...) with the token
as a single string argument.| Modifier and Type | Class | Description |
|---|---|---|
static class |
TokenHandler.Builder |
Fluent API builder to create
TokenHandler. |
| Modifier and Type | Method | 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. |
String |
extractToken(String tokenRawValue) |
Extracts the token from the string value of the header (or other field).
|
Optional<String> |
extractToken(Map<String,List<String>> headers) |
Extracts the token from request.
|
static TokenHandler |
forHeader(String header) |
A shortcut method to build a token handler that does not modify the token content.
|
static TokenHandler |
fromConfig(Config config) |
Create a
TokenHandler from configuration. |
String |
getTokenHeader() |
|
void |
setHeader(Map<String,List<String>> headers,
String token) |
Set the token as a new header.
|
public static TokenHandler.Builder builder()
TokenHandler.public static TokenHandler forHeader(String header)
header - header name (to read or write to)public static TokenHandler fromConfig(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 getTokenHeader()
public void setHeader(Map<String,List<String>> headers, String token)
headers - Headers to updatetoken - Token valueCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.