-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple installations, provide JWT via environment
- Loading branch information
Showing
15 changed files
with
162 additions
and
73 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
12 changes: 12 additions & 0 deletions
12
src/main/java/de/antragsgruen/live/multisite/AntragsgruenInstallation.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,12 @@ | ||
package de.antragsgruen.live.multisite; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class AntragsgruenInstallation { | ||
private final String installationId; | ||
|
||
private final AntragsgruenJwtDecoder jwtDecoder; | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/de/antragsgruen/live/multisite/AntragsgruenInstallationProvider.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,62 @@ | ||
package de.antragsgruen.live.multisite; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
import java.security.spec.InvalidKeySpecException; | ||
import java.util.HashMap; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class AntragsgruenInstallationProvider { | ||
private final Environment environment; | ||
private final HashMap<String, AntragsgruenInstallation> installations = new HashMap<>(); | ||
|
||
public AntragsgruenInstallation getInstallation(String installationId) throws InstallationNotFoundException { | ||
if (!installations.containsKey(installationId)) { | ||
throw new InstallationNotFoundException("Invalid installation id: " + installationId); | ||
} | ||
|
||
return installations.get(installationId); | ||
} | ||
|
||
@PostConstruct | ||
public void onInit() { | ||
String installationId; | ||
String publicKey; | ||
int count = 0; | ||
do { | ||
installationId = environment.getProperty("antragsgruen.installations." + count + ".id"); | ||
publicKey = environment.getProperty("antragsgruen.installations." + count + ".public-key"); | ||
|
||
if (installationId == null && publicKey == null) { | ||
return; | ||
} | ||
if (installationId == null || publicKey == null || installationId.isEmpty() || publicKey.isEmpty()) { | ||
throw new RuntimeException("ANTRAGSGRUEN_INSTALLATION_" + count + "_* is inconsistently filled"); | ||
} | ||
|
||
try { | ||
this.installations.put(installationId, AntragsgruenInstallationProvider.createInstallation(installationId, publicKey)); | ||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) { | ||
throw new RuntimeException(e); | ||
} | ||
log.info("Found installation ID: " + installationId); | ||
|
||
count++; | ||
} while (true); | ||
} | ||
|
||
private static AntragsgruenInstallation createInstallation(String installationId, String publicKey) | ||
throws NoSuchAlgorithmException, InvalidKeySpecException { | ||
return new AntragsgruenInstallation( | ||
installationId, | ||
AntragsgruenJwtDecoder.create(publicKey) | ||
); | ||
} | ||
} |
33 changes: 10 additions & 23 deletions
33
...ive/websocket/AntragsgruenJwtDecoder.java → ...ive/multisite/AntragsgruenJwtDecoder.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
7 changes: 7 additions & 0 deletions
7
src/main/java/de/antragsgruen/live/multisite/InstallationNotFoundException.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,7 @@ | ||
package de.antragsgruen.live.multisite; | ||
|
||
public class InstallationNotFoundException extends Exception { | ||
public InstallationNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/de/antragsgruen/live/multisite/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,6 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package de.antragsgruen.live.multisite; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
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
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 |
---|---|---|
|
@@ -5,9 +5,6 @@ | |
}, | ||
{ | ||
"pattern": "^stomp\\.umd\\.min\\.js$" | ||
}, | ||
{ | ||
"pattern": "^public\\.key$" | ||
} | ||
] | ||
} |
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.