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,7 +22,21 @@ import com.vaadin.flow.router.Route;
|
||||
@Route("admin")
|
||||
public class AdminView extends VerticalLayout {
|
||||
|
||||
private final org.springframework.core.env.Environment environment;
|
||||
|
||||
// Methode zum Prüfen, ob das "test"-Profil aktiv ist
|
||||
private boolean isTestProfileActive() {
|
||||
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("");
|
||||
@@ -34,9 +48,12 @@ public class AdminView extends VerticalLayout {
|
||||
event.rerouteTo("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AdminView(KickerEloService service) {
|
||||
// Zeige den aktuell authentifizierten Benutzer
|
||||
public AdminView(KickerEloService service, org.springframework.core.env.Environment environment) {
|
||||
this.environment = environment;
|
||||
|
||||
if (!isTestProfileActive()) {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.getPrincipal() instanceof OidcUser oidcUser) {
|
||||
String username = oidcUser.getPreferredUsername();
|
||||
@@ -65,6 +82,7 @@ public class AdminView extends VerticalLayout {
|
||||
getUI().ifPresent(ui -> ui.navigate(""));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextField spielername = new TextField("Spielername");
|
||||
spielername.addClassName("bordered");
|
||||
|
||||
Reference in New Issue
Block a user