Вот моя конфигурация безопасности spring:
<http pattern="/auth/login" security="none" />
<http pattern="/auth/loginFailed" security="none" />
<http pattern="/resources/**" security="none" />
<http auto-config="true" access-decision-manager-ref="accessDecisionManager">
<intercept-url pattern="/auth/logout" access="permitAll"/>
<intercept-url pattern="/admin/**" access="ADMINISTRATIVE_ACCESS"/>
<intercept-url pattern="/**" access="XYZ_ACCESS"/>
<form-login
login-page="/auth/login"
authentication-failure-url="/auth/loginFailed"
authentication-success-handler-ref="authenticationSuccessHandler" />
<logout logout-url="/auth/logout" logout-success-url="/auth/login" />
</http>
authenticationSuccessHandler
расширяет SavedRequestAwareAuthenticationSuccessHandler
, гарантируя, что пользователь перенаправляется на запрашиваемую им страницу.
Однако, поскольку /auth/login
помечен как security="none"
, я не могу успешно перенаправить пользователя на домашнюю страницу, если он обратился к странице входа в систему после входа в систему. Я считаю, что это правильный .
Я тоже попробовал это, но объект Principal
всегда null
, предположительно из-за атрибута security="none"
.
@RequestMapping(value = "/auth/login", method = GET)
public String showLoginForm(HttpServletRequest request, Principal principal) {
if(principal != null) {
return "redirect:/";
}
return "login";
}