/**
* Get the access token
*/
protected AccessTokenValidation getAccessTokenValidation() {
AccessTokenValidation accessTokenV = null;
if (dataProvider == null && tokenHandlers.isEmpty()) {
throw new WebApplicationException(500);
}
// Get the scheme and its data, Bearer only is supported by default
// WWW-Authenticate with the list of supported schemes will be sent back
// if the scheme is not accepted
String[] authParts = AuthorizationUtils.getAuthorizationParts(mc, supportedSchemes);
String authScheme = authParts[0];
String authSchemeData = authParts[1];
// Get the registered handler capable of processing the token
AccessTokenValidator handler = findTokenValidator(authScheme);
if (handler != null) {
try {
// Convert the HTTP Authorization scheme data into a token
accessTokenV = handler.validateAccessToken(mc, authScheme, authSchemeData);
} catch (OAuthServiceException ex) {
AuthorizationUtils.throwAuthorizationFailure(
Collections.singleton(authScheme));
}
}
// Default processing if no registered providers available
ServerAccessToken localAccessToken = null;
if (accessTokenV == null && dataProvider != null && authScheme.equals(DEFAULT_AUTH_SCHEME)) {
try {
localAccessToken = dataProvider.getAccessToken(authSchemeData);
} catch (OAuthServiceException ex) {
// to be handled next
}
if (localAccessToken == null) {
AuthorizationUtils.throwAuthorizationFailure(
Collections.singleton(authScheme));
}
accessTokenV = new AccessTokenValidation(localAccessToken);
}
if (accessTokenV == null) {
AuthorizationUtils.throwAuthorizationFailure(supportedSchemes);
}
// Check if token is still valid
if (OAuthUtils.isExpired(accessTokenV.getTokenIssuedAt(), accessTokenV.getTokenLifetime())) {
if (localAccessToken != null) {
dataProvider.removeAccessToken(localAccessToken);
}
AuthorizationUtils.throwAuthorizationFailure(supportedSchemes);
}