Spring security custom login page

有些话、适合烂在心里 提交于 2019-12-24 19:44:54

问题


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 standard UsernamePasswordAuthenticationToken), 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 of UsernamePasswordAuthenticationToken.

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 AuthenticationProvider to handle it (or extend the standard DaoAuthenticationProvider). If you have concatenated the fields, you can implement your own UserDetailsService which splits them up and loads the appropriate user data for authentication.



来源:https://stackoverflow.com/questions/10571383/spring-security-custom-login-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!