-
Notifications
You must be signed in to change notification settings - Fork 265
Support artifact listing in new ICP #4457
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
Draft
Dilhasha
wants to merge
1
commit into
wso2:master
Choose a base branch
from
Dilhasha:icp2-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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
56 changes: 56 additions & 0 deletions
56
.../src/main/java/org/wso2/micro/integrator/initializer/dashboard/HMACJWTTokenGenerator.java
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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package org.wso2.micro.integrator.initializer.dashboard; | ||
|
|
||
| import com.nimbusds.jose.JOSEException; | ||
| import com.nimbusds.jose.JWSAlgorithm; | ||
| import com.nimbusds.jose.JWSHeader; | ||
| import com.nimbusds.jose.JWSSigner; | ||
| import com.nimbusds.jose.crypto.MACSigner; | ||
| import com.nimbusds.jwt.JWTClaimsSet; | ||
| import com.nimbusds.jwt.SignedJWT; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Date; | ||
|
|
||
| public class HMACJWTTokenGenerator { | ||
|
|
||
| private final String hmacSecret; | ||
|
|
||
| public HMACJWTTokenGenerator(String hmacSecret) { | ||
| if (hmacSecret == null || hmacSecret.getBytes(StandardCharsets.UTF_8).length < 32) { | ||
| throw new IllegalArgumentException("HMAC secret must be at least 256 bits (32 bytes)"); | ||
| } | ||
| this.hmacSecret = hmacSecret; | ||
| } | ||
|
|
||
| /** | ||
| * Generate JWT Token with HMAC SHA256 | ||
| */ | ||
| public String generateToken(String issuer, String audience, String scope, long expiryTimeSeconds) | ||
| throws JOSEException { | ||
|
|
||
| // Calculate expiry | ||
| long expiryMillis = System.currentTimeMillis() + (expiryTimeSeconds * 1000); | ||
|
|
||
| // Build claims | ||
| JWTClaimsSet claimsSet = new JWTClaimsSet.Builder() | ||
| .issuer(issuer) | ||
| .audience(audience) | ||
| .expirationTime(new Date(expiryMillis)) | ||
| .issueTime(new Date()) | ||
| .claim("scope", scope) | ||
| .build(); | ||
|
|
||
| // Create HMAC signer | ||
| JWSSigner signer = new MACSigner(hmacSecret.getBytes(StandardCharsets.UTF_8)); | ||
|
|
||
| // Create and sign JWT | ||
| SignedJWT signedJWT = new SignedJWT( | ||
| new JWSHeader.Builder(JWSAlgorithm.HS256).build(), | ||
| claimsSet | ||
| ); | ||
|
|
||
| signedJWT.sign(signer); | ||
| return signedJWT.serialize(); | ||
| } | ||
|
|
||
| } |
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,9 +17,9 @@ | |||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| package org.wso2.micro.integrator.initializer.dashboard; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import com.google.gson.Gson; | ||||||||||||||||||||||||||||
| import com.google.gson.JsonObject; | ||||||||||||||||||||||||||||
| import com.google.gson.JsonParseException; | ||||||||||||||||||||||||||||
| import com.google.gson.JsonParser; | ||||||||||||||||||||||||||||
| import org.apache.commons.logging.Log; | ||||||||||||||||||||||||||||
| import org.apache.commons.logging.LogFactory; | ||||||||||||||||||||||||||||
| import org.apache.http.HttpEntity; | ||||||||||||||||||||||||||||
|
|
@@ -71,7 +71,13 @@ private HeartBeatComponent(){ | |||||||||||||||||||||||||||
| private static final Map<String, Object> configs = ConfigParser.getParsedConfigs(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public static void invokeHeartbeatExecutorService() { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Check if new ICP is configured | ||||||||||||||||||||||||||||
| if (ICPHeartBeatComponent.isICPConfigured()) { | ||||||||||||||||||||||||||||
| log.info("New ICP configuration detected. Starting ICP heartbeat service."); | ||||||||||||||||||||||||||||
| ICPHeartBeatComponent.invokeICPHeartbeatExecutorService(); | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| // Fall back to old dashboard heartbeat | ||||||||||||||||||||||||||||
| String heartbeatApiUrl = configs.get(DASHBOARD_CONFIG_URL) + "/heartbeat"; | ||||||||||||||||||||||||||||
| String groupId = getGroupId(); | ||||||||||||||||||||||||||||
| String nodeId = getNodeId(); | ||||||||||||||||||||||||||||
|
|
@@ -174,14 +180,16 @@ private static String generateRandomId() { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public static boolean isDashboardConfigured() { | ||||||||||||||||||||||||||||
| return configs.get(DASHBOARD_CONFIG_URL) != null; | ||||||||||||||||||||||||||||
| // Check for either old dashboard config or new ICP config | ||||||||||||||||||||||||||||
| return configs.get(DASHBOARD_CONFIG_URL) != null || ICPHeartBeatComponent.isICPConfigured(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public static JsonObject getJsonResponse(CloseableHttpResponse response) { | ||||||||||||||||||||||||||||
| String stringResponse = getStringResponse(response); | ||||||||||||||||||||||||||||
| JsonObject responseObject = null; | ||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| responseObject = new JsonParser().parse(stringResponse).getAsJsonObject(); | ||||||||||||||||||||||||||||
| Gson gson = new Gson(); | ||||||||||||||||||||||||||||
| responseObject = gson.fromJson(stringResponse, JsonObject.class); | ||||||||||||||||||||||||||||
|
Comment on lines
188
to
+192
Contributor
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. Log Improvement Suggestion No: 2
Suggested change
|
||||||||||||||||||||||||||||
| } catch (JsonParseException e) { | ||||||||||||||||||||||||||||
| log.debug("Error occurred while parsing the heartbeat response.", e); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
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.
Log Improvement Suggestion No: 1