Skip to content

Commit

Permalink
AWS updates
Browse files Browse the repository at this point in the history
* Support custom, non-AWS, endpoint
* Simplification of oAuth code
* Remove custom S3Presigner code, this is now included in the SDK
  • Loading branch information
jrobinso committed Jan 16, 2025
1 parent e7bcd3e commit 816c97e
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 401 deletions.
41 changes: 18 additions & 23 deletions src/main/java/org/broad/igv/oauth/OAuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,13 @@ public void fetchAccessToken(String authorizationCode) throws IOException {
fetchUserProfile(payload);
}

if (authProvider != null && "Amazon".equals(authProvider)) {
// Get AWS credentials after getting relevant tokens
Credentials aws_credentials;
aws_credentials = AmazonUtils.GetCognitoAWSCredentials();

// Update S3 client with newly acquired token
AmazonUtils.updateS3Client(aws_credentials);
}


// Notify UI that we are authz'd/authn'd
if (isLoggedIn()) {
IGVEventBus.getInstance().post(new AuthStateEvent(true, this.authProvider, this.getCurrentUserName()));
}

} catch (Exception e) {
log.error(e);
e.printStackTrace();
}
}

Expand All @@ -256,7 +245,7 @@ public void setAccessToken(String accessToken) {
}

/**
* Fetch a new access token from a refresh token.
* Fetch a new access token from a refresh token. Unlike authorization, this is a synchronous operation
*
* @throws IOException
*/
Expand Down Expand Up @@ -293,18 +282,15 @@ private void refreshAccessToken() throws IOException {
expirationTime = System.currentTimeMillis() + response.getAsJsonPrimitive("expires_in").getAsInt() * 1000;
} else {
// Refresh token has failed, reauthorize from scratch
reauthorize();
logout();
try {
openAuthorizationPage();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}

private void reauthorize() throws IOException {
logout();
try {
openAuthorizationPage();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}

/**
* Extract user information from the claim information
Expand Down Expand Up @@ -374,6 +360,15 @@ public void logout() {
IGVEventBus.getInstance().post(new AuthStateEvent(false, this.authProvider, null));
}

public JsonObject getAuthorizationResponse() {

if (response == null) {
// Go back to auth flow, not auth'd yet
checkLogin();
response = getResponse();
}
return response;
}

/**
* If not logged in, attempt to login
Expand All @@ -390,10 +385,10 @@ public synchronized void checkLogin() {
}

}
// wait until authentication successful or 1 minute -
// wait until authentication successful or 2 minutes -
// dwm08
int i = 0;
while (!isLoggedIn() && i < 600) {
while (!isLoggedIn() && i < 1200) {
++i;
try {
Thread.sleep(100);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/broad/igv/track/TrackLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ public List<Track> load(ResourceLocator locator, Genome genome) throws DataLoadE

final String path = locator.getPath().trim();

// Check if the AWS credentials are still valid. If not, re-login and renew pre-signed urls
if (AmazonUtils.isAwsS3Path(path)) {
AmazonUtils.checkLogin();
}

log.info("Loading resource: " + (locator.isDataURL() ? "<data url>" : path));
try {

Expand Down
25 changes: 3 additions & 22 deletions src/main/java/org/broad/igv/ui/action/LoadFromURLMenuAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ private void loadUrls(List<String> inputs, List<String> indexes, boolean isHtsGe
} else if (inputs.size() == 1 && SessionReader.isSessionFile(inputs.getFirst())) {
// Session URL
String url = inputs.getFirst();
if (url.startsWith("s3://")) {
checkAWSAccessbility(url);
}

try {
LongRunningTask.submit(() -> this.igv.loadSession(url, null));
} catch (Exception ex) {
Expand Down Expand Up @@ -186,29 +184,12 @@ private static boolean isHubURL(String input) {

private static void checkURLs(List<String> urls) {
for (String url : urls) {
if (url.startsWith("s3://")) {
checkAWSAccessbility(url);
} else if (url.startsWith("ftp://")) {
if (url.startsWith("ftp://")) {
MessageUtils.showMessage("FTP protocol is not supported");
}
}
}

private static void checkAWSAccessbility(String url) {
try {
// If AWS support is active, check if objects are in accessible tiers via Load URL menu...
if (AmazonUtils.isAwsS3Path(url)) {
String bucket = AmazonUtils.getBucketFromS3URL(url);
String key = AmazonUtils.getKeyFromS3URL(url);
AmazonUtils.s3ObjectAccessResult res = isObjectAccessible(bucket, key);
if (!res.isObjectAvailable()) {
MessageUtils.showErrorMessage(res.getErrorReason(), null);
}
}
} catch (NullPointerException npe) {
// User has not yet done Amazon->Login sequence
AmazonUtils.checkLogin();
}
}

}

Loading

0 comments on commit 816c97e

Please sign in to comment.