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")
|
@Route("admin")
|
||||||
public class AdminView extends VerticalLayout {
|
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) {
|
public void beforeEnter(BeforeEnterEvent event) {
|
||||||
|
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)) {
|
||||||
event.rerouteTo("");
|
event.rerouteTo("");
|
||||||
@@ -34,9 +48,12 @@ public class AdminView extends VerticalLayout {
|
|||||||
event.rerouteTo("");
|
event.rerouteTo("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public AdminView(KickerEloService service) {
|
public AdminView(KickerEloService service, org.springframework.core.env.Environment environment) {
|
||||||
// Zeige den aktuell authentifizierten Benutzer
|
this.environment = environment;
|
||||||
|
|
||||||
|
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) {
|
||||||
String username = oidcUser.getPreferredUsername();
|
String username = oidcUser.getPreferredUsername();
|
||||||
@@ -65,6 +82,7 @@ public class AdminView extends VerticalLayout {
|
|||||||
getUI().ifPresent(ui -> ui.navigate(""));
|
getUI().ifPresent(ui -> ui.navigate(""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TextField spielername = new TextField("Spielername");
|
TextField spielername = new TextField("Spielername");
|
||||||
spielername.addClassName("bordered");
|
spielername.addClassName("bordered");
|
||||||
|
|||||||
Reference in New Issue
Block a user