У меня очень странное поведение в отношении безопасности весны. КонфигурацияВесна безопасности. невероятное поведение
безопасности:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http use-expressions="true" >
<intercept-url pattern="/home.jsp" access="permitAll" />
<intercept-url pattern="/*" access="isAuthenticated()"/>
<form-login login-page="/"
authentication-failure-url="/loginFailed" default-target-url="/index" />
<logout logout-success-url="/logOut" />
</http>
<authentication-manager>
<authentication-provider ref="provider" />
</authentication-manager>
</beans:beans>
Контроллер:
@Controller
public class HomeController {
@RequestMapping("/index")
public String success(Model model) {
System.out.println("/index");
return "index";
}
@RequestMapping(value="/loginFailed", method = RequestMethod.GET)
public String loginError(Model model, RedirectAttributes redirectAttributes) throws Exception {
redirectAttributes.addAttribute("message", "incorrect combination of login and password");
System.out.println("/loginFailed");
return "redirect:home.jsp";
}
@RequestMapping(value="/logOut", method = RequestMethod.GET)
public String logOut(Model model, RedirectAttributes redirectAttributes) throws Exception {
redirectAttributes.addAttribute("message", "success logout");
System.out.println("/logOut");
return "redirect:home.jsp";
}
...
}
если на URL http://localhost:8080/ui/
(корень приложения URL) I типа
первая активность:
1 введите правильный пароль - ->http://localhost:8080/ui/index
в журнале я вижу /index
isAuthenttificated() == true
2 нажмите Завершить работу ->http://localhost:8080/ui/
и журнал пуст isAuthenttificated() == false
3 ввода правильного пароля ->http://localhost:8080/ui/home.jsp?message=success+logout
и я вижу /logOut
в консоли isAuthenttificated() == true
4 нажмите Завершить работу -> перейти к http://localhost:8080/ui/
и журнал пуст isAuthenttificated() == false
5 ввода правильного пароля -> перейти к http://localhost:8080/ui/
и войти пуст isAuthenttificated() == false
Я не понимаю, какая весенняя безопасность выбирает, какой контроллер использовать.
Я думаю, что весна вызывает правильные сервлеты, но использует неправильные URL-адреса.
Весенняя безопасность перенаправляет на «default-target-url» или на страницу, с которой вы перенаправляетесь, чтобы получить аутентификацию. Если вы хотите всегда пересылать целевой объект по умолчанию, используйте 'always-use-default-target =" true "' – Bart