Display Error Login Message On Custom Spring Boot Login Form
I'm working on a custom spring boot login form. When user provides wrong credentials, I want my application redirect to the same page and show an error. What I tried, is to create
Solution 1:
When login fails. Spring security sends you back on the same login page with special request param something like guest/login?error
or You can change this to custom by setting up .failureUrl()
in security config which you are not doing.
So change it to .failureUrl("/guest/login?error")
Use this error
param to identify if something went wrong using ${not empty param.error}
.
I am guessing you are using JSP and the EL
is by default available.
You can add something like below on your login page which will give you the actual reason why it failed.
<c:iftest="${not empty param.error}"><pstyle="color:red">
Your login attempt was not
successful, try again.<br /> Reason: <c:outvalue="${SPRING_SECURITY_LAST_EXCEPTION.message}" />.
</p></c:if>
Where SPRING_SECURITY_LAST_EXCEPTION
param is available in user's session scope added by spring security with actual cause.
Post a Comment for "Display Error Login Message On Custom Spring Boot Login Form"