Erweiterungen
This commit is contained in:
@@ -14,13 +14,10 @@ import de.assecutor.emulatorstation.pojo.NiederlassungInfo;
|
|||||||
@Push
|
@Push
|
||||||
@Theme("default")
|
@Theme("default")
|
||||||
public class Application implements AppShellConfigurator {
|
public class Application implements AppShellConfigurator {
|
||||||
public static final Map<String, UserInfo> users = Map.ofEntries(
|
// Single user configuration
|
||||||
Map.entry("user1", new UserInfo("pass1")),
|
public static final String SINGLE_USERNAME = "user";
|
||||||
Map.entry("user2", new UserInfo("pass2")),
|
public static final String SINGLE_PASSWORD = "user123";
|
||||||
Map.entry("user3", new UserInfo("pass3")),
|
public static final int MAX_ACTIVE_SESSIONS = 5;
|
||||||
Map.entry("user4", new UserInfo("pass4")),
|
|
||||||
Map.entry("user5", new UserInfo("pass5"))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final Map<String, NiederlassungInfo> niederlassungen = Map.ofEntries(
|
public static final Map<String, NiederlassungInfo> niederlassungen = Map.ofEntries(
|
||||||
Map.entry("Berlin", new NiederlassungInfo("Berlin", "172.18.0.103", "6083", "/berlin")),
|
Map.entry("Berlin", new NiederlassungInfo("Berlin", "172.18.0.103", "6083", "/berlin")),
|
||||||
@@ -37,7 +34,7 @@ public class Application implements AppShellConfigurator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public static final Map<String, String> activeNiederlassungen = new ConcurrentHashMap<>();
|
public static final Map<String, String> activeNiederlassungen = new ConcurrentHashMap<>();
|
||||||
public static final Map<String, String> activeUsers = new ConcurrentHashMap<>();
|
public static final Map<String, String> activeSessions = new ConcurrentHashMap<>(); // sessionId -> niederlassung
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
|
|||||||
@@ -78,12 +78,7 @@ public class LoginView extends VerticalLayout {
|
|||||||
formLayout.setPadding(false);
|
formLayout.setPadding(false);
|
||||||
formLayout.setWidthFull();
|
formLayout.setWidthFull();
|
||||||
|
|
||||||
// Eingabefelder
|
// Eingabefelder - nur noch Passwort
|
||||||
TextField usernameField = new TextField("Benutzername");
|
|
||||||
usernameField.setWidthFull();
|
|
||||||
usernameField.getStyle()
|
|
||||||
.set("margin-bottom", "16px");
|
|
||||||
|
|
||||||
PasswordField passwordField = new PasswordField("Passwort");
|
PasswordField passwordField = new PasswordField("Passwort");
|
||||||
passwordField.setWidthFull();
|
passwordField.setWidthFull();
|
||||||
passwordField.getStyle()
|
passwordField.getStyle()
|
||||||
@@ -98,39 +93,33 @@ public class LoginView extends VerticalLayout {
|
|||||||
.set("margin-bottom", "24px");
|
.set("margin-bottom", "24px");
|
||||||
|
|
||||||
Button loginButton = new Button("Anmelden", new Icon(VaadinIcon.SIGN_IN), event -> {
|
Button loginButton = new Button("Anmelden", new Icon(VaadinIcon.SIGN_IN), event -> {
|
||||||
String username = usernameField.getValue();
|
|
||||||
String password = passwordField.getValue();
|
String password = passwordField.getValue();
|
||||||
String niederlassung = niederlassungSelect.getValue();
|
String niederlassung = niederlassungSelect.getValue();
|
||||||
|
|
||||||
if (username.isEmpty() || password.isEmpty() || niederlassung == null) {
|
// Validierung der Eingabefelder
|
||||||
|
if (password.isEmpty() || niederlassung == null) {
|
||||||
Notification.show("Bitte alle Felder ausfüllen", 3000, Notification.Position.MIDDLE);
|
Notification.show("Bitte alle Felder ausfüllen", 3000, Notification.Position.MIDDLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Application.users.containsKey(username) ||
|
// Passwort prüfen
|
||||||
!Application.users.get(username).password().equals(password)) {
|
if (!Application.SINGLE_PASSWORD.equals(password)) {
|
||||||
Notification.show("Ungültige Anmeldedaten", 3000, Notification.Position.MIDDLE);
|
Notification.show("Ungültiges Passwort", 3000, Notification.Position.MIDDLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Application.activeUsers.containsKey(username)) {
|
// Maximale Session-Anzahl prüfen
|
||||||
Notification.show("Benutzer ist bereits angemeldet", 3000, Notification.Position.MIDDLE);
|
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prüfen ob Niederlassung bereits belegt ist
|
||||||
if (Application.activeNiederlassungen.containsKey(niederlassung)) {
|
if (Application.activeNiederlassungen.containsKey(niederlassung)) {
|
||||||
Notification.show("Niederlassung ist bereits von einem anderen Benutzer belegt", 3000, Notification.Position.MIDDLE);
|
Notification.show("Niederlassung ist bereits von einer anderen Session belegt", 3000, Notification.Position.MIDDLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Application.activeNiederlassungen.put(niederlassung, username);
|
|
||||||
Application.activeUsers.put(username, niederlassung);
|
|
||||||
|
|
||||||
// Spring Security Authentifizierung setzen
|
|
||||||
var authorities = List.of(new SimpleGrantedAuthority("ROLE_USER"));
|
|
||||||
var authentication = new UsernamePasswordAuthenticationToken(username, password, authorities);
|
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
||||||
|
|
||||||
var niederlassungInfo = Application.niederlassungen.get(niederlassung);
|
var niederlassungInfo = Application.niederlassungen.get(niederlassung);
|
||||||
if (niederlassungInfo == null) {
|
if (niederlassungInfo == null) {
|
||||||
Notification.show("Ausgewählte Niederlassung ist ungültig", 3000, Notification.Position.MIDDLE);
|
Notification.show("Ausgewählte Niederlassung ist ungültig", 3000, Notification.Position.MIDDLE);
|
||||||
@@ -138,13 +127,28 @@ public class LoginView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUI().ifPresent(ui -> {
|
getUI().ifPresent(ui -> {
|
||||||
ui.getSession().setAttribute("user", username);
|
String sessionId = ui.getSession().getSession().getId();
|
||||||
ui.getSession().setAttribute("username", username);
|
|
||||||
|
// Session registrieren
|
||||||
|
Application.activeSessions.put(sessionId, niederlassung);
|
||||||
|
Application.activeNiederlassungen.put(niederlassung, sessionId);
|
||||||
|
|
||||||
|
// 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("niederlassung", niederlassungInfo);
|
||||||
|
ui.getSession().setAttribute("sessionId", sessionId);
|
||||||
|
|
||||||
logger.info("Login erfolgreich - Session-Daten gesetzt:");
|
logger.info("Login erfolgreich - Session-Daten gesetzt:");
|
||||||
logger.info("Username: {}", username);
|
logger.info("Username: {}", Application.SINGLE_USERNAME);
|
||||||
logger.info("Niederlassung: {}", niederlassungInfo.name());
|
logger.info("Niederlassung: {}", niederlassungInfo.name());
|
||||||
|
logger.info("SessionId: {}", sessionId);
|
||||||
|
logger.info("Aktive Sessions: {}/{}", Application.activeSessions.size(), Application.MAX_ACTIVE_SESSIONS);
|
||||||
|
|
||||||
ui.navigate("main");
|
ui.navigate("main");
|
||||||
});
|
});
|
||||||
@@ -160,7 +164,7 @@ public class LoginView extends VerticalLayout {
|
|||||||
.set("font-weight", "600");
|
.set("font-weight", "600");
|
||||||
|
|
||||||
// Eingabefelder zum Form-Layout hinzufügen
|
// Eingabefelder zum Form-Layout hinzufügen
|
||||||
formLayout.add(usernameField, passwordField, niederlassungSelect, loginButton);
|
formLayout.add(passwordField, niederlassungSelect, loginButton);
|
||||||
|
|
||||||
// Alle Komponenten zum Login-Container hinzufügen
|
// Alle Komponenten zum Login-Container hinzufügen
|
||||||
loginContainer.add(icon, title, subtitle, formLayout);
|
loginContainer.add(icon, title, subtitle, formLayout);
|
||||||
|
|||||||
@@ -658,14 +658,16 @@ public final class MainView extends Main implements BeforeEnterObserver
|
|||||||
dialog.close();
|
dialog.close();
|
||||||
|
|
||||||
// Session cleanup erst nach Shutdown
|
// Session cleanup erst nach Shutdown
|
||||||
|
String sessionId = (String) ui.getSession().getAttribute("sessionId");
|
||||||
|
if (sessionId != null) {
|
||||||
|
Application.activeSessions.remove(sessionId);
|
||||||
|
logger.info("Session {} aus aktiven Sessions entfernt", sessionId);
|
||||||
|
}
|
||||||
if (niederlassung != null) {
|
if (niederlassung != null) {
|
||||||
Application.activeNiederlassungen.remove(niederlassung.name());
|
Application.activeNiederlassungen.remove(niederlassung.name());
|
||||||
logger.info("Niederlassung {} aus aktiven Niederlassungen entfernt", niederlassung.name());
|
logger.info("Niederlassung {} aus aktiven Niederlassungen entfernt", niederlassung.name());
|
||||||
}
|
}
|
||||||
if (username != null) {
|
logger.info("Aktive Sessions nach Logout: {}/{}", Application.activeSessions.size(), Application.MAX_ACTIVE_SESSIONS);
|
||||||
Application.activeUsers.remove(username);
|
|
||||||
logger.info("Benutzer {} aus aktiven Benutzern entfernt", username);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Session invalidieren und weiterleiten erst ganz am Ende
|
// Session invalidieren und weiterleiten erst ganz am Ende
|
||||||
ui.getSession().getSession().invalidate();
|
ui.getSession().getSession().invalidate();
|
||||||
|
|||||||
Reference in New Issue
Block a user