-
Notifications
You must be signed in to change notification settings - Fork 150
Remove javaxb dependency from HMACValidator #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| * | ||
| * Adyen Java API Library | ||
| * | ||
| * Copyright (c) 2017 Adyen B.V. | ||
| * Copyright (c) 2026 Adyen B.V. | ||
| * This file is open source and available under the MIT license. | ||
| * See the LICENSE file for more info. | ||
| */ | ||
|
|
@@ -31,8 +31,9 @@ | |
| import java.util.List; | ||
| import javax.crypto.Mac; | ||
| import javax.crypto.spec.SecretKeySpec; | ||
| import javax.xml.bind.DatatypeConverter; | ||
| import org.apache.commons.codec.DecoderException; | ||
| import org.apache.commons.codec.binary.Base64; | ||
| import org.apache.commons.codec.binary.Hex; | ||
|
|
||
| /** Utility class for generating and validating HMAC signatures used in Adyen webhooks. */ | ||
| public class HMACValidator { | ||
|
|
@@ -48,7 +49,7 @@ public class HMACValidator { | |
| * @param data the data to sign | ||
| * @param key the HMAC key in hexadecimal format | ||
| * @return the Base64-encoded HMAC signature | ||
| * @throws IllegalArgumentException if the data or key is null | ||
| * @throws IllegalArgumentException if the data or key is null or if key is invalid | ||
| * @throws SignatureException if signature generation fails | ||
| */ | ||
| public String calculateHMAC(String data, String key) | ||
|
|
@@ -61,7 +62,7 @@ public String calculateHMAC(String data, String key) | |
| throw new IllegalArgumentException("HMAC key is not provided"); | ||
| } | ||
|
|
||
| byte[] rawKey = DatatypeConverter.parseHexBinary(key); | ||
| byte[] rawKey = Hex.decodeHex(key); | ||
jeandersonbc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SecretKeySpec signingKey = new SecretKeySpec(rawKey, HMAC_SHA256_ALGORITHM); | ||
|
|
||
| Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM); | ||
|
|
@@ -71,6 +72,8 @@ public String calculateHMAC(String data, String key) | |
| return new String(Base64.encodeBase64(rawHmac)); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException("Missing data or key: " + e.getMessage()); | ||
| } catch (DecoderException e) { | ||
| throw new IllegalArgumentException("Invalid Hex HMAC key: " + key); | ||
|
Comment on lines
+75
to
+76
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added suggestion from @gcatanese |
||
| } catch (Exception e) { | ||
| throw new SignatureException("Failed to generate HMAC: " + e.getMessage()); | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just noticing this, but why do we have
gsonandjacksonin the same project?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GSON only used by the TerminalAPI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm also curious about this. We do use it for serialization and deserialization in a few places (
.toJson/.fromJson):I think as part of the bigger migration, we want to stick with a single JSON library.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered my own question 😅
This library uses both serialization stacks for historical and compatibility reasons:
• Jackson is used broadly by the generated API models (com.adyen.model.*.JSON classes with ObjectMapper).
• Gson is still used in specific flows, especially Terminal API and webhook notification helpers (for example TerminalCloudAPI and NotificationRequest#fromJson/toJson).
Edit: forgot to refresh 😆