String clientMacString) {
String macKey = macAuthInfo.getMacKey();
ServerAccessToken accessToken = dataProvider.getAccessToken(macKey);
if (!(accessToken instanceof MacAccessToken)) {
throw new OAuthServiceException(OAuthConstants.SERVER_ERROR);
}
MacAccessToken macAccessToken = (MacAccessToken)accessToken;
String normalizedString = macAuthInfo.getNormalizedRequestString();
try {
HmacAlgorithm hmacAlgo = HmacAlgorithm.toHmacAlgorithm(macAccessToken.getMacAlgorithm());
byte[] serverMacData = HmacUtils.computeHmac(
macAccessToken.getMacKey(), hmacAlgo, normalizedString);
byte[] clientMacData = Base64Utility.decode(clientMacString);
boolean validMac = Arrays.equals(serverMacData, clientMacData);
if (!validMac) {
AuthorizationUtils.throwAuthorizationFailure(Collections
.singleton(OAuthConstants.MAC_AUTHORIZATION_SCHEME));
}
} catch (Base64Exception e) {
throw new OAuthServiceException(OAuthConstants.SERVER_ERROR, e);
}
return macAccessToken;
}