Код: Выделить всё
@GetMapping("/login")
public String login(Model model) {
if (ldapService.isLdapAvailable()) {
System.out.println("Inside login method. LDAP is available.");
return "redirect:/login"; // Redirect to success page if LDAP connection is successful
} else {
System.out.println("Inside login method. LDAP is unavailable.");
model.addAttribute("ldapUnavailableMessage", "LDAP service is currently unavailable. Do you want to continue with local backup authentication?");
return "login"; // Return login page with an LDAP error message
}
}
@PostMapping("/login")
public String handleLogin(@RequestParam Map credentials, HttpSession session, Model model) {
String username = credentials.get("username");
String password = credentials.get("password");
if (ldapService.isLdapAvailable()) {
// Handle LDAP authentication (not provided in this example)
System.out.println("LDAP is available and handling login via LDAP.");
// Assuming LDAP authentication success here for now
session.setAttribute("username", username); // Set whatever attributes are needed here
return "redirect:/dashboard"; // Redirect to dashboard
} else {
boolean isAuthenticated = localAuthService.authenticate(username, password);
if (isAuthenticated) {
session.setAttribute("username", username);
System.out.println("Authenticated using local DB.");
return "redirect:/dashboard"; // Redirect to dashboard or another page
} else {
model.addAttribute("error", "Authentication failed. Please check your username and password.");
System.out.println("Local DB authentication failed.");
return "login"; // Stay on login page and show error
}
}
}
Код: Выделить всё
alert([[${ldapUnavailableMessage}]]);
if (confirm("Do you want to continue with local backup authentication?")) {
window.location.href = "/localLogin"; // Redirect to local login page
}
Но это не работает. Код может проверить, доступен ли LDAP или нет. Если он недоступен, выдается ошибка
Код: Выделить всё
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController': Unsatisfied dependency expressed through field 'ldapService'
Подробнее здесь: https://stackoverflow.com/questions/787 ... n-troubles