在 Spring Security 中是否有任何配置方式,以便我可以在调用此代码时获取自定义的“USER”DAO 类对象。
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
最佳答案
使用 DaoAuthenticationProvider
最简单的方法
- 确保您的
User
dao对象扩展org.springframework.security.core.userdetails.UserDetails
- 实现您的
org.springframework.security.core.userdetails.UserDetailsService
并返回您的User
dao 对象 - 使用您的
UserDetailsService
配置DaoAuthenticationProvider
关于java - 在 Spring Security 中配置自定义对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17829391/