5
0
mirror of https://github.com/AJMicke/KickerELO.git synced 2026-03-11 13:31:02 +01:00

Fix reviews

This commit is contained in:
2025-06-12 17:48:55 +02:00
parent 5df6605bef
commit ebb6a8cae6

View File

@@ -27,26 +27,46 @@ public class AdminView extends VerticalLayout {
// Methode zum Prüfen, ob das "test"-Profil aktiv ist // Methode zum Prüfen, ob das "test"-Profil aktiv ist
private boolean isTestProfileActive() { private boolean isTestProfileActive() {
for (String profile : environment.getActiveProfiles()) { for (String profile : environment.getActiveProfiles()) {
System.out.println("Active profile: " + profile); if ("test".equals(profile)) {
if ("prod".equals(profile)) {
return true; return true;
} }
} }
return false; return false;
} }
public void beforeEnter(BeforeEnterEvent event) { private boolean isAuthentikated() {
if (!isTestProfileActive()) { Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.getPrincipal() instanceof OidcUser oidcUser) {
if (auth == null || !(auth.getPrincipal() instanceof OidcUser oidcUser)) { Object groupsObj = oidcUser.getClaims().getOrDefault("groups", List.of());
event.rerouteTo(""); List<String> listOfGroups;
return; if (groupsObj instanceof List<?> groupsList) {
listOfGroups = groupsList.stream()
.filter(String.class::isInstance)
.map(String.class::cast)
.toList();
} else {
listOfGroups = List.of();
} }
var groups = oidcUser.getClaimAsStringList("groups"); return listOfGroups.contains("Kicker Admin");
if (groups == null || !groups.contains("Kicker Admin")) { } else {
event.rerouteTo(""); return false;
} }
}
public void beforeEnter(BeforeEnterEvent event) {
if (isTestProfileActive()) {
return; // Skip authentication check in test profile
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth == null || !(auth.getPrincipal() instanceof OidcUser oidcUser)) {
event.rerouteTo("");
return;
}
var groups = oidcUser.getClaimAsStringList("groups");
if (groups == null || !groups.contains("Kicker Admin")) {
event.rerouteTo("");
} }
} }
@@ -54,30 +74,7 @@ public class AdminView extends VerticalLayout {
this.environment = environment; this.environment = environment;
if (!isTestProfileActive()) { if (!isTestProfileActive()) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (!isAuthentikated()) {
if (auth != null && auth.getPrincipal() instanceof OidcUser oidcUser) {
String username = oidcUser.getPreferredUsername();
Object groupsObj = oidcUser.getClaims().getOrDefault("groups", List.of());
List<String> listOfGroups;
if (groupsObj instanceof List<?> groupsList) {
listOfGroups = groupsList.stream()
.filter(String.class::isInstance)
.map(String.class::cast)
.toList();
} else {
listOfGroups = List.of();
}
add(new Paragraph("Angemeldet als: " + username));
if (!listOfGroups.contains("Kicker Admin")) {
add(new Paragraph("Du bist nicht berechtigt, diese Seite zu sehen."));
getUI().ifPresent(ui -> ui.navigate(""));
return;
} else {
add(new Paragraph("Willkommen im Admin-Bereich!"));
}
} else {
add(new Paragraph("Niemand ist angemeldet"));
add(new Paragraph("Du bist nicht berechtigt, diese Seite zu sehen.")); add(new Paragraph("Du bist nicht berechtigt, diese Seite zu sehen."));
getUI().ifPresent(ui -> ui.navigate("")); getUI().ifPresent(ui -> ui.navigate(""));
return; return;