diff --git a/authentication/pom.xml b/authentication/pom.xml
index ea84309e7..418113192 100644
--- a/authentication/pom.xml
+++ b/authentication/pom.xml
@@ -139,6 +139,20 @@ SPDX-License-Identifier: Apache-2.0
11.10.1
+
+
+ org.slf4j
+ slf4j-api
+ 2.0.13
+
+
+
+
+ ch.qos.logback
+ logback-classic
+ 1.5.6
+
+
org.junit.jupiter
diff --git a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/AzureLogin.java b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/AzureLogin.java
index 4e91ed43f..dddf41c67 100644
--- a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/AzureLogin.java
+++ b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/AzureLogin.java
@@ -13,9 +13,6 @@
import java.io.IOException;
import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -38,7 +35,7 @@ public AzureLogin(String code, String redirectUrl) {
}
@Override
- public OpenIdInfo openidInfo() throws IOException, InterruptedException {
+ public OpenIdInfo openidInfo() throws IOException, InterruptedException, RsdResponseException {
Map form = createForm();
String tokenResponse = getTokensFromAzureconext(form);
String idToken = extractIdToken(tokenResponse);
@@ -61,23 +58,12 @@ private Map createForm() {
return form;
}
- private String getTokensFromAzureconext(Map form) throws IOException, InterruptedException {
+ private String getTokensFromAzureconext(Map form) throws IOException, InterruptedException, RsdResponseException {
URI tokenEndpoint = Utils.getTokenUrlFromWellKnownUrl(URI.create(Config.azureWellknown()));
- return postForm(tokenEndpoint, form);
+ return Utils.postForm(tokenEndpoint, form);
}
private String extractIdToken(String response) {
return JsonParser.parseString(response).getAsJsonObject().getAsJsonPrimitive("id_token").getAsString();
}
-
- private String postForm(URI uri, Map form) throws IOException, InterruptedException {
- HttpRequest request = Utils.formToHttpRequest(uri, form);
- try (HttpClient client = HttpClient.newHttpClient()) {
- HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
- if (response.statusCode() >= 300) {
- throw new RuntimeException("Error fetching data from " + uri.toString() + ": " + response.body());
- }
- return response.body();
- }
- }
}
diff --git a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/Config.java b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/Config.java
index 216334eb9..c0b56b167 100644
--- a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/Config.java
+++ b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/Config.java
@@ -1,6 +1,6 @@
-// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center)
-// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center
+// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2022 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
+// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 Matthias Rüster (GFZ)
// SPDX-FileCopyrightText: 2022 dv4all
@@ -21,6 +21,9 @@ public static String jwtSigningSecret() {
return System.getenv("PGRST_JWT_SECRET");
}
+ private Config() {
+ }
+
private static Collection rsdAuthCoupleProviders() {
return Optional.ofNullable(System.getenv("RSD_AUTH_COUPLE_PROVIDERS"))
.map(String::toUpperCase)
@@ -39,10 +42,10 @@ public static boolean isDevEnv() {
private static Collection rsdLoginProviders() {
return Optional.ofNullable(System.getenv("RSD_AUTH_PROVIDERS"))
- .map(String::toUpperCase)
- .map(s -> s.split(";"))
- .map(Set::of)
- .orElse(Collections.emptySet());
+ .map(String::toUpperCase)
+ .map(s -> s.split(";"))
+ .map(Set::of)
+ .orElse(Collections.emptySet());
}
public static boolean isLocalLoginEnabled() {
diff --git a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/HelmholtzIdLogin.java b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/HelmholtzIdLogin.java
index 72ed9d0f2..0da8ed0a2 100644
--- a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/HelmholtzIdLogin.java
+++ b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/HelmholtzIdLogin.java
@@ -1,6 +1,6 @@
-// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center)
-// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center
+// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2022 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
+// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Matthias Rüster (GFZ)
// SPDX-FileCopyrightText: 2023 - 2024 Christian Meeßen (GFZ)
//
@@ -50,7 +50,7 @@ public class HelmholtzIdLogin implements Login {
static final String DEFAULT_ORGANISATION = "Helmholtz";
// See https://hifis.net/doc/helmholtz-aai/list-of-vos/#vos-representing-helmholtz-centres
- static private final Collection knownHgfOrganisations = Set.of(
+ private static final Collection knownHgfOrganisations = Set.of(
"AWI", "CISPA", "DESY", "DKFZ", "DLR", "DZNE", "FZJ", "GEOMAR", "GFZ", "GSI", "hereon", "HMGU", "HZB", "KIT", "MDC", "UFZ"
);
@@ -198,8 +198,8 @@ public OpenIdInfo openidInfo() throws IOException, InterruptedException {
JSONArray entitlements = new JSONArray();
Object edupersonClaim = userInfo.getClaim("eduperson_entitlement");
- if (edupersonClaim instanceof JSONArray) {
- entitlements = (JSONArray) edupersonClaim;
+ if (edupersonClaim instanceof JSONArray jsonArray) {
+ entitlements = jsonArray;
} else if (edupersonClaim instanceof String) {
entitlements.appendElement(edupersonClaim);
} else if (edupersonClaim == null) {
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 c600a3379..56d3ad08a 100644
--- a/authentication/src/main/java/nl/esciencecenter/rsd/authentication/JwtCreator.java
+++ b/authentication/src/main/java/nl/esciencecenter/rsd/authentication/JwtCreator.java
@@ -1,5 +1,5 @@
-// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center)
-// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center
+// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center)
+// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 dv4all
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ)
@@ -25,29 +25,29 @@ public class JwtCreator {
private final Algorithm signingAlgorithm;
public JwtCreator(String signingSecret) {
- signingSecret = Objects.requireNonNull(signingSecret);
+ Objects.requireNonNull(signingSecret);
this.signingSecret = signingSecret;
this.signingAlgorithm = Algorithm.HMAC256(this.signingSecret);
}
String createUserJwt(AccountInfo accountInfo) {
return JWT.create()
- .withClaim("iss", "rsd_auth")
- .withClaim("role", accountInfo.isAdmin() ? "rsd_admin" : "rsd_user")
- .withClaim("account", accountInfo.account().toString())
- .withClaim("name", accountInfo.name())
- .withClaim("data", accountInfo.data())
- .withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS))
- .sign(signingAlgorithm);
+ .withClaim("iss", "rsd_auth")
+ .withClaim("role", accountInfo.isAdmin() ? "rsd_admin" : "rsd_user")
+ .withClaim("account", accountInfo.account().toString())
+ .withClaim("name", accountInfo.name())
+ .withClaim("data", accountInfo.data())
+ .withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS))
+ .sign(signingAlgorithm);
}
String createAdminJwt() {
return JWT.create()
- .withClaim("iss", "rsd_auth")
- .withClaim("role", "rsd_admin")
- .withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS))
- .sign(signingAlgorithm);
+ .withClaim("iss", "rsd_auth")
+ .withClaim("role", "rsd_admin")
+ .withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS))
+ .sign(signingAlgorithm);
}
String refreshToken(String token) {
@@ -55,10 +55,10 @@ String refreshToken(String token) {
String payloadEncoded = oldJwt.getPayload();
String payloadDecoded = Main.decode(payloadEncoded);
Gson gson = new Gson();
- Map claimsMap = gson.fromJson(payloadDecoded, Map.class);
+ Map claimsMap = gson.