-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement SonarCloud suggestions
- Loading branch information
1 parent
0b7397a
commit 645bf66
Showing
30 changed files
with
269 additions
and
218 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// 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) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 dv4all | ||
|
@@ -21,6 +21,9 @@ public static String jwtSigningSecret() { | |
return System.getenv("PGRST_JWT_SECRET"); | ||
} | ||
|
||
private Config() { | ||
} | ||
|
||
private static Collection<String> rsdAuthCoupleProviders() { | ||
return Optional.ofNullable(System.getenv("RSD_AUTH_COUPLE_PROVIDERS")) | ||
.map(String::toUpperCase) | ||
|
@@ -39,10 +42,10 @@ public static boolean isDevEnv() { | |
|
||
private static Collection<String> 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() { | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// 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) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// | ||
|
@@ -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<String> knownHgfOrganisations = Set.of( | ||
private static final Collection<String> 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) { | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2022 dv4all | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
|
@@ -25,40 +25,40 @@ 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) { | ||
DecodedJWT oldJwt = JWT.decode(token); | ||
String payloadEncoded = oldJwt.getPayload(); | ||
String payloadDecoded = Main.decode(payloadEncoded); | ||
Gson gson = new Gson(); | ||
Map claimsMap = gson.fromJson(payloadDecoded, Map.class); | ||
Map<String, ?> claimsMap = gson.<Map<String, ?>>fromJson(payloadDecoded, Map.class); | ||
return JWT.create() | ||
.withPayload(claimsMap) | ||
.withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS)) | ||
.sign(signingAlgorithm); | ||
.withPayload(claimsMap) | ||
.withExpiresAt(new Date(System.currentTimeMillis() + ONE_HOUR_IN_MILLISECONDS)) | ||
.sign(signingAlgorithm); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2021 - 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2021 - 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2021 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2021 - 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -9,5 +9,5 @@ | |
|
||
public interface Login { | ||
|
||
OpenIdInfo openidInfo() throws IOException, InterruptedException; | ||
OpenIdInfo openidInfo() throws IOException, InterruptedException, RsdResponseException; | ||
} |
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
Oops, something went wrong.