Erweiterungen
This commit is contained in:
@@ -14,13 +14,10 @@ import de.assecutor.emulatorstation.pojo.NiederlassungInfo;
|
||||
@Push
|
||||
@Theme("default")
|
||||
public class Application implements AppShellConfigurator {
|
||||
public static final Map<String, UserInfo> users = Map.ofEntries(
|
||||
Map.entry("user1", new UserInfo("pass1")),
|
||||
Map.entry("user2", new UserInfo("pass2")),
|
||||
Map.entry("user3", new UserInfo("pass3")),
|
||||
Map.entry("user4", new UserInfo("pass4")),
|
||||
Map.entry("user5", new UserInfo("pass5"))
|
||||
);
|
||||
// Single user configuration
|
||||
public static final String SINGLE_USERNAME = "user";
|
||||
public static final String SINGLE_PASSWORD = "user123";
|
||||
public static final int MAX_ACTIVE_SESSIONS = 5;
|
||||
|
||||
public static final Map<String, NiederlassungInfo> niederlassungen = Map.ofEntries(
|
||||
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> activeUsers = new ConcurrentHashMap<>();
|
||||
public static final Map<String, String> activeSessions = new ConcurrentHashMap<>(); // sessionId -> niederlassung
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
|
||||
@@ -78,12 +78,7 @@ public class LoginView extends VerticalLayout {
|
||||
formLayout.setPadding(false);
|
||||
formLayout.setWidthFull();
|
||||
|
||||
// Eingabefelder
|
||||
TextField usernameField = new TextField("Benutzername");
|
||||
usernameField.setWidthFull();
|
||||
usernameField.getStyle()
|
||||
.set("margin-bottom", "16px");
|
||||
|
||||
// Eingabefelder - nur noch Passwort
|
||||
PasswordField passwordField = new PasswordField("Passwort");
|
||||
passwordField.setWidthFull();
|
||||
passwordField.getStyle()
|
||||
@@ -98,39 +93,33 @@ public class LoginView extends VerticalLayout {
|
||||
.set("margin-bottom", "24px");
|
||||
|
||||
Button loginButton = new Button("Anmelden", new Icon(VaadinIcon.SIGN_IN), event -> {
|
||||
String username = usernameField.getValue();
|
||||
String password = passwordField.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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Application.users.containsKey(username) ||
|
||||
!Application.users.get(username).password().equals(password)) {
|
||||
Notification.show("Ungültige Anmeldedaten", 3000, Notification.Position.MIDDLE);
|
||||
// Passwort prüfen
|
||||
if (!Application.SINGLE_PASSWORD.equals(password)) {
|
||||
Notification.show("Ungültiges Passwort", 3000, Notification.Position.MIDDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Application.activeUsers.containsKey(username)) {
|
||||
Notification.show("Benutzer ist bereits angemeldet", 3000, Notification.Position.MIDDLE);
|
||||
// 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);
|
||||
return;
|
||||
}
|
||||
|
||||
// Prüfen ob Niederlassung bereits belegt ist
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (niederlassungInfo == null) {
|
||||
Notification.show("Ausgewählte Niederlassung ist ungültig", 3000, Notification.Position.MIDDLE);
|
||||
@@ -138,13 +127,28 @@ public class LoginView extends VerticalLayout {
|
||||
}
|
||||
|
||||
getUI().ifPresent(ui -> {
|
||||
ui.getSession().setAttribute("user", username);
|
||||
ui.getSession().setAttribute("username", username);
|
||||
String sessionId = ui.getSession().getSession().getId();
|
||||
|
||||
// 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("sessionId", sessionId);
|
||||
|
||||
logger.info("Login erfolgreich - Session-Daten gesetzt:");
|
||||
logger.info("Username: {}", username);
|
||||
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");
|
||||
});
|
||||
@@ -160,7 +164,7 @@ public class LoginView extends VerticalLayout {
|
||||
.set("font-weight", "600");
|
||||
|
||||
// Eingabefelder zum Form-Layout hinzufügen
|
||||
formLayout.add(usernameField, passwordField, niederlassungSelect, loginButton);
|
||||
formLayout.add(passwordField, niederlassungSelect, loginButton);
|
||||
|
||||
// Alle Komponenten zum Login-Container hinzufügen
|
||||
loginContainer.add(icon, title, subtitle, formLayout);
|
||||
|
||||
@@ -658,14 +658,16 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
dialog.close();
|
||||
|
||||
// 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) {
|
||||
Application.activeNiederlassungen.remove(niederlassung.name());
|
||||
logger.info("Niederlassung {} aus aktiven Niederlassungen entfernt", niederlassung.name());
|
||||
}
|
||||
if (username != null) {
|
||||
Application.activeUsers.remove(username);
|
||||
logger.info("Benutzer {} aus aktiven Benutzern entfernt", username);
|
||||
}
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user