diff --git a/authentication/README.md b/authentication/README.md
index 3324e8fd5..ee4192b49 100644
--- a/authentication/README.md
+++ b/authentication/README.md
@@ -28,7 +28,8 @@ extra_hosts:
- "host.docker.internal:host-gateway"
```
2. In `nginx.conf`, replace `server auth:7000;` with `server host.docker.internal:7000;`
-3. (Optionally) allow TCP traffic on port 7000 of your firewall if logging in seems to hang forever or if you get `504 Gateway Timeout` responses.
+3. (Optional) For refreshing your tokens to work, set `RSD_AUTH_URL=http://nginx/auth` in your `.env`.
+4. (Optional) Allow TCP traffic on port 7000 of your firewall if signing in seems to hang forever or if you get `504 Gateway Timeout` responses.
Remember to undo these changes before committing!
diff --git a/authentication/pom.xml b/authentication/pom.xml
index 418113192..82be58ade 100644
--- a/authentication/pom.xml
+++ b/authentication/pom.xml
@@ -34,7 +34,7 @@ SPDX-License-Identifier: Apache-2.0
org.apache.maven.plugins
maven-dependency-plugin
- 3.7.1
+ 3.8.1
@@ -101,21 +101,21 @@ SPDX-License-Identifier: Apache-2.0
io.javalin
javalin
- 6.2.0
+ 6.3.0
org.jetbrains
annotations
- 24.1.0
+ 26.0.1
org.slf4j
slf4j-simple
- 2.0.13
+ 2.0.16
@@ -143,14 +143,14 @@ SPDX-License-Identifier: Apache-2.0
org.slf4j
slf4j-api
- 2.0.13
+ 2.0.16
ch.qos.logback
logback-classic
- 1.5.6
+ 1.5.12
diff --git a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/JwtCreator.java b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/JwtCreator.java
index 56d3ad08a..a200d81f6 100644
--- a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/JwtCreator.java
+++ b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/JwtCreator.java
@@ -14,26 +14,28 @@
import com.auth0.jwt.interfaces.DecodedJWT;
import com.google.gson.Gson;
+import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
+import java.util.UUID;
public class JwtCreator {
static final long ONE_HOUR_IN_MILLISECONDS = 3600_000L; // 60 * 60 * 1000
- private final String signingSecret;
private final Algorithm signingAlgorithm;
+ private static final String RSD_ADMIN_ROLE = "rsd_admin";
+ private static final String RSD_USER_ROLE = "rsd_user";
public JwtCreator(String signingSecret) {
Objects.requireNonNull(signingSecret);
- this.signingSecret = signingSecret;
- this.signingAlgorithm = Algorithm.HMAC256(this.signingSecret);
+ this.signingAlgorithm = Algorithm.HMAC256(signingSecret);
}
String createUserJwt(AccountInfo accountInfo) {
return JWT.create()
.withClaim("iss", "rsd_auth")
- .withClaim("role", accountInfo.isAdmin() ? "rsd_admin" : "rsd_user")
+ .withClaim("role", accountInfo.isAdmin() ? RSD_ADMIN_ROLE : RSD_USER_ROLE)
.withClaim("account", accountInfo.account().toString())
.withClaim("name", accountInfo.name())
.withClaim("data", accountInfo.data())
@@ -45,19 +47,22 @@ String createUserJwt(AccountInfo accountInfo) {
String createAdminJwt() {
return JWT.create()
.withClaim("iss", "rsd_auth")
- .withClaim("role", "rsd_admin")
+ .withClaim("role", RSD_ADMIN_ROLE)
.withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS))
.sign(signingAlgorithm);
}
- String refreshToken(String token) {
+ String refreshToken(String token) throws IOException, InterruptedException {
DecodedJWT oldJwt = JWT.decode(token);
+ UUID accountId = UUID.fromString(oldJwt.getClaim("account").asString());
+ boolean isAdmin = PostgrestAccount.isAdmin(accountId);
String payloadEncoded = oldJwt.getPayload();
String payloadDecoded = Main.decode(payloadEncoded);
Gson gson = new Gson();
Map claimsMap = gson.