问题
Can anybody please help me to get how can i add more field in custom login jsp file ? The default is "j_username" and "j_password". What if i want to add more field i.e and want to get it in my CustomAuthenticationProvider class which extends AbstractUserDetailsAuthenticationProvider. If there is any resource or link out there please let me know.
回答1:
Quoting the official FAQ:
1.1. I need to login in with more information than just the username. How do I add support for extra login fields (e.g. a company name)?
This question comes up repeatedly in the Spring Security forum so you will find more information there by searching the archives (or through google).
The submitted login information is processed by an instance of
UsernamePasswordAuthenticationFilter. You will need to customize this class to handle the extra data field(s). One option is to use your own customized authentication token class (rather than the standardUsernamePasswordAuthenticationToken), another is simply to concatenate the extra fields with the username (for example, using a ":" as the separator) and pass them in the username property ofUsernamePasswordAuthenticationToken.You will also need to customize the actual authentication process. If you are using a custom authentication token class, for example, you will have to write an
AuthenticationProviderto handle it (or extend the standardDaoAuthenticationProvider). If you have concatenated the fields, you can implement your ownUserDetailsServicewhich splits them up and loads the appropriate user data for authentication.
来源:https://stackoverflow.com/questions/10571383/spring-security-custom-login-page