-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authentication to remote data sources
Allow remote data ingestion to perform basic and bearer authentication.
- Loading branch information
Showing
9 changed files
with
211 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
* Allow HTTP authentication for `-remote` input format sources |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/ca/on/oicr/gsi/shesmu/plugin/authentication/AuthenticationConfiguration.java
This file contains 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,29 @@ | ||
package ca.on.oicr.gsi.shesmu.plugin.authentication; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import java.io.IOException; | ||
import java.net.http.HttpRequest.Builder; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = AuthenticationConfigurationBasic.class, name = "basic"), | ||
@JsonSubTypes.Type(value = AuthenticationConfigurationBearer.class, name = "bearer"), | ||
@JsonSubTypes.Type(value = AuthenticationConfigurationFileBasic.class, name = "basic-file"), | ||
@JsonSubTypes.Type(value = AuthenticationConfigurationFileBearer.class, name = "bearer-file") | ||
}) | ||
public abstract sealed class AuthenticationConfiguration | ||
permits AuthenticationConfigurationBasic, | ||
AuthenticationConfigurationBearer, | ||
AuthenticationConfigurationFileBasic, | ||
AuthenticationConfigurationFileBearer { | ||
|
||
public static void addAuthenticationHeader( | ||
AuthenticationConfiguration authentication, Builder request) throws IOException { | ||
if (authentication != null) { | ||
request.header("Authorization", authentication.prepareAuthentication()); | ||
} | ||
} | ||
|
||
public abstract String prepareAuthentication() throws IOException; | ||
} |
36 changes: 36 additions & 0 deletions
36
...in/java/ca/on/oicr/gsi/shesmu/plugin/authentication/AuthenticationConfigurationBasic.java
This file contains 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,36 @@ | ||
package ca.on.oicr.gsi.shesmu.plugin.authentication; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
|
||
public final class AuthenticationConfigurationBasic extends AuthenticationConfiguration { | ||
public static String makeHeader(String username, String password) { | ||
return "Basic " | ||
+ Base64.getEncoder() | ||
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
private String password; | ||
private String username; | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
@Override | ||
public String prepareAuthentication() { | ||
return makeHeader(username, password); | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...n/java/ca/on/oicr/gsi/shesmu/plugin/authentication/AuthenticationConfigurationBearer.java
This file contains 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,20 @@ | ||
package ca.on.oicr.gsi.shesmu.plugin.authentication; | ||
|
||
import java.io.IOException; | ||
|
||
public final class AuthenticationConfigurationBearer extends AuthenticationConfiguration { | ||
private String token; | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
@Override | ||
public String prepareAuthentication() throws IOException { | ||
return "Bearer " + token; | ||
} | ||
|
||
public void setToken(String token) { | ||
this.token = token; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ava/ca/on/oicr/gsi/shesmu/plugin/authentication/AuthenticationConfigurationFileBasic.java
This file contains 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,32 @@ | ||
package ca.on.oicr.gsi.shesmu.plugin.authentication; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public final class AuthenticationConfigurationFileBasic extends AuthenticationConfiguration { | ||
private String passwordFile; | ||
private String username; | ||
|
||
public String getPasswordFile() { | ||
return passwordFile; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
@Override | ||
public String prepareAuthentication() throws IOException { | ||
return AuthenticationConfigurationBasic.makeHeader( | ||
username, Files.readString(Paths.get(passwordFile)).trim()); | ||
} | ||
|
||
public void setPasswordFile(String passwordFile) { | ||
this.passwordFile = passwordFile; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...va/ca/on/oicr/gsi/shesmu/plugin/authentication/AuthenticationConfigurationFileBearer.java
This file contains 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,22 @@ | ||
package ca.on.oicr.gsi.shesmu.plugin.authentication; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public final class AuthenticationConfigurationFileBearer extends AuthenticationConfiguration { | ||
private String tokenFile; | ||
|
||
public String getTokenFile() { | ||
return tokenFile; | ||
} | ||
|
||
@Override | ||
public String prepareAuthentication() throws IOException { | ||
return "Bearer " + Files.readString(Paths.get(tokenFile)).trim(); | ||
} | ||
|
||
public void setTokenFile(String tokenFile) { | ||
this.tokenFile = tokenFile; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
shesmu-pluginapi/src/main/java/ca/on/oicr/gsi/shesmu/plugin/authentication/package-info.java
This file contains 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,2 @@ | ||
/** Utilities for configuring HTTP authentication in configuration files */ | ||
package ca.on.oicr.gsi.shesmu.plugin.authentication; |
This file contains 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