public interface BearerTokenService extends AppContextService<BearerTokenService>, ScopeQuery
AppContextService
that encapsulates the policy for bearer token authentication.
The model here is that bearer tokens can modify the session. Typically setting the current user.
The role session roles may also be modified to fine tune permissions for example having a token that removes
some of the users roles. Alternatively a user could not be set, with just session roles or explicit decoding of the
access token used for access control.
Normally bearer tokens will not establish a session but each request will authenticate. Different operations can then
be restricted to different scopes (with a full impersonation scope being the default requirement). Normal user permissions
will still apply but the token will only authenticate if it has at least one of the desired scopes.
Different models could be mixed in the same application provided that the tokens always inhabit different realms.Modifier and Type | Method and Description |
---|---|
ErrorCodes |
getError()
get an error to return with authentication request.
|
java.lang.String |
getRealm()
get the realm to request for bearer token authentication.
|
java.lang.String |
getToken()
get the successfully processed token.
|
default boolean |
hasToken() |
void |
processToken(SessionService sess,
java.lang.String token)
Attempt to login with the specified token.
|
boolean |
request()
Should authentication be requested or errors reported.
|
java.util.Set<java.lang.String> |
requestedScopes()
Return the scopes requested during authentication.
|
void |
setActive(boolean active)
Enable/Disable bearer token authentication for this request.
|
void |
setRealm(java.lang.String realm)
set the realm to request if bearer authorisation is requested
|
void |
setRequestable(boolean requestable)
Can we request a token via an authorization header.
|
void |
setRequiredScopes(java.lang.String[] scopes)
restrict authentication to tokens that have one of the specified scopes.
|
getType
cleanup
hasScope, hasScope
void setActive(boolean active)
active
- void setRealm(java.lang.String realm)
realm
- java.lang.String getRealm()
java.util.Set<java.lang.String> requestedScopes()
void setRequiredScopes(java.lang.String[] scopes)
scopes
- ErrorCodes getError()
processToken(SessionService, String)
has failed to validate a token.void processToken(SessionService sess, java.lang.String token)
request()
should return false after this.
If it fails then request()
should return true and getError()
may return a non-null value.
This method MUST verify the permitted scopes of the token.SessionService
- to modifytoken
- void setRequestable(boolean requestable)
requestable
- boolean request()
processToken(SessionService, String)
has successfully processed a token.
This should always return true if there is an error to report.
If this returns false then bearer authentication will not be explicitly requested but a client can still provide a
token spontaneously.
A non-empty set of requested scopes are usually required fro authorisation to be requested.java.lang.String getToken()
default boolean hasToken()