Erweiterungen
This commit is contained in:
9513
package-lock.json
generated
Normal file
9513
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
110
package.json
Normal file
110
package.json
Normal file
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"name": "no-name",
|
||||
"license": "UNLICENSED",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@polymer/polymer": "3.5.2",
|
||||
"@vaadin/bundles": "24.7.7",
|
||||
"@vaadin/common-frontend": "0.0.19",
|
||||
"@vaadin/polymer-legacy-adapter": "24.7.7",
|
||||
"@vaadin/react-components": "24.7.7",
|
||||
"@vaadin/react-components-pro": "24.7.7",
|
||||
"@vaadin/vaadin-development-mode-detector": "2.0.7",
|
||||
"@vaadin/vaadin-lumo-styles": "24.7.7",
|
||||
"@vaadin/vaadin-material-styles": "24.7.7",
|
||||
"@vaadin/vaadin-themable-mixin": "24.7.7",
|
||||
"@vaadin/vaadin-usage-statistics": "2.1.3",
|
||||
"construct-style-sheets-polyfill": "3.1.0",
|
||||
"date-fns": "2.29.3",
|
||||
"lit": "3.3.0",
|
||||
"proj4": "2.15.0",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-router": "7.5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-react": "7.26.3",
|
||||
"@preact/signals-react-transform": "0.5.1",
|
||||
"@rollup/plugin-replace": "6.0.2",
|
||||
"@rollup/pluginutils": "5.1.4",
|
||||
"@types/react": "18.3.20",
|
||||
"@types/react-dom": "18.3.6",
|
||||
"@vitejs/plugin-react": "4.4.1",
|
||||
"async": "3.2.6",
|
||||
"glob": "11.0.2",
|
||||
"rollup-plugin-brotli": "3.1.0",
|
||||
"rollup-plugin-visualizer": "5.14.0",
|
||||
"strip-css-comments": "5.0.0",
|
||||
"transform-ast": "2.4.4",
|
||||
"typescript": "5.7.3",
|
||||
"vite": "6.3.4",
|
||||
"vite-plugin-checker": "0.9.1",
|
||||
"workbox-build": "7.3.0",
|
||||
"workbox-core": "7.3.0",
|
||||
"workbox-precaching": "7.3.0"
|
||||
},
|
||||
"vaadin": {
|
||||
"dependencies": {
|
||||
"@polymer/polymer": "3.5.2",
|
||||
"@vaadin/bundles": "24.7.7",
|
||||
"@vaadin/common-frontend": "0.0.19",
|
||||
"@vaadin/polymer-legacy-adapter": "24.7.7",
|
||||
"@vaadin/react-components": "24.7.7",
|
||||
"@vaadin/react-components-pro": "24.7.7",
|
||||
"@vaadin/vaadin-development-mode-detector": "2.0.7",
|
||||
"@vaadin/vaadin-lumo-styles": "24.7.7",
|
||||
"@vaadin/vaadin-material-styles": "24.7.7",
|
||||
"@vaadin/vaadin-themable-mixin": "24.7.7",
|
||||
"@vaadin/vaadin-usage-statistics": "2.1.3",
|
||||
"construct-style-sheets-polyfill": "3.1.0",
|
||||
"date-fns": "2.29.3",
|
||||
"lit": "3.3.0",
|
||||
"proj4": "2.15.0",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-router": "7.5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-react": "7.26.3",
|
||||
"@preact/signals-react-transform": "0.5.1",
|
||||
"@rollup/plugin-replace": "6.0.2",
|
||||
"@rollup/pluginutils": "5.1.4",
|
||||
"@types/react": "18.3.20",
|
||||
"@types/react-dom": "18.3.6",
|
||||
"@vitejs/plugin-react": "4.4.1",
|
||||
"async": "3.2.6",
|
||||
"glob": "11.0.2",
|
||||
"rollup-plugin-brotli": "3.1.0",
|
||||
"rollup-plugin-visualizer": "5.14.0",
|
||||
"strip-css-comments": "5.0.0",
|
||||
"transform-ast": "2.4.4",
|
||||
"typescript": "5.7.3",
|
||||
"vite": "6.3.4",
|
||||
"vite-plugin-checker": "0.9.1",
|
||||
"workbox-build": "7.3.0",
|
||||
"workbox-core": "7.3.0",
|
||||
"workbox-precaching": "7.3.0"
|
||||
},
|
||||
"hash": "c18408e57a0875a842d7f93da064e1b59d0f12787cf31c11320e67bdbc80cdb5"
|
||||
},
|
||||
"overrides": {
|
||||
"@vaadin/bundles": "$@vaadin/bundles",
|
||||
"@vaadin/polymer-legacy-adapter": "$@vaadin/polymer-legacy-adapter",
|
||||
"@vaadin/vaadin-development-mode-detector": "$@vaadin/vaadin-development-mode-detector",
|
||||
"@vaadin/vaadin-usage-statistics": "$@vaadin/vaadin-usage-statistics",
|
||||
"@vaadin/react-components": "$@vaadin/react-components",
|
||||
"@vaadin/react-components-pro": "$@vaadin/react-components-pro",
|
||||
"@vaadin/common-frontend": "$@vaadin/common-frontend",
|
||||
"react-dom": "$react-dom",
|
||||
"construct-style-sheets-polyfill": "$construct-style-sheets-polyfill",
|
||||
"lit": "$lit",
|
||||
"@polymer/polymer": "$@polymer/polymer",
|
||||
"react": "$react",
|
||||
"react-router": "$react-router",
|
||||
"date-fns": "$date-fns",
|
||||
"proj4": "$proj4",
|
||||
"@vaadin/vaadin-themable-mixin": "$@vaadin/vaadin-themable-mixin",
|
||||
"@vaadin/vaadin-lumo-styles": "$@vaadin/vaadin-lumo-styles",
|
||||
"@vaadin/vaadin-material-styles": "$@vaadin/vaadin-material-styles"
|
||||
}
|
||||
}
|
||||
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.assecutor.emulatorstation</groupId>
|
||||
<artifactId>emulatorstation</artifactId>
|
||||
<version>0.9.11</version>
|
||||
<version>0.9.12</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -29,9 +29,7 @@ public class Application implements AppShellConfigurator {
|
||||
Map.entry("Hannover", new NiederlassungInfo("Hannover", "172.18.0.104", "6084", "/hannover")),
|
||||
Map.entry("Stuttgart", new NiederlassungInfo("Stuttgart", "172.18.0.111", "6091", "/stuttgart")),
|
||||
Map.entry("Frankfurt am Main", new NiederlassungInfo("Frankfurt am Main", "172.18.0.105", "6085", "/frankfurt")),
|
||||
Map.entry("Geschäftführung", new NiederlassungInfo("Geschäftführung", "172.18.0.112", "6092", "/gfl")),
|
||||
Map.entry("Admin", new NiederlassungInfo("Admin", "172.18.0.110", "6090", "/admin"))
|
||||
);
|
||||
Map.entry("Geschäftführung", new NiederlassungInfo("Geschäftführung", "172.18.0.112", "6092", "/gfl")));
|
||||
|
||||
public static final Map<String, String> activeNiederlassungen = new ConcurrentHashMap<>();
|
||||
public static final Map<String, String> activeSessions = new ConcurrentHashMap<>(); // sessionId -> niederlassung
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
|
||||
|
||||
|
||||
@Route("login")
|
||||
@AnonymousAllowed
|
||||
@@ -31,43 +33,28 @@ public class LoginView extends VerticalLayout {
|
||||
setSizeFull();
|
||||
setAlignItems(Alignment.CENTER);
|
||||
setJustifyContentMode(JustifyContentMode.CENTER);
|
||||
getStyle()
|
||||
.set("background", "linear-gradient(135deg, #667eea 0%, #764ba2 100%)")
|
||||
.set("min-height", "100vh")
|
||||
getStyle().set("background", "linear-gradient(135deg, #667eea 0%, #764ba2 100%)").set("min-height", "100vh")
|
||||
.set("padding", "20px");
|
||||
|
||||
// Haupt-Container für das Login-Formular
|
||||
Div loginContainer = new Div();
|
||||
loginContainer.getStyle()
|
||||
.set("background-color", "#ffffff")
|
||||
.set("border-radius", "12px")
|
||||
.set("box-shadow", "0 10px 30px rgba(0,0,0,0.2)")
|
||||
.set("padding", "40px")
|
||||
.set("max-width", "400px")
|
||||
.set("width", "100%")
|
||||
.set("text-align", "center");
|
||||
loginContainer.getStyle().set("background-color", "#ffffff").set("border-radius", "12px")
|
||||
.set("box-shadow", "0 10px 30px rgba(0,0,0,0.2)").set("padding", "40px").set("max-width", "400px")
|
||||
.set("width", "100%").set("text-align", "center");
|
||||
|
||||
// Logo/Icon
|
||||
Icon icon = new Icon(VaadinIcon.DESKTOP);
|
||||
icon.setSize("64px");
|
||||
icon.getStyle()
|
||||
.set("color", "#667eea")
|
||||
.set("margin-bottom", "20px");
|
||||
icon.getStyle().set("color", "#667eea").set("margin-bottom", "20px");
|
||||
|
||||
// Titel
|
||||
H1 title = new H1("Emulator Station");
|
||||
title.getStyle()
|
||||
.set("margin", "0 0 8px 0")
|
||||
.set("color", "#333333")
|
||||
.set("font-size", "2rem")
|
||||
.set("font-weight", "600");
|
||||
title.getStyle().set("margin", "0 0 8px 0").set("color", "#333333").set("font-size", "2rem").set("font-weight",
|
||||
"600");
|
||||
|
||||
// Untertitel
|
||||
Paragraph subtitle = new Paragraph("Melden Sie sich an, um fortzufahren");
|
||||
subtitle.getStyle()
|
||||
.set("margin", "0 0 30px 0")
|
||||
.set("color", "#666666")
|
||||
.set("font-size", "0.95rem");
|
||||
subtitle.getStyle().set("margin", "0 0 30px 0").set("color", "#666666").set("font-size", "0.95rem");
|
||||
|
||||
// Form-Container
|
||||
VerticalLayout formLayout = new VerticalLayout();
|
||||
@@ -78,16 +65,14 @@ public class LoginView extends VerticalLayout {
|
||||
// Eingabefelder - nur noch Passwort
|
||||
PasswordField passwordField = new PasswordField("Passwort");
|
||||
passwordField.setWidthFull();
|
||||
passwordField.getStyle()
|
||||
.set("margin-bottom", "16px");
|
||||
passwordField.getStyle().set("margin-bottom", "16px");
|
||||
|
||||
Select<String> niederlassungSelect = new Select<>();
|
||||
niederlassungSelect.setLabel("Niederlassung");
|
||||
niederlassungSelect.setItems(Application.niederlassungen.keySet().stream().sorted().toList());
|
||||
niederlassungSelect.setPlaceholder("Wählen Sie eine Niederlassung");
|
||||
niederlassungSelect.setWidthFull();
|
||||
niederlassungSelect.getStyle()
|
||||
.set("margin-bottom", "24px");
|
||||
niederlassungSelect.getStyle().set("margin-bottom", "24px");
|
||||
|
||||
Button loginButton = new Button("Anmelden", new Icon(VaadinIcon.SIGN_IN), event -> {
|
||||
String password = passwordField.getValue();
|
||||
@@ -107,13 +92,17 @@ public class LoginView extends VerticalLayout {
|
||||
|
||||
// Maximale Session-Anzahl prüfen
|
||||
if (Application.activeSessions.size() >= Application.MAX_ACTIVE_SESSIONS) {
|
||||
Notification.show("Maximale Anzahl von " + Application.MAX_ACTIVE_SESSIONS + " gleichzeitigen Anmeldungen erreicht. Bitte versuchen Sie es später erneut.", 5000, Notification.Position.MIDDLE);
|
||||
Notification.show(
|
||||
"Maximale Anzahl von " + Application.MAX_ACTIVE_SESSIONS
|
||||
+ " gleichzeitigen Anmeldungen erreicht. Bitte versuchen Sie es später erneut.",
|
||||
5000, Notification.Position.MIDDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Prüfen ob Niederlassung bereits belegt ist
|
||||
if (Application.activeNiederlassungen.containsKey(niederlassung)) {
|
||||
Notification.show("Niederlassung ist bereits von einer anderen Session belegt", 3000, Notification.Position.MIDDLE);
|
||||
Notification.show("Niederlassung ist bereits von einer anderen Session belegt", 3000,
|
||||
Notification.Position.MIDDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -124,44 +113,32 @@ public class LoginView extends VerticalLayout {
|
||||
}
|
||||
|
||||
getUI().ifPresent(ui -> {
|
||||
String sessionId = ui.getSession().getSession().getId();
|
||||
|
||||
// Session registrieren
|
||||
Application.activeSessions.put(sessionId, niederlassung);
|
||||
Application.activeNiederlassungen.put(niederlassung, sessionId);
|
||||
|
||||
// Log that Niederlassung is now blocked
|
||||
logger.info("Niederlassung '{}' wurde gesperrt für Session {}", niederlassung, sessionId);
|
||||
logger.info("Aktive Niederlassungen: {}", Application.activeNiederlassungen.keySet());
|
||||
|
||||
// Spring Security Authentifizierung setzen
|
||||
var authorities = List.of(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
var authentication = new UsernamePasswordAuthenticationToken(Application.SINGLE_USERNAME, password, authorities);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
// Session-Daten setzen
|
||||
ui.getSession().setAttribute("user", Application.SINGLE_USERNAME);
|
||||
ui.getSession().setAttribute("username", Application.SINGLE_USERNAME);
|
||||
ui.getSession().setAttribute("niederlassung", niederlassungInfo);
|
||||
ui.getSession().setAttribute("sessionId", sessionId);
|
||||
|
||||
logger.info("Login erfolgreich - Session-Daten gesetzt:");
|
||||
logger.info("Username: {}", Application.SINGLE_USERNAME);
|
||||
logger.info("Niederlassung: {}", niederlassungInfo.name());
|
||||
logger.info("SessionId: {}", sessionId);
|
||||
logger.info("Aktive Sessions: {}/{}", Application.activeSessions.size(), Application.MAX_ACTIVE_SESSIONS);
|
||||
|
||||
ui.navigate("main");
|
||||
if (isContainerRunning(niederlassungInfo)) {
|
||||
var dialog = new com.vaadin.flow.component.dialog.Dialog();
|
||||
dialog.setHeaderTitle("Container läuft bereits");
|
||||
var text = new Paragraph("Für '" + niederlassungInfo.name() + "' läuft bereits ein Emulator-Container. Möchten Sie ihn für diese Session übernehmen?");
|
||||
var adopt = new Button("Übernehmen", e2 -> {
|
||||
dialog.close();
|
||||
completeLogin(ui, password, niederlassungInfo, true);
|
||||
});
|
||||
adopt.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||
var cancel = new Button("Abbrechen", e2 -> dialog.close());
|
||||
var buttons = new com.vaadin.flow.component.orderedlayout.HorizontalLayout(cancel, adopt);
|
||||
buttons.setWidthFull();
|
||||
buttons.setJustifyContentMode(com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode.END);
|
||||
dialog.add(text, buttons);
|
||||
dialog.open();
|
||||
} else {
|
||||
completeLogin(ui, password, niederlassungInfo, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Button-Styling
|
||||
loginButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_LARGE);
|
||||
loginButton.setWidthFull();
|
||||
loginButton.getStyle()
|
||||
.set("margin-top", "8px")
|
||||
.set("background", "linear-gradient(135deg, #667eea 0%, #764ba2 100%)")
|
||||
.set("border", "none")
|
||||
loginButton.getStyle().set("margin-top", "8px")
|
||||
.set("background", "linear-gradient(135deg, #667eea 0%, #764ba2 100%)").set("border", "none")
|
||||
.set("font-weight", "600");
|
||||
|
||||
// Eingabefelder zum Form-Layout hinzufügen
|
||||
|
||||
@@ -42,24 +42,17 @@ public final class MainLayout extends AppLayout {
|
||||
UI ui = UI.getCurrent();
|
||||
ui.setPollInterval(60000); // Poll-Intervall auf 60 Sekunden setzen
|
||||
|
||||
// Session expiration handling
|
||||
// Session keep-alive - no automatic invalidation on reload
|
||||
ui.addPollListener(event -> {
|
||||
if (!isUserSessionValid()) {
|
||||
VaadinSession.getCurrent().getSession().invalidate(); // Session invalidieren
|
||||
ui.access(() -> ui.navigate("main")); // Immer zur Main-Seite weiterleiten
|
||||
// Just keep the session alive, don't invalidate
|
||||
// Session timeout is now handled by Spring Security configuration
|
||||
if (VaadinSession.getCurrent() != null) {
|
||||
// Touch the session to keep it alive
|
||||
VaadinSession.getCurrent().getSession().getMaxInactiveInterval();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isUserSessionValid() {
|
||||
// Logik für Sitzungsprüfung, z.B. Timeout-Zeit überprüfen
|
||||
return VaadinSession.getCurrent() != null
|
||||
&& VaadinSession.getCurrent().getSession() != null
|
||||
&& VaadinSession.getCurrent().getSession().getLastAccessedTime() + 300000
|
||||
> System.currentTimeMillis(); // 300000 ms = 5 Minuten
|
||||
}
|
||||
|
||||
|
||||
private Div createHeader() {
|
||||
// TODO Replace with real application logo and name
|
||||
var appLogo = VaadinIcon.CUBES.create();
|
||||
|
||||
@@ -20,6 +20,8 @@ import com.vaadin.flow.router.BeforeEnterObserver;
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.html.Main;
|
||||
import com.vaadin.flow.router.Route;
|
||||
import com.vaadin.flow.router.PreserveOnRefresh;
|
||||
|
||||
import com.vaadin.flow.server.auth.AnonymousAllowed;
|
||||
import com.vaadin.flow.server.VaadinSession;
|
||||
import de.assecutor.emulatorstation.pojo.ExecResponse;
|
||||
@@ -38,9 +40,9 @@ import java.util.concurrent.Executors;
|
||||
|
||||
@PermitAll // When security is enabled, allow all authenticated users
|
||||
@Route("main")
|
||||
@PreserveOnRefresh
|
||||
@AnonymousAllowed
|
||||
public final class MainView extends Main implements BeforeEnterObserver
|
||||
{
|
||||
public final class MainView extends Main implements BeforeEnterObserver {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MainView.class);
|
||||
private String username;
|
||||
private NiederlassungInfo niederlassung;
|
||||
@@ -55,26 +57,16 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
MainView() {
|
||||
setSizeFull();
|
||||
getStyle()
|
||||
.set("background", "linear-gradient(135deg, #667eea 0%, #764ba2 100%)")
|
||||
.set("min-height", "100vh")
|
||||
.set("display", "flex")
|
||||
.set("flex-direction", "column")
|
||||
.set("align-items", "center")
|
||||
.set("justify-content", "center")
|
||||
.set("padding", "2.5%")
|
||||
.set("box-sizing", "border-box")
|
||||
getStyle().set("background", "linear-gradient(135deg, #667eea 0%, #764ba2 100%)").set("min-height", "100vh")
|
||||
.set("display", "flex").set("flex-direction", "column").set("align-items", "center")
|
||||
.set("justify-content", "center").set("padding", "2.5%").set("box-sizing", "border-box")
|
||||
.set("overflow", "hidden");
|
||||
|
||||
var contentContainer = new Div();
|
||||
contentContainer.getStyle()
|
||||
.set("width", "95%")
|
||||
.set("height", "95%")
|
||||
.set("display", "flex")
|
||||
.set("flex-direction", "column")
|
||||
.set("box-sizing", "border-box");
|
||||
contentContainer.getStyle().set("width", "95%").set("height", "95%").set("display", "flex")
|
||||
.set("flex-direction", "column").set("box-sizing", "border-box");
|
||||
|
||||
|
||||
setupInactivityTimer();
|
||||
setupWelcomeMessage(contentContainer);
|
||||
setupEmulatorContainer(contentContainer);
|
||||
setupButtonLayout(contentContainer);
|
||||
@@ -83,18 +75,19 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
addAttachListener(event -> {
|
||||
loadSessionData();
|
||||
setupSessionCleanupListener();
|
||||
restoreUIStateIfNeeded();
|
||||
});
|
||||
|
||||
// Add detach listener to cleanup resources when view is detached
|
||||
addDetachListener(event -> {
|
||||
logger.info("MainView detached - cleaning up resources");
|
||||
cleanupResources();
|
||||
});
|
||||
// Kein Cleanup mehr beim Detach, um Reload-Resume zu ermöglichen
|
||||
}
|
||||
|
||||
private void setupSessionCleanupListener() {
|
||||
VaadinSession session = VaadinSession.getCurrent();
|
||||
if (session != null) {
|
||||
Boolean registered = (Boolean) session.getAttribute("cleanupListenerRegistered");
|
||||
if (Boolean.TRUE.equals(registered)) {
|
||||
return;
|
||||
}
|
||||
session.addSessionDestroyListener(event -> {
|
||||
logger.info("Session destroy event triggered - cleaning up resources");
|
||||
// Cleanup will be done in a background thread to avoid blocking
|
||||
@@ -106,6 +99,7 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
}
|
||||
});
|
||||
});
|
||||
session.setAttribute("cleanupListenerRegistered", true);
|
||||
logger.info("Session cleanup listener registered for session: {}", session.getSession().getId());
|
||||
}
|
||||
}
|
||||
@@ -140,55 +134,27 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
if (niederlassungName != null) {
|
||||
Application.activeNiederlassungen.remove(niederlassungName);
|
||||
logger.info("Niederlassung '{}' wurde freigegeben und ist wieder verfügbar für neue Anmeldungen", niederlassungName);
|
||||
logger.info("Niederlassung '{}' wurde freigegeben und ist wieder verfügbar für neue Anmeldungen",
|
||||
niederlassungName);
|
||||
logger.info("Aktive Niederlassungen nach Freigabe: {}", Application.activeNiederlassungen.keySet());
|
||||
}
|
||||
|
||||
logger.info("Resource cleanup completed successfully");
|
||||
logger.info("Active sessions after cleanup: {}/{}", Application.activeSessions.size(), Application.MAX_ACTIVE_SESSIONS);
|
||||
logger.info("Active sessions after cleanup: {}/{}", Application.activeSessions.size(),
|
||||
Application.MAX_ACTIVE_SESSIONS);
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error during resource cleanup", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupInactivityTimer() {
|
||||
String jsCode = """
|
||||
var inactivityTime = function () {
|
||||
var time;
|
||||
window.onload = resetTimer;
|
||||
document.onmousemove = resetTimer;
|
||||
document.onkeypress = resetTimer;
|
||||
document.onclick = resetTimer;
|
||||
document.onscroll = resetTimer;
|
||||
|
||||
function logout() {
|
||||
$0.$server.logout();
|
||||
}
|
||||
|
||||
function resetTimer() {
|
||||
clearTimeout(time);
|
||||
time = setTimeout(logout, 4 * 60 * 60 * 1000);
|
||||
}
|
||||
};
|
||||
inactivityTime();
|
||||
""";
|
||||
|
||||
UI.getCurrent().getPage().executeJs(jsCode, this);
|
||||
}
|
||||
|
||||
private void setupWelcomeMessage(Div container) {
|
||||
welcomeMessage.addClassName("welcome-panel");
|
||||
welcomeMessage.getStyle()
|
||||
.set("display", "flex")
|
||||
.set("flex-direction", "column")
|
||||
.set("align-items", "center")
|
||||
.set("justify-content", "center")
|
||||
.set("flex-grow", "1")
|
||||
.set("background-color", "#f8f9fa")
|
||||
.set("border", "2px dashed #dee2e6")
|
||||
.set("border-radius", "8px")
|
||||
.set("color", "#6c757d")
|
||||
welcomeMessage.getStyle().set("display", "flex").set("flex-direction", "column").set("align-items", "center")
|
||||
.set("justify-content", "center").set("flex-grow", "1").set("background-color", "#f8f9fa")
|
||||
.set("border", "2px dashed #dee2e6").set("border-radius", "8px").set("color", "#6c757d")
|
||||
.set("margin-bottom", "16px");
|
||||
|
||||
Icon icon = new Icon(VaadinIcon.DESKTOP);
|
||||
@@ -198,7 +164,8 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
H2 title = new H2("Willkommen bei der Emulator Station");
|
||||
title.getStyle().set("margin", "0 0 6px 0").set("color", "#495057").set("font-size", "1.5rem");
|
||||
|
||||
Paragraph description = new Paragraph("Klicken Sie auf 'Emulator starten', um Ihren Android Emulator zu starten.");
|
||||
Paragraph description = new Paragraph(
|
||||
"Klicken Sie auf 'Emulator starten', um Ihren Android Emulator zu starten.");
|
||||
description.getStyle().set("margin", "0").set("text-align", "center").set("font-size", "0.9rem");
|
||||
|
||||
welcomeMessage.add(icon, title, description);
|
||||
@@ -208,36 +175,24 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
private void setupButtonLayout(Div container) {
|
||||
var buttonLayout = new HorizontalLayout();
|
||||
buttonLayout.setJustifyContentMode(HorizontalLayout.JustifyContentMode.CENTER);
|
||||
buttonLayout.getStyle()
|
||||
.set("margin", "0")
|
||||
.set("padding", "8px 0")
|
||||
.set("flex-shrink", "0")
|
||||
.set("order", "999");
|
||||
buttonLayout.getStyle().set("margin", "0").set("padding", "8px 0").set("flex-shrink", "0").set("order", "999");
|
||||
|
||||
startBtn = new Button("Emulator starten", new Icon(VaadinIcon.PLAY), event -> startup());
|
||||
startBtn.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||
|
||||
Button logoutBtn = new Button("Abmelden", new Icon(VaadinIcon.SIGN_OUT), event -> logout());
|
||||
logoutBtn.addThemeVariants(ButtonVariant.LUMO_CONTRAST);
|
||||
logoutBtn.getStyle()
|
||||
.set("background-color", "#f5f5f5")
|
||||
.set("color", "#333333")
|
||||
.set("border", "1px solid #d0d0d0");
|
||||
logoutBtn.getStyle().set("background-color", "#f5f5f5").set("color", "#333333").set("border",
|
||||
"1px solid #d0d0d0");
|
||||
|
||||
buttonLayout.add(startBtn, logoutBtn);
|
||||
container.add(buttonLayout);
|
||||
}
|
||||
|
||||
private void setupEmulatorContainer(Div container) {
|
||||
emulatorContainer.getStyle()
|
||||
.set("border", "2px solid #e9ecef")
|
||||
.set("border-radius", "8px")
|
||||
.set("background-color", "#ffffff")
|
||||
.set("box-shadow", "0 2px 4px rgba(0,0,0,0.1)")
|
||||
.set("overflow", "hidden")
|
||||
.set("display", "none")
|
||||
.set("flex-grow", "1")
|
||||
.set("margin-bottom", "16px");
|
||||
emulatorContainer.getStyle().set("border", "2px solid #e9ecef").set("border-radius", "8px")
|
||||
.set("background-color", "#ffffff").set("box-shadow", "0 2px 4px rgba(0,0,0,0.1)")
|
||||
.set("overflow", "hidden").set("display", "none").set("flex-grow", "1").set("margin-bottom", "16px");
|
||||
|
||||
webView.setSizeFull();
|
||||
ensureWebViewScrollbarsHidden();
|
||||
@@ -250,26 +205,19 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
webView.addClassName("mainview-webview");
|
||||
webView.getElement().setAttribute("frameborder", "0");
|
||||
webView.getElement().setAttribute("scrolling", "no");
|
||||
webView.getElement().getStyle()
|
||||
.set("border", "0")
|
||||
.set("overflow", "hidden")
|
||||
.set("-ms-overflow-style", "none")
|
||||
webView.getElement().getStyle().set("border", "0").set("overflow", "hidden").set("-ms-overflow-style", "none")
|
||||
.set("scrollbar-width", "none");
|
||||
|
||||
// Force-disable iframe scrollbars for all major engines
|
||||
webView.getElement().executeJs(
|
||||
"const frame = this;" +
|
||||
"frame.style.setProperty('overflow', 'hidden', 'important');" +
|
||||
"frame.style.setProperty('scrollbar-width', 'none', 'important');" +
|
||||
"frame.style.setProperty('-ms-overflow-style', 'none', 'important');" +
|
||||
"frame.classList.add('mainview-webview');" +
|
||||
"if (!document.getElementById('mainview-webview-scroll-style')) {" +
|
||||
" const style = document.createElement('style');" +
|
||||
" style.id = 'mainview-webview-scroll-style';" +
|
||||
" style.textContent = '.mainview-webview { overflow: hidden !important; scrollbar-width: none !important; -ms-overflow-style: none !important; } .mainview-webview::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }';" +
|
||||
" document.head.appendChild(style);" +
|
||||
"}"
|
||||
);
|
||||
webView.getElement().executeJs("const frame = this;"
|
||||
+ "frame.style.setProperty('overflow', 'hidden', 'important');"
|
||||
+ "frame.style.setProperty('scrollbar-width', 'none', 'important');"
|
||||
+ "frame.style.setProperty('-ms-overflow-style', 'none', 'important');"
|
||||
+ "frame.classList.add('mainview-webview');"
|
||||
+ "if (!document.getElementById('mainview-webview-scroll-style')) {"
|
||||
+ " const style = document.createElement('style');" + " style.id = 'mainview-webview-scroll-style';"
|
||||
+ " style.textContent = '.mainview-webview { overflow: hidden !important; scrollbar-width: none !important; -ms-overflow-style: none !important; } .mainview-webview::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }';"
|
||||
+ " document.head.appendChild(style);" + "}");
|
||||
}
|
||||
|
||||
private void loadSessionData() {
|
||||
@@ -279,6 +227,29 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
username = (String) vaadinSession.getAttribute("username");
|
||||
niederlassung = (NiederlassungInfo) vaadinSession.getAttribute("niederlassung");
|
||||
server = (String) vaadinSession.getAttribute("server");
|
||||
|
||||
// Fallback: Nach Reload Niederlassung anhand der aktiven Sessions rekonstruieren
|
||||
if (niederlassung == null) {
|
||||
try {
|
||||
String sid = (String) vaadinSession.getAttribute("sessionId");
|
||||
if (sid == null && vaadinSession.getSession() != null) {
|
||||
sid = vaadinSession.getSession().getId();
|
||||
}
|
||||
if (sid != null) {
|
||||
String nlName = Application.activeSessions.get(sid);
|
||||
if (nlName != null) {
|
||||
NiederlassungInfo info = Application.niederlassungen.get(nlName);
|
||||
if (info != null) {
|
||||
niederlassung = info;
|
||||
vaadinSession.setAttribute("niederlassung", info);
|
||||
logger.info("Niederlassung nach Reload wiederhergestellt: {}", info.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Fehler bei der Rekonstruktion der Niederlassung", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.error("UI nicht verfügbar - kann Session-Daten nicht laden");
|
||||
}
|
||||
@@ -291,10 +262,25 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
logger.info("Username: {}", username);
|
||||
logger.info("Niederlassung: {}", (niederlassung != null ? niederlassung.name() : "null"));
|
||||
logger.info("Server: {}", server);
|
||||
// Wichtig: Kein Redirect mehr hier. Falls keine Daten da sind, bleibt der Nutzer auf Main.
|
||||
}
|
||||
|
||||
if (niederlassung == null) {
|
||||
logger.error("FEHLER: Niederlassung ist null! Benutzer muss sich neu anmelden.");
|
||||
getUI().ifPresent(ui -> ui.navigate("login"));
|
||||
private void restoreUIStateIfNeeded() {
|
||||
var uiOpt = getUI();
|
||||
if (uiOpt.isEmpty()) return;
|
||||
var session = uiOpt.get().getSession();
|
||||
|
||||
boolean emulatorStarted = Boolean.TRUE.equals(session.getAttribute("emulatorStarted"));
|
||||
if (emulatorStarted && niederlassung != null) {
|
||||
// UI in gestarteten Zustand versetzen
|
||||
welcomeMessage.getStyle().set("display", "none");
|
||||
emulatorContainer.getStyle().set("display", "block");
|
||||
if (startBtn != null) {
|
||||
startBtn.setEnabled(false);
|
||||
startBtn.setText("Emulator gestartet");
|
||||
}
|
||||
// WebView aktualisieren (baut URL aus der Niederlassung)
|
||||
refreshWebView();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,8 +300,7 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
shutdown();
|
||||
|
||||
if (!isContainerStarted(niederlassung)) {
|
||||
createContainer();
|
||||
|
||||
startContainer();
|
||||
@@ -325,7 +310,7 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
downloadApp();
|
||||
|
||||
installApp();
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// Logging, Fehlerbehandlung …
|
||||
} finally {
|
||||
@@ -340,6 +325,9 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
// Button bleibt dauerhaft deaktiviert
|
||||
startBtn.setText("Emulator gestartet");
|
||||
|
||||
// Zustand merken, damit Reload weiterfuehrt
|
||||
ui.getSession().setAttribute("emulatorStarted", true);
|
||||
|
||||
refreshWebView();
|
||||
});
|
||||
}
|
||||
@@ -380,9 +368,9 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
// HTTP-Request erstellen
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/exec"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name()
|
||||
+ "/exec"))
|
||||
.header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.build();
|
||||
|
||||
// Anfrage senden und Antwort verarbeiten
|
||||
@@ -407,15 +395,15 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
String jsonPayload = """
|
||||
{
|
||||
"Cmd": ["adb", "install", "/home/sb.apk"],
|
||||
"Cmd": ["adb", "install", "sb.apk"],
|
||||
"AttachStdout": true,
|
||||
"AttachStderr": true
|
||||
}""";
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/exec"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.uri(URI.create(
|
||||
"http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/exec"))
|
||||
.header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.build();
|
||||
|
||||
try {
|
||||
@@ -436,9 +424,7 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/exec/" + execId + "/start"))
|
||||
.POST(HttpRequest.BodyPublishers.noBody())
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.build();
|
||||
.POST(HttpRequest.BodyPublishers.noBody()).version(HttpClient.Version.HTTP_1_1).build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
@@ -457,7 +443,8 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/start"))
|
||||
.uri(URI.create(
|
||||
"http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/start"))
|
||||
.POST(HttpRequest.BodyPublishers.noBody()) // Kein Body wird gesendet
|
||||
.build();
|
||||
|
||||
@@ -485,10 +472,10 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
}""";
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/exec"))
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-"
|
||||
+ niederlassung.name() + "/exec"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.build();
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload)).build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
logger.info("HTTP-Response-Code: {}", response.statusCode());
|
||||
@@ -572,9 +559,9 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
// HTTP-Request erstellen
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/create?name=android-container-" + niederlassung.name()))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.uri(URI.create(
|
||||
"http://" + server + ":2375/containers/create?name=android-container-" + niederlassung.name()))
|
||||
.header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.build();
|
||||
|
||||
// Anfrage senden und Antwort verarbeiten
|
||||
@@ -591,7 +578,8 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/stop"))
|
||||
.uri(URI.create(
|
||||
"http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "/stop"))
|
||||
.POST(HttpRequest.BodyPublishers.noBody()) // Kein Body wird gesendet
|
||||
.build();
|
||||
|
||||
@@ -608,7 +596,8 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name() + "?force=true"))
|
||||
.uri(URI.create("http://" + server + ":2375/containers/android-container-" + niederlassung.name()
|
||||
+ "?force=true"))
|
||||
.DELETE() // Kein Body wird gesendet
|
||||
.build();
|
||||
|
||||
@@ -620,6 +609,42 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
logger.error("Fehler beim HTTP-Request", e);
|
||||
}
|
||||
}
|
||||
private String buildContainerName(NiederlassungInfo info) {
|
||||
return "android-container-" + info.name();
|
||||
}
|
||||
|
||||
private boolean isContainerStarted(NiederlassungInfo info) {
|
||||
if (info == null) {
|
||||
logger.warn("isContainerStarted: Niederlassung ist null");
|
||||
return false;
|
||||
}
|
||||
String srv = (this.server != null ? this.server : "172.16.0.158");
|
||||
String name = buildContainerName(info);
|
||||
try {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + srv + ":2375/containers/" + name + "/json"))
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
int status = response.statusCode();
|
||||
logger.info("Inspect-Container '{}': status={} ", name, status);
|
||||
if (status == 200) {
|
||||
String body = response.body();
|
||||
// Simple check: look for State.Running = true
|
||||
boolean running = body != null && body.contains("\"Running\":true");
|
||||
logger.info("Inspect-Container '{}': running={}", name, running);
|
||||
return running;
|
||||
} else if (status == 404) {
|
||||
// Container existiert nicht
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Fehler beim Prüfen des Container-Status für '{}': {}", name, e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private Dialog showWaitDialog(String message) {
|
||||
Dialog dialog = new Dialog();
|
||||
@@ -630,32 +655,25 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
dialog.setResizable(false);
|
||||
|
||||
// Dialog-Styling
|
||||
dialog.getElement().getStyle()
|
||||
.set("border-radius", "16px")
|
||||
.set("box-shadow", "0 20px 40px rgba(0,0,0,0.3)")
|
||||
.set("background", "rgba(255,255,255,0.95)")
|
||||
.set("backdrop-filter", "blur(10px)");
|
||||
dialog.getElement().getStyle().set("border-radius", "16px").set("box-shadow", "0 20px 40px rgba(0,0,0,0.3)")
|
||||
.set("background", "rgba(255,255,255,0.95)").set("backdrop-filter", "blur(10px)");
|
||||
|
||||
// Haupt-Container
|
||||
VerticalLayout mainContainer = new VerticalLayout();
|
||||
mainContainer.setSpacing(false);
|
||||
mainContainer.setPadding(false);
|
||||
mainContainer.setAlignItems(VerticalLayout.Alignment.CENTER);
|
||||
mainContainer.getStyle()
|
||||
.set("padding", "40px")
|
||||
.set("min-width", "400px")
|
||||
.set("text-align", "center");
|
||||
mainContainer.getStyle().set("padding", "40px").set("min-width", "400px").set("text-align", "center");
|
||||
|
||||
// Animiertes Icon
|
||||
Icon loadingIcon = new Icon(VaadinIcon.COG);
|
||||
loadingIcon.setSize("48px");
|
||||
loadingIcon.getStyle()
|
||||
.set("color", "#667eea")
|
||||
.set("margin-bottom", "20px")
|
||||
.set("animation", "spin 2s linear infinite");
|
||||
loadingIcon.getStyle().set("color", "#667eea").set("margin-bottom", "20px").set("animation",
|
||||
"spin 2s linear infinite");
|
||||
|
||||
// CSS-Animation für das Icon
|
||||
dialog.getElement().executeJs("""
|
||||
dialog.getElement().executeJs(
|
||||
"""
|
||||
if (!document.getElementById('spin-animation')) {
|
||||
const style = document.createElement('style');
|
||||
style.id = 'spin-animation';
|
||||
@@ -666,34 +684,24 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
|
||||
// Titel
|
||||
H3 title = new H3("Bitte warten");
|
||||
title.getStyle()
|
||||
.set("margin", "0 0 12px 0")
|
||||
.set("color", "#333333")
|
||||
.set("font-size", "1.5rem")
|
||||
title.getStyle().set("margin", "0 0 12px 0").set("color", "#333333").set("font-size", "1.5rem")
|
||||
.set("font-weight", "600");
|
||||
|
||||
// Nachricht
|
||||
Paragraph messageText = new Paragraph(message);
|
||||
messageText.getStyle()
|
||||
.set("margin", "0 0 24px 0")
|
||||
.set("color", "#666666")
|
||||
.set("font-size", "1rem")
|
||||
messageText.getStyle().set("margin", "0 0 24px 0").set("color", "#666666").set("font-size", "1rem")
|
||||
.set("line-height", "1.5");
|
||||
|
||||
// Indeterminate Progress Bar
|
||||
ProgressBar progressBar = new ProgressBar();
|
||||
progressBar.setIndeterminate(true);
|
||||
progressBar.setWidthFull();
|
||||
progressBar.getStyle()
|
||||
.set("margin-bottom", "16px");
|
||||
progressBar.getStyle().set("margin-bottom", "16px");
|
||||
|
||||
// Status-Text
|
||||
Paragraph statusText = new Paragraph("Vorgang wird ausgeführt...");
|
||||
statusText.getStyle()
|
||||
.set("margin", "0")
|
||||
.set("color", "#888888")
|
||||
.set("font-size", "0.875rem")
|
||||
.set("font-style", "italic");
|
||||
statusText.getStyle().set("margin", "0").set("color", "#888888").set("font-size", "0.875rem").set("font-style",
|
||||
"italic");
|
||||
|
||||
// Alle Komponenten hinzufügen
|
||||
mainContainer.add(loadingIcon, title, messageText, progressBar, statusText);
|
||||
@@ -735,14 +743,35 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
}
|
||||
if (niederlassung != null) {
|
||||
Application.activeNiederlassungen.remove(niederlassung.name());
|
||||
logger.info("Niederlassung {} aus aktiven Niederlassungen entfernt", niederlassung.name());
|
||||
logger.info("Niederlassung {} aus aktiven Niederlassungen entfernt",
|
||||
niederlassung.name());
|
||||
}
|
||||
logger.info("Aktive Sessions nach Logout: {}/{}", Application.activeSessions.size(), Application.MAX_ACTIVE_SESSIONS);
|
||||
logger.info("Aktive Sessions nach Logout: {}/{}", Application.activeSessions.size(),
|
||||
Application.MAX_ACTIVE_SESSIONS);
|
||||
|
||||
// Session invalidieren und weiterleiten erst ganz am Ende
|
||||
ui.getSession().getSession().invalidate();
|
||||
logger.info("Session invalidiert - Weiterleitung zur Login-Seite");
|
||||
ui.getPage().setLocation("login");
|
||||
// 1) Client-seitigen Redirect sofort ausführen (wird beim Client direkt verarbeitet)
|
||||
var httpSession = ui.getSession().getSession();
|
||||
var vaadinSession = ui.getSession();
|
||||
ui.getPage().executeJs("window.location.replace($0);", "login");
|
||||
|
||||
// 2) Session-Schließung leicht verzögert im Hintergrund, damit der Redirect sicher ankommt
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
Thread.sleep(300); // kurze Verzögerung reicht i.d.R.
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
try {
|
||||
vaadinSession.close();
|
||||
} catch (Exception e) {
|
||||
logger.warn("Fehler beim Schließen der VaadinSession nach Redirect", e);
|
||||
}
|
||||
try {
|
||||
httpSession.invalidate();
|
||||
} catch (Exception e) {
|
||||
logger.warn("Fehler beim Invalidieren der HttpSession nach Redirect", e);
|
||||
}
|
||||
logger.info("Session nach Redirect geschlossen/invalidiert");
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Fehler beim Logout UI-Update", ex);
|
||||
|
||||
@@ -12,5 +12,3 @@ public class RootView implements BeforeEnterObserver {
|
||||
event.rerouteTo("main");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.vaadin.flow.spring.security.VaadinWebSecurity;
|
||||
import de.assecutor.emulatorstation.base.ui.view.LoginView;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy;
|
||||
|
||||
import de.assecutor.emulatorstation.Application;
|
||||
|
||||
@@ -16,19 +17,19 @@ public class SecurityConfig extends VaadinWebSecurity {
|
||||
|
||||
setLoginView(http, LoginView.class);
|
||||
|
||||
http
|
||||
.logout(logout -> logout
|
||||
.logoutSuccessUrl("/login")
|
||||
.addLogoutHandler((request, response, authentication) -> {
|
||||
http.sessionManagement(session -> session
|
||||
// Wichtig: Session-Fixation so konfigurieren, dass Session-Attribute (z.B. "user") erhalten bleiben
|
||||
.sessionFixation(fixation -> fixation.migrateSession())
|
||||
.maximumSessions(Application.MAX_ACTIVE_SESSIONS)
|
||||
.maxSessionsPreventsLogin(false))
|
||||
.logout(
|
||||
logout -> logout.logoutSuccessUrl("/login").addLogoutHandler((request, response, authentication) -> {
|
||||
if (authentication != null) {
|
||||
String username = authentication.getName();
|
||||
Application.activeNiederlassungen.entrySet().removeIf(entry ->
|
||||
entry.getValue().equals(username));
|
||||
Application.activeNiederlassungen.entrySet()
|
||||
.removeIf(entry -> entry.getValue().equals(username));
|
||||
}
|
||||
})
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,5 +52,3 @@ public class VaadinAccessHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ public class ExecResponse {
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package de.assecutor.emulatorstation.pojo;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
public record NiederlassungInfo(String name, String ip, String port, String urlExtension)
|
||||
implements Serializable {
|
||||
public record NiederlassungInfo(String name, String ip, String port, String urlExtension) implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -2,5 +2,3 @@ package de.assecutor.emulatorstation.pojo;
|
||||
|
||||
public record UserInfo(String password) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,14 +2,15 @@ package util;
|
||||
|
||||
import com.vaadin.flow.server.WrappedSession;
|
||||
|
||||
|
||||
public class Util {
|
||||
public static String getSessionAttributeWithDefault(WrappedSession currentSession, String key, String defaultValue) {
|
||||
public static String getSessionAttributeWithDefault(WrappedSession currentSession, String key,
|
||||
String defaultValue) {
|
||||
var result = defaultValue;
|
||||
|
||||
try {
|
||||
result = currentSession.getAttribute(key).toString();
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
7
src/main/resources/application-prod.properties
Normal file
7
src/main/resources/application-prod.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
# Production overrides
|
||||
# - Secure session cookie only over HTTPS
|
||||
# - SameSite policy for CSRF protection and to avoid third-party sending
|
||||
|
||||
server.servlet.session.cookie.secure=true
|
||||
server.servlet.session.cookie.same-site=lax
|
||||
|
||||
@@ -13,5 +13,19 @@ spring.jpa.open-in-view=false
|
||||
# Initialize the JPA Entity Manager before considering data.sql so that the EM can create the schema and data.sql contain data
|
||||
spring.jpa.defer-datasource-initialization = true
|
||||
|
||||
server.servlet.session.timeout=300s
|
||||
# Session configuration - preserve session on browser reload
|
||||
server.servlet.session.timeout=0
|
||||
|
||||
server.servlet.session.cookie.max-age=180d
|
||||
|
||||
server.servlet.session.cookie.http-only=true
|
||||
server.servlet.session.cookie.secure=false
|
||||
server.servlet.session.persistent=true
|
||||
|
||||
# Vaadin session configuration
|
||||
vaadin.heartbeatInterval=300
|
||||
vaadin.closeIdleSessions=false
|
||||
|
||||
|
||||
# Disable Spring Boot's default generated user/password (we handle auth via Vaadin & custom login)
|
||||
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration
|
||||
|
||||
39
tsconfig.json
Normal file
39
tsconfig.json
Normal file
@@ -0,0 +1,39 @@
|
||||
// This TypeScript configuration file is generated by vaadin-maven-plugin.
|
||||
// This is needed for TypeScript compiler to compile your TypeScript code in the project.
|
||||
// It is recommended to commit this file to the VCS.
|
||||
// You might want to change the configurations to fit your preferences
|
||||
// For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
|
||||
{
|
||||
"_version": "9.1",
|
||||
"compilerOptions": {
|
||||
"sourceMap": true,
|
||||
"jsx": "react-jsx",
|
||||
"inlineSources": true,
|
||||
"module": "esNext",
|
||||
"target": "es2022",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"baseUrl": "src/main/frontend",
|
||||
"paths": {
|
||||
"@vaadin/flow-frontend": ["generated/jar-resources"],
|
||||
"@vaadin/flow-frontend/*": ["generated/jar-resources/*"],
|
||||
"Frontend/*": ["*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/main/frontend/**/*",
|
||||
"types.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"src/main/frontend/generated/jar-resources/**"
|
||||
]
|
||||
}
|
||||
17
types.d.ts
vendored
Normal file
17
types.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// This TypeScript modules definition file is generated by vaadin-maven-plugin.
|
||||
// You can not directly import your different static files into TypeScript,
|
||||
// This is needed for TypeScript compiler to declare and export as a TypeScript module.
|
||||
// It is recommended to commit this file to the VCS.
|
||||
// You might want to change the configurations to fit your preferences
|
||||
declare module '*.css?inline' {
|
||||
import type { CSSResultGroup } from 'lit';
|
||||
const content: CSSResultGroup;
|
||||
export default content;
|
||||
}
|
||||
|
||||
// Allow any CSS Custom Properties
|
||||
declare module 'csstype' {
|
||||
interface Properties {
|
||||
[index: `--${string}`]: any;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user