mirror of
https://github.com/AJMicke/KickerELO.git
synced 2026-03-11 13:31:02 +01:00
Ignore login when in test env
This commit is contained in:
@@ -22,48 +22,66 @@ import com.vaadin.flow.router.Route;
|
|||||||
@Route("admin")
|
@Route("admin")
|
||||||
public class AdminView extends VerticalLayout {
|
public class AdminView extends VerticalLayout {
|
||||||
|
|
||||||
public void beforeEnter(BeforeEnterEvent event) {
|
private final org.springframework.core.env.Environment environment;
|
||||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
||||||
if (auth == null || !(auth.getPrincipal() instanceof OidcUser oidcUser)) {
|
|
||||||
event.rerouteTo("");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var groups = oidcUser.getClaimAsStringList("groups");
|
// Methode zum Prüfen, ob das "test"-Profil aktiv ist
|
||||||
if (groups == null || !groups.contains("Kicker Admin")) {
|
private boolean isTestProfileActive() {
|
||||||
event.rerouteTo("");
|
for (String profile : environment.getActiveProfiles()) {
|
||||||
|
System.out.println("Active profile: " + profile);
|
||||||
|
if ("prod".equals(profile)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void beforeEnter(BeforeEnterEvent event) {
|
||||||
|
if (!isTestProfileActive()) {
|
||||||
|
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("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminView(KickerEloService service) {
|
public AdminView(KickerEloService service, org.springframework.core.env.Environment environment) {
|
||||||
// Zeige den aktuell authentifizierten Benutzer
|
this.environment = environment;
|
||||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
||||||
if (auth != null && auth.getPrincipal() instanceof OidcUser oidcUser) {
|
if (!isTestProfileActive()) {
|
||||||
String username = oidcUser.getPreferredUsername();
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||||
Object groupsObj = oidcUser.getClaims().getOrDefault("groups", List.of());
|
if (auth != null && auth.getPrincipal() instanceof OidcUser oidcUser) {
|
||||||
List<String> listOfGroups;
|
String username = oidcUser.getPreferredUsername();
|
||||||
if (groupsObj instanceof List<?> groupsList) {
|
Object groupsObj = oidcUser.getClaims().getOrDefault("groups", List.of());
|
||||||
listOfGroups = groupsList.stream()
|
List<String> listOfGroups;
|
||||||
.filter(String.class::isInstance)
|
if (groupsObj instanceof List<?> groupsList) {
|
||||||
.map(String.class::cast)
|
listOfGroups = groupsList.stream()
|
||||||
.toList();
|
.filter(String.class::isInstance)
|
||||||
} else {
|
.map(String.class::cast)
|
||||||
listOfGroups = List.of();
|
.toList();
|
||||||
}
|
} else {
|
||||||
add(new Paragraph("Angemeldet als: " + username));
|
listOfGroups = List.of();
|
||||||
|
}
|
||||||
|
add(new Paragraph("Angemeldet als: " + username));
|
||||||
|
|
||||||
if (!listOfGroups.contains("Kicker Admin")) {
|
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;
|
||||||
} 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."));
|
|
||||||
getUI().ifPresent(ui -> ui.navigate(""));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField spielername = new TextField("Spielername");
|
TextField spielername = new TextField("Spielername");
|
||||||
|
|||||||
Reference in New Issue
Block a user